From ddc2102a075d9690b9e98e16cef2ae3c1e5268f3 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 4 Feb 2022 14:41:53 +0100 Subject: [PATCH] [fix] solidtorrents engine: store random bas_url in param Two different threads ( = two different user queries) can call the request function in a row and then the response function. The namespace will be same since this is the same engine. To keep exactly the same value ``base_url`` must be stored in params and then retrieve using ``resp.search_params["base_url"]``. Suggested-by: @dalf https://github.com/searxng/searxng/pull/862#discussion_r799324861 Signed-off-by: Markus Heiser --- searx/engines/solidtorrents.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/searx/engines/solidtorrents.py b/searx/engines/solidtorrents.py index 1e58996e5..9b5d543d8 100644 --- a/searx/engines/solidtorrents.py +++ b/searx/engines/solidtorrents.py @@ -29,17 +29,16 @@ about = { categories = ['files'] paging = True -base_url = '' -base_url_rand = '' +# base_url can be overwritten by a list of URLs in the settings.yml +base_url = 'https://solidtorrents.net' def request(query, params): - global base_url_rand # pylint: disable=global-statement if isinstance(base_url, list): - base_url_rand = random.choice(base_url) + params['base_url'] = random.choice(base_url) else: - base_url_rand = base_url - search_url = base_url_rand + '/search?{query}' + params['base_url'] = base_url + search_url = params['base_url'] + '/search?{query}' page = (params['pageno'] - 1) * 20 query = urlencode({'q': query, 'page': page}) params['url'] = search_url.format(query=query) @@ -70,7 +69,7 @@ def response(resp): 'seed': seed, 'leech': leech, 'title': title, - 'url': base_url_rand + url, + 'url': resp.search_params['base_url'] + url, 'filesize': filesize, 'magnetlink': magnet, 'torrentfile': torrentfile,