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