From 2dff3887f0c64ce317b3bb720c75f764c1ec8b3e Mon Sep 17 00:00:00 2001 From: mrwormo Date: Fri, 8 Jan 2021 13:27:54 +0100 Subject: [PATCH] [fix] Invidious engine by enabling requests by randomly picking amongst working instances --- searx/engines/invidious.py | 19 +++++++++++++++---- searx/settings.yml | 4 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/searx/engines/invidious.py b/searx/engines/invidious.py index 6ea942699..d02119d06 100644 --- a/searx/engines/invidious.py +++ b/searx/engines/invidious.py @@ -11,6 +11,7 @@ from urllib.parse import quote_plus from dateutil import parser import time +import random # engine dependent config categories = ["videos", "music"] @@ -18,19 +19,29 @@ paging = True language_support = True time_range_support = True + # search-url -base_url = "https://invidio.us/" + +base_url = '' +base_url_rand = '' # do search-request def request(query, params): + global base_url_rand time_range_dict = { "day": "today", "week": "week", "month": "month", "year": "year", } - search_url = base_url + "api/v1/search?q={query}" + + if isinstance(base_url, list): + base_url_rand = random.choice(base_url) + else: + base_url_rand = base_url + + search_url = base_url_rand + "api/v1/search?q={query}" params["url"] = search_url.format( query=quote_plus(query) ) + "&page={pageno}".format(pageno=params["pageno"]) @@ -56,12 +67,12 @@ def response(resp): embedded_url = ( '' ) - base_invidious_url = base_url + "watch?v=" + base_invidious_url = base_url_rand + "watch?v=" for result in search_results: rtype = result.get("type", None) diff --git a/searx/settings.yml b/searx/settings.yml index 55c9849c1..ac1be701e 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -522,7 +522,9 @@ engines: - name : invidious engine : invidious - base_url : 'https://invidio.us/' + base_url : + - https://invidious.tube/ + - https://invidious.snopyta.org/ shortcut: iv timeout : 5.0 disabled : True