From e2ec6b4211322d5780c13f2f860b0b7bc912cd3e Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 4 Feb 2022 15:16:23 +0100 Subject: [PATCH 1/2] [fix] invidious engine: store random base_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/invidious.py | 20 ++++++++------------ searx/settings.yml | 10 +++++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/searx/engines/invidious.py b/searx/engines/invidious.py index 914615d6f..931fd1066 100644 --- a/searx/engines/invidious.py +++ b/searx/engines/invidious.py @@ -23,16 +23,12 @@ categories = ["videos", "music"] paging = True time_range_support = True - -# search-url - -base_url = '' -base_url_rand = '' +# base_url can be overwritten by a list of URLs in the settings.yml +base_url = 'https://vid.puffyan.us' # do search-request def request(query, params): - global base_url_rand time_range_dict = { "day": "today", "week": "week", @@ -41,11 +37,11 @@ def request(query, params): } 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 + params["base_url"] = base_url - search_url = base_url_rand + "api/v1/search?q={query}" + search_url = params["base_url"] + "/api/v1/search?q={query}" params["url"] = search_url.format(query=quote_plus(query)) + "&page={pageno}".format(pageno=params["pageno"]) if params["time_range"] in time_range_dict: @@ -67,12 +63,12 @@ def response(resp): embedded_url = ( '' ) - base_invidious_url = base_url_rand + "watch?v=" + base_invidious_url = resp.search_params['base_url'] + "/watch?v=" for result in search_results: rtype = result.get("type", None) diff --git a/searx/settings.yml b/searx/settings.yml index 3d4c0e18a..6496e6eaf 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -786,11 +786,11 @@ engines: # Instanes will be selected randomly, see https://api.invidious.io/ for # instances that are stable (good uptime) and close to you. base_url: - - https://invidious.snopyta.org/ - - https://vid.puffyan.us/ - - https://invidious.kavin.rocks/ - - https://invidio.xamh.de/ - - https://inv.riverside.rocks/ + - https://invidious.snopyta.org + - https://vid.puffyan.us + # - https://invidious.kavin.rocks # Error 1020 // Access denied by Cloudflare + - https://invidio.xamh.de + - https://inv.riverside.rocks shortcut: iv timeout: 3.0 disabled: true From b35ef9789bc1f302ca28f46716ac9864622559d5 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 4 Feb 2022 15:20:57 +0100 Subject: [PATCH 2/2] [pylint] engines/invidious.py Fix remarks from pylint and remove usless comments Signed-off-by: Markus Heiser --- searx/engines/invidious.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/searx/engines/invidious.py b/searx/engines/invidious.py index 931fd1066..badef57fd 100644 --- a/searx/engines/invidious.py +++ b/searx/engines/invidious.py @@ -1,12 +1,12 @@ # SPDX-License-Identifier: AGPL-3.0-or-later -""" - Invidious (Videos) +# lint: pylint +"""Invidious (Videos) """ -from urllib.parse import quote_plus -from dateutil import parser import time import random +from urllib.parse import quote_plus +from dateutil import parser # about about = { @@ -27,7 +27,6 @@ time_range_support = True base_url = 'https://vid.puffyan.us' -# do search-request def request(query, params): time_range_dict = { "day": "today", @@ -55,7 +54,6 @@ def request(query, params): return params -# get response from search-request def response(resp): results = []