202def fetch_traits(engine_traits: EngineTraits):
203 """Fetch locales & languages from dailymotion.
204
205 Locales fetched from `api/locales <https://api.dailymotion.com/locales>`_.
206 There are duplications in the locale codes returned from Dailymotion which
207 can be ignored::
208
209 en_EN --> en_GB, en_US
210 ar_AA --> ar_EG, ar_AE, ar_SA
211
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.
215
216 .. _PR1071: https://github.com/searxng/searxng/pull/1071
217
218 """
219
220 resp = get('https://api.dailymotion.com/locales')
221 if not resp.ok:
222 print("ERROR: response from dailymotion/locales is not OK.")
223
224 for item in resp.json()['list']:
225 eng_tag = item['locale']
226 if eng_tag in ('en_EN', 'ar_AA'):
227 continue
228 try:
229 sxng_tag = region_tag(babel.Locale.parse(eng_tag))
230 except babel.UnknownLocaleError:
231 print("ERROR: item unknown --> %s" % item)
232 continue
233
234 conflict = engine_traits.regions.get(sxng_tag)
235 if conflict:
236 if conflict != eng_tag:
237 print("CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
238 continue
239 engine_traits.regions[sxng_tag] = eng_tag
240
241 locale_lang_list = [x.split('_')[0] for x in engine_traits.regions.values()]
242
243 resp = get('https://api.dailymotion.com/languages')
244 if not resp.ok:
245 print("ERROR: response from dailymotion/languages is not OK.")
246
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