108 eng_region: str = traits.get_region(params[
'searxng_locale'],
'en_US')
109 eng_lang = traits.get_language(params[
'searxng_locale'],
'en')
113 'family_filter': family_filter_map.get(params[
'safesearch'],
'false'),
114 'thumbnail_ratio':
'original',
116 'languages': eng_lang,
117 'page': params[
'pageno'],
118 'password_protected':
'false',
121 'limit': number_of_results,
122 'fields':
','.join(result_fields),
125 args.update(safesearch_params.get(params[
'safesearch'], {}))
130 if len(params[
'searxng_locale'].split(
'-')) > 1:
132 args[
'localization'] = eng_region
133 args[
'country'] = eng_region.split(
'_')[1]
137 time_delta = time_delta_dict.get(params[
"time_range"])
139 created_after = datetime.now() - time_delta
140 args[
'created_after'] = datetime.timestamp(created_after)
142 query_str = urlencode(args)
143 params[
'url'] = search_url + query_str
152 search_res = resp.json()
155 if 'error' in search_res:
158 raise_for_httperror(resp)
161 for res
in search_res.get(
'list', []):
166 content = html_to_text(res[
'description'])
167 if len(content) > 300:
168 content = content[:300] +
'...'
170 publishedDate = datetime.fromtimestamp(res[
'created_time'],
None)
172 length = time.gmtime(res.get(
'duration'))
174 length = time.strftime(
"%H:%M:%S", length)
176 length = time.strftime(
"%M:%S", length)
178 thumbnail = res[
'thumbnail_360_url']
179 thumbnail = thumbnail.replace(
"http://",
"https://")
182 'template':
'videos.html',
186 'publishedDate': publishedDate,
188 'thumbnail': thumbnail,
193 if res[
'allow_embed']:
194 item[
'iframe_src'] = iframe_src.format(video_id=res[
'id'])
203 """Fetch locales & languages from dailymotion.
205 Locales fetched from `api/locales <https://api.dailymotion.com/locales>`_.
206 There are duplications in the locale codes returned from Dailymotion which
209 en_EN --> en_GB, en_US
210 ar_AA --> ar_EG, ar_AE, ar_SA
212 The language list `api/languages <https://api.dailymotion.com/languages>`_
213 contains over 7000 *languages* codes (see PR1071_). We use only those
214 language codes that are used in the locales.
216 .. _PR1071: https://github.com/searxng/searxng/pull/1071
220 resp = get(
'https://api.dailymotion.com/locales')
222 print(
"ERROR: response from dailymotion/locales is not OK.")
224 for item
in resp.json()[
'list']:
225 eng_tag = item[
'locale']
226 if eng_tag
in (
'en_EN',
'ar_AA'):
229 sxng_tag = region_tag(babel.Locale.parse(eng_tag))
230 except babel.UnknownLocaleError:
231 print(
"ERROR: item unknown --> %s" % item)
234 conflict = engine_traits.regions.get(sxng_tag)
236 if conflict != eng_tag:
237 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
239 engine_traits.regions[sxng_tag] = eng_tag
241 locale_lang_list = [x.split(
'_')[0]
for x
in engine_traits.regions.values()]
243 resp = get(
'https://api.dailymotion.com/languages')
245 print(
"ERROR: response from dailymotion/languages is not OK.")
247 for item
in resp.json()[
'list']:
248 eng_tag = item[
'code']
249 if eng_tag
in locale_lang_list:
250 sxng_tag = language_tag(babel.Locale.parse(eng_tag))
251 engine_traits.languages[sxng_tag] = eng_tag