diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2022-10-03 18:09:37 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2023-03-24 10:37:42 +0100 |
commit | fc0c7750301b3475631ddd34a031451e068235b0 (patch) | |
tree | 1ed80f0c8069064d35d75f285e5484924b384feb /searx/engines/dailymotion.py | |
parent | 61383edb27c50c3316226f88c60837d4a3c4f540 (diff) | |
download | searxng-fc0c7750301b3475631ddd34a031451e068235b0.tar.gz searxng-fc0c7750301b3475631ddd34a031451e068235b0.zip |
[mod] Dailymotion: fetch engine traits (data_type: supported_languages)
Implements a fetch_traits function for the Dailymotion engine.
.. note::
Does not include migration of the request methode from 'supported_languages'
to 'traits' (EngineTraits) object!
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/dailymotion.py')
-rw-r--r-- | searx/engines/dailymotion.py | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/searx/engines/dailymotion.py b/searx/engines/dailymotion.py index 7dd84dd27..1da3f4e0e 100644 --- a/searx/engines/dailymotion.py +++ b/searx/engines/dailymotion.py @@ -10,8 +10,9 @@ import time import babel from searx.exceptions import SearxEngineAPIException -from searx.network import raise_for_httperror +from searx import network from searx.utils import html_to_text +from searx.enginelib.traits import EngineTraits # about about = { @@ -123,7 +124,7 @@ def response(resp): if 'error' in search_res: raise SearxEngineAPIException(search_res['error'].get('message')) - raise_for_httperror(resp) + network.raise_for_httperror(resp) # parse results for res in search_res.get('list', []): @@ -171,3 +172,41 @@ def response(resp): def _fetch_supported_languages(resp): response_json = resp.json() return [item['locale'] for item in response_json['list']] + + +def fetch_traits(engine_traits: EngineTraits): + """Fetch regions from dailymotion. + + There are duplications in the locale codes returned from Dailymotion which + can be ignored:: + + en_EN --> en_GB, en_US + ar_AA --> ar_EG, ar_AE, ar_SA + + """ + # pylint: disable=import-outside-toplevel + + engine_traits.data_type = 'supported_languages' # deprecated + + from searx.locales import region_tag + + resp = network.get('https://api.dailymotion.com/locales') + if not resp.ok: + print("ERROR: response from peertube is not OK.") + + for item in resp.json()['list']: + eng_tag = item['locale'] + if eng_tag in ('en_EN', 'ar_AA'): + continue + try: + sxng_tag = region_tag(babel.Locale.parse(eng_tag)) + except babel.UnknownLocaleError: + print("ERROR: item unknown --> %s" % item) + continue + + conflict = engine_traits.regions.get(sxng_tag) + if conflict: + if conflict != eng_tag: + print("CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag)) + continue + engine_traits.regions[sxng_tag] = eng_tag |