.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.invidious Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ["videos", "music"]
 
bool paging = True
 
bool time_range_support = True
 
str base_url = 'https://vid.puffyan.us'
 

Detailed Description

Invidious (Videos)

Function Documentation

◆ request()

searx.engines.invidious.request ( query,
params )

Definition at line 31 of file invidious.py.

31def request(query, params):
32 time_range_dict = {
33 "day": "today",
34 "week": "week",
35 "month": "month",
36 "year": "year",
37 }
38
39 if isinstance(base_url, list):
40 params["base_url"] = random.choice(base_url)
41 else:
42 params["base_url"] = base_url
43
44 search_url = params["base_url"] + "/api/v1/search?q={query}"
45 params["url"] = search_url.format(query=quote_plus(query)) + "&page={pageno}".format(pageno=params["pageno"])
46
47 if params["time_range"] in time_range_dict:
48 params["url"] += "&date={timerange}".format(timerange=time_range_dict[params["time_range"]])
49
50 if params["language"] != "all":
51 lang = params["language"].split("-")
52 if len(lang) == 2:
53 params["url"] += "&range={lrange}".format(lrange=lang[1])
54
55 return params
56
57

References searx.format.

◆ response()

searx.engines.invidious.response ( resp)

Definition at line 58 of file invidious.py.

58def response(resp):
59 results = []
60
61 search_results = resp.json()
62 base_invidious_url = resp.search_params['base_url'] + "/watch?v="
63
64 for result in search_results:
65 rtype = result.get("type", None)
66 if rtype == "video":
67 videoid = result.get("videoId", None)
68 if not videoid:
69 continue
70
71 url = base_invidious_url + videoid
72 thumbs = result.get("videoThumbnails", [])
73 thumb = next((th for th in thumbs if th["quality"] == "sddefault"), None)
74 if thumb:
75 thumbnail = thumb.get("url", "")
76 else:
77 thumbnail = ""
78
79 # some instances return a partial thumbnail url
80 # we check if the url is partial, and prepend the base_url if it is
81 if thumbnail and not urlparse(thumbnail).netloc:
82 thumbnail = resp.search_params['base_url'] + thumbnail
83
84 publishedDate = parser.parse(time.ctime(result.get("published", 0)))
85 length = time.gmtime(result.get("lengthSeconds"))
86 if length.tm_hour:
87 length = time.strftime("%H:%M:%S", length)
88 else:
89 length = time.strftime("%M:%S", length)
90
91 results.append(
92 {
93 "url": url,
94 "title": result.get("title", ""),
95 "content": result.get("description", ""),
96 "length": length,
97 "views": humanize_number(result['viewCount']),
98 "template": "videos.html",
99 "author": result.get("author"),
100 "publishedDate": publishedDate,
101 "iframe_src": resp.search_params['base_url'] + '/embed/' + videoid,
102 "thumbnail": thumbnail,
103 }
104 )
105
106 return results

Variable Documentation

◆ about

dict searx.engines.invidious.about
Initial value:
1= {
2 "website": 'https://api.invidious.io/',
3 "wikidata_id": 'Q79343316',
4 "official_api_documentation": 'https://github.com/iv-org/documentation/blob/master/API.md',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 13 of file invidious.py.

◆ base_url

str searx.engines.invidious.base_url = 'https://vid.puffyan.us'

Definition at line 28 of file invidious.py.

◆ categories

list searx.engines.invidious.categories = ["videos", "music"]

Definition at line 23 of file invidious.py.

◆ paging

bool searx.engines.invidious.paging = True

Definition at line 24 of file invidious.py.

◆ time_range_support

bool searx.engines.invidious.time_range_support = True

Definition at line 25 of file invidious.py.