diff options
author | mrwormo <mrwormo@ox2.fr> | 2021-01-08 13:27:54 +0100 |
---|---|---|
committer | mrwormo <mrwormo@ox2.fr> | 2021-01-14 12:12:56 +0100 |
commit | 2dff3887f0c64ce317b3bb720c75f764c1ec8b3e (patch) | |
tree | 09a41b88bfd28def9cfec480e5746c74bd39190d /searx/engines/invidious.py | |
parent | 484dc99580a4cfdbba022209cbe896cd69b3e8b2 (diff) | |
download | searxng-2dff3887f0c64ce317b3bb720c75f764c1ec8b3e.tar.gz searxng-2dff3887f0c64ce317b3bb720c75f764c1ec8b3e.zip |
[fix] Invidious engine by enabling requests by randomly picking amongst working instances
Diffstat (limited to 'searx/engines/invidious.py')
-rw-r--r-- | searx/engines/invidious.py | 19 |
1 files changed, 15 insertions, 4 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 = ( '<iframe width="540" height="304" ' + 'data-src="' - + base_url + + base_url_rand + 'embed/{videoid}" ' + 'frameborder="0" allowfullscreen></iframe>' ) - 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) |