forked from zaclys/searxng
Merge pull request #867 from return42/fix-base_url_rand
[fix] invidious engine: store random base_url in param
This commit is contained in:
commit
10e6881ca8
|
@ -1,12 +1,12 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""
|
# lint: pylint
|
||||||
Invidious (Videos)
|
"""Invidious (Videos)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from urllib.parse import quote_plus
|
|
||||||
from dateutil import parser
|
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
from urllib.parse import quote_plus
|
||||||
|
from dateutil import parser
|
||||||
|
|
||||||
# about
|
# about
|
||||||
about = {
|
about = {
|
||||||
|
@ -23,16 +23,11 @@ categories = ["videos", "music"]
|
||||||
paging = True
|
paging = True
|
||||||
time_range_support = True
|
time_range_support = True
|
||||||
|
|
||||||
|
# base_url can be overwritten by a list of URLs in the settings.yml
|
||||||
# search-url
|
base_url = 'https://vid.puffyan.us'
|
||||||
|
|
||||||
base_url = ''
|
|
||||||
base_url_rand = ''
|
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
global base_url_rand
|
|
||||||
time_range_dict = {
|
time_range_dict = {
|
||||||
"day": "today",
|
"day": "today",
|
||||||
"week": "week",
|
"week": "week",
|
||||||
|
@ -41,11 +36,11 @@ def request(query, params):
|
||||||
}
|
}
|
||||||
|
|
||||||
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 + "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"])
|
params["url"] = search_url.format(query=quote_plus(query)) + "&page={pageno}".format(pageno=params["pageno"])
|
||||||
|
|
||||||
if params["time_range"] in time_range_dict:
|
if params["time_range"] in time_range_dict:
|
||||||
|
@ -59,7 +54,6 @@ def request(query, params):
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
# get response from search-request
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
|
@ -67,12 +61,12 @@ def response(resp):
|
||||||
embedded_url = (
|
embedded_url = (
|
||||||
'<iframe width="540" height="304" '
|
'<iframe width="540" height="304" '
|
||||||
+ 'data-src="'
|
+ 'data-src="'
|
||||||
+ base_url_rand
|
+ resp.search_params['base_url']
|
||||||
+ 'embed/{videoid}" '
|
+ '/embed/{videoid}" '
|
||||||
+ 'frameborder="0" allowfullscreen></iframe>'
|
+ 'frameborder="0" allowfullscreen></iframe>'
|
||||||
)
|
)
|
||||||
|
|
||||||
base_invidious_url = base_url_rand + "watch?v="
|
base_invidious_url = resp.search_params['base_url'] + "/watch?v="
|
||||||
|
|
||||||
for result in search_results:
|
for result in search_results:
|
||||||
rtype = result.get("type", None)
|
rtype = result.get("type", None)
|
||||||
|
|
|
@ -786,11 +786,11 @@ engines:
|
||||||
# Instanes will be selected randomly, see https://api.invidious.io/ for
|
# Instanes will be selected randomly, see https://api.invidious.io/ for
|
||||||
# instances that are stable (good uptime) and close to you.
|
# instances that are stable (good uptime) and close to you.
|
||||||
base_url:
|
base_url:
|
||||||
- https://invidious.snopyta.org/
|
- https://invidious.snopyta.org
|
||||||
- https://vid.puffyan.us/
|
- https://vid.puffyan.us
|
||||||
- https://invidious.kavin.rocks/
|
# - https://invidious.kavin.rocks # Error 1020 // Access denied by Cloudflare
|
||||||
- https://invidio.xamh.de/
|
- https://invidio.xamh.de
|
||||||
- https://inv.riverside.rocks/
|
- https://inv.riverside.rocks
|
||||||
shortcut: iv
|
shortcut: iv
|
||||||
timeout: 3.0
|
timeout: 3.0
|
||||||
disabled: true
|
disabled: true
|
||||||
|
|
Loading…
Reference in New Issue