99 eng_region: str = traits.get_region(params[
'searxng_locale'],
'en_US')
100 eng_lang = traits.get_language(params[
'searxng_locale'],
'en')
104 'family_filter': family_filter_map.get(params[
'safesearch'],
'false'),
105 'thumbnail_ratio':
'original',
107 'languages': eng_lang,
108 'page': params[
'pageno'],
109 'password_protected':
'false',
112 'limit': number_of_results,
113 'fields':
','.join(result_fields),
116 args.update(safesearch_params.get(params[
'safesearch'], {}))
121 if len(params[
'searxng_locale'].split(
'-')) > 1:
123 args[
'localization'] = eng_region
124 args[
'country'] = eng_region.split(
'_')[1]
128 time_delta = time_delta_dict.get(params[
"time_range"])
130 created_after = datetime.now() - time_delta
131 args[
'created_after'] = datetime.timestamp(created_after)
133 query_str = urlencode(args)
134 params[
'url'] = search_url + query_str
143 search_res = resp.json()
146 if 'error' in search_res:
149 raise_for_httperror(resp)
152 for res
in search_res.get(
'list', []):
157 content = html_to_text(res[
'description'])
158 if len(content) > 300:
159 content = content[:300] +
'...'
161 publishedDate = datetime.fromtimestamp(res[
'created_time'],
None)
163 length = time.gmtime(res.get(
'duration'))
165 length = time.strftime(
"%H:%M:%S", length)
167 length = time.strftime(
"%M:%S", length)
169 thumbnail = res[
'thumbnail_360_url']
170 thumbnail = thumbnail.replace(
"http://",
"https://")
173 'template':
'videos.html',
177 'publishedDate': publishedDate,
179 'thumbnail': thumbnail,
184 if res[
'allow_embed']:
185 item[
'iframe_src'] = iframe_src.format(video_id=res[
'id'])
194 """Fetch locales & languages from dailymotion.
196 Locales fetched from `api/locales <https://api.dailymotion.com/locales>`_.
197 There are duplications in the locale codes returned from Dailymotion which
200 en_EN --> en_GB, en_US
201 ar_AA --> ar_EG, ar_AE, ar_SA
203 The language list `api/languages <https://api.dailymotion.com/languages>`_
204 contains over 7000 *languages* codes (see PR1071_). We use only those
205 language codes that are used in the locales.
207 .. _PR1071: https://github.com/searxng/searxng/pull/1071
211 resp = get(
'https://api.dailymotion.com/locales')
213 print(
"ERROR: response from dailymotion/locales is not OK.")
215 for item
in resp.json()[
'list']:
216 eng_tag = item[
'locale']
217 if eng_tag
in (
'en_EN',
'ar_AA'):
220 sxng_tag = region_tag(babel.Locale.parse(eng_tag))
221 except babel.UnknownLocaleError:
222 print(
"ERROR: item unknown --> %s" % item)
225 conflict = engine_traits.regions.get(sxng_tag)
227 if conflict != eng_tag:
228 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
230 engine_traits.regions[sxng_tag] = eng_tag
232 locale_lang_list = [x.split(
'_')[0]
for x
in engine_traits.regions.values()]
234 resp = get(
'https://api.dailymotion.com/languages')
236 print(
"ERROR: response from dailymotion/languages is not OK.")
238 for item
in resp.json()[
'list']:
239 eng_tag = item[
'code']
240 if eng_tag
in locale_lang_list:
241 sxng_tag = language_tag(babel.Locale.parse(eng_tag))
242 engine_traits.languages[sxng_tag] = eng_tag