1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-14 08:40:11 +01:00

[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 <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2022-02-04 14:41:53 +01:00
parent d6061b7c8a
commit ddc2102a07

View File

@ -29,17 +29,16 @@ about = {
categories = ['files'] categories = ['files']
paging = True paging = True
base_url = '' # base_url can be overwritten by a list of URLs in the settings.yml
base_url_rand = '' base_url = 'https://solidtorrents.net'
def request(query, params): def request(query, params):
global base_url_rand # pylint: disable=global-statement
if isinstance(base_url, list): if isinstance(base_url, list):
base_url_rand = random.choice(base_url) params['base_url'] = random.choice(base_url)
else: else:
base_url_rand = base_url params['base_url'] = base_url
search_url = base_url_rand + '/search?{query}' search_url = params['base_url'] + '/search?{query}'
page = (params['pageno'] - 1) * 20 page = (params['pageno'] - 1) * 20
query = urlencode({'q': query, 'page': page}) query = urlencode({'q': query, 'page': page})
params['url'] = search_url.format(query=query) params['url'] = search_url.format(query=query)
@ -70,7 +69,7 @@ def response(resp):
'seed': seed, 'seed': seed,
'leech': leech, 'leech': leech,
'title': title, 'title': title,
'url': base_url_rand + url, 'url': resp.search_params['base_url'] + url,
'filesize': filesize, 'filesize': filesize,
'magnetlink': magnet, 'magnetlink': magnet,
'torrentfile': torrentfile, 'torrentfile': torrentfile,