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

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['videos', 'music']
 
bool paging = False
 
 api_key = None
 
str base_url = 'https://www.googleapis.com/youtube/v3/search'
 
str search_url = base_url + '?part=snippet&{query}&maxResults=20&key={api_key}'
 
str base_youtube_url = 'https://www.youtube.com/watch?v='
 

Detailed Description

 Youtube (Videos)

Function Documentation

◆ request()

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

Definition at line 34 of file youtube_api.py.

34def request(query, params):
35 params['url'] = search_url.format(query=urlencode({'q': query}), api_key=api_key)
36
37 # add language tag if specified
38 if params['language'] != 'all':
39 params['url'] += '&relevanceLanguage=' + params['language'].split('-')[0]
40
41 return params
42
43
44# get response from search-request

◆ response()

searx.engines.youtube_api.response ( resp)

Definition at line 45 of file youtube_api.py.

45def response(resp):
46 results = []
47
48 search_results = loads(resp.text)
49
50 if 'error' in search_results and 'message' in search_results['error']:
51 raise SearxEngineAPIException(search_results['error']['message'])
52
53 # return empty array if there are no results
54 if 'items' not in search_results:
55 return []
56
57 # parse results
58 for result in search_results['items']:
59 if "videoId" not in result["id"]:
60 # ignore channels
61 continue
62
63 videoid = result['id']['videoId']
64
65 title = result['snippet']['title']
66 content = ''
67 thumbnail = ''
68
69 pubdate = result['snippet']['publishedAt']
70 publishedDate = parser.parse(pubdate)
71
72 thumbnail = result['snippet']['thumbnails']['high']['url']
73
74 content = result['snippet']['description']
75
76 url = base_youtube_url + videoid
77
78 # append result
79 results.append(
80 {
81 'url': url,
82 'title': title,
83 'content': content,
84 'template': 'videos.html',
85 'publishedDate': publishedDate,
86 'iframe_src': "https://www.youtube-nocookie.com/embed/" + videoid,
87 'thumbnail': thumbnail,
88 }
89 )
90
91 # return results
92 return results

Variable Documentation

◆ about

dict searx.engines.youtube_api.about
Initial value:
1= {
2 "website": 'https://www.youtube.com/',
3 "wikidata_id": 'Q866',
4 "official_api_documentation": 'https://developers.google.com/youtube/v3/docs/search/list?apix=true',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 13 of file youtube_api.py.

◆ api_key

searx.engines.youtube_api.api_key = None

Definition at line 25 of file youtube_api.py.

◆ base_url

str searx.engines.youtube_api.base_url = 'https://www.googleapis.com/youtube/v3/search'

Definition at line 28 of file youtube_api.py.

◆ base_youtube_url

str searx.engines.youtube_api.base_youtube_url = 'https://www.youtube.com/watch?v='

Definition at line 30 of file youtube_api.py.

◆ categories

list searx.engines.youtube_api.categories = ['videos', 'music']

Definition at line 23 of file youtube_api.py.

◆ paging

bool searx.engines.youtube_api.paging = False

Definition at line 24 of file youtube_api.py.

◆ search_url

str searx.engines.youtube_api.search_url = base_url + '?part=snippet&{query}&maxResults=20&key={api_key}'

Definition at line 29 of file youtube_api.py.