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

Functions

 request (query, params)
 response (resp)

Variables

dict about
list categories = ['videos', 'web']
bool paging = True
int max_page = 50
bool language_support = True
bool time_range_support = True
bool safesearch = True

Detailed Description

This is the implementation of the Google Videos engine.

.. admonition:: Content-Security-Policy (CSP)

   This engine needs to allow images from the `data URLs`_ (prefixed with the
   ``data:`` scheme)::

     Header set Content-Security-Policy "img-src 'self' data: ;"

.. _data URLs:
   https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

Function Documentation

◆ request()

searx.engines.google_videos.request ( query,
params )
Google-Video search request

Definition at line 55 of file google_videos.py.

55def request(query, params):
56 """Google-Video search request"""
57 google_info = get_google_info(params, traits)
58 start = (params['pageno'] - 1) * 10
59
60 query_url = (
61 'https://'
62 + google_info['subdomain']
63 + '/search'
64 + "?"
65 + urlencode(
66 {
67 'q': query,
68 'tbm': "vid",
69 'start': start,
70 **google_info['params'],
71 'asearch': 'arc',
72 'async': ui_async(start),
73 }
74 )
75 )
76
77 if params['time_range'] in time_range_dict:
78 query_url += '&' + urlencode({'tbs': 'qdr:' + time_range_dict[params['time_range']]})
79 if 'safesearch' in params:
80 query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
81 params['url'] = query_url
82
83 params['cookies'] = google_info['cookies']
84 params['headers'].update(google_info['headers'])
85 return params
86
87

◆ response()

searx.engines.google_videos.response ( resp)
Get response from google's search request

Definition at line 88 of file google_videos.py.

88def response(resp):
89 """Get response from google's search request"""
90 results = []
91
92 detect_google_sorry(resp)
93 data_image_map = parse_data_images(resp.text)
94
95 # convert the text to dom
96 dom = html.fromstring(resp.text)
97
98 result_divs = eval_xpath_list(dom, '//div[contains(@class, "MjjYud")]')
99
100 # parse results
101 for result in result_divs:
102 title = extract_text(
103 eval_xpath_getindex(result, './/h3[contains(@class, "LC20lb")]', 0, default=None), allow_none=True
104 )
105 url = eval_xpath_getindex(result, './/a[@jsname="UWckNb"]/@href', 0, default=None)
106 content = extract_text(
107 eval_xpath_getindex(result, './/div[contains(@class, "ITZIwc")]', 0, default=None), allow_none=True
108 )
109 pub_info = extract_text(
110 eval_xpath_getindex(result, './/div[contains(@class, "gqF9jc")]', 0, default=None), allow_none=True
111 )
112 # Broader XPath to find any <img> element
113 thumbnail = eval_xpath_getindex(result, './/img/@src', 0, default=None)
114 duration = extract_text(
115 eval_xpath_getindex(result, './/span[contains(@class, "k1U36b")]', 0, default=None), allow_none=True
116 )
117 video_id = eval_xpath_getindex(result, './/div[@jscontroller="rTuANe"]/@data-vid', 0, default=None)
118
119 # Fallback for video_id from URL if not found via XPath
120 if not video_id and url and 'youtube.com' in url:
121 parsed_url = urlparse(url)
122 video_id = parse_qs(parsed_url.query).get('v', [None])[0]
123
124 # Handle thumbnail
125 if thumbnail and thumbnail.startswith('data:image'):
126 img_id = eval_xpath_getindex(result, './/img/@id', 0, default=None)
127 if img_id and img_id in data_image_map:
128 thumbnail = data_image_map[img_id]
129 else:
130 thumbnail = None
131 if not thumbnail and video_id:
132 thumbnail = f"https://img.youtube.com/vi/{video_id}/hqdefault.jpg"
133
134 # Handle video embed URL
135 embed_url = None
136 if video_id:
137 embed_url = get_embeded_stream_url(f"https://www.youtube.com/watch?v={video_id}")
138 elif url:
139 embed_url = get_embeded_stream_url(url)
140
141 # Only append results with valid title and url
142 if title and url:
143 results.append(
144 {
145 'url': url,
146 'title': title,
147 'content': content or '',
148 'author': pub_info,
149 'thumbnail': thumbnail,
150 'length': duration,
151 'iframe_src': embed_url,
152 'template': 'videos.html',
153 }
154 )
155
156 # parse suggestion
157 for suggestion in eval_xpath_list(dom, suggestion_xpath):
158 results.append({'suggestion': extract_text(suggestion)})
159
160 return results

Variable Documentation

◆ about

dict searx.engines.google_videos.about
Initial value:
1= {
2 "website": 'https://www.google.com',
3 "wikidata_id": 'Q219885',
4 "official_api_documentation": 'https://developers.google.com/custom-search',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 37 of file google_videos.py.

◆ categories

list searx.engines.google_videos.categories = ['videos', 'web']

Definition at line 47 of file google_videos.py.

◆ language_support

bool searx.engines.google_videos.language_support = True

Definition at line 50 of file google_videos.py.

◆ max_page

int searx.engines.google_videos.max_page = 50

Definition at line 49 of file google_videos.py.

◆ paging

bool searx.engines.google_videos.paging = True

Definition at line 48 of file google_videos.py.

◆ safesearch

bool searx.engines.google_videos.safesearch = True

Definition at line 52 of file google_videos.py.

◆ time_range_support

bool searx.engines.google_videos.time_range_support = True

Definition at line 51 of file google_videos.py.