diff options
author | Bnyro <bnyro@tutanota.com> | 2023-09-11 10:24:57 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-09-13 21:41:33 +0200 |
commit | 3568a3cafb6fca6ef71552806885bad3bc5bf669 (patch) | |
tree | adb33e5738e9d0a6b47d96503f8b71440f74f4e5 | |
parent | 09c61dabc9927ee075626188a93c6b2aea32a869 (diff) | |
download | searxng-3568a3cafb6fca6ef71552806885bad3bc5bf669.tar.gz searxng-3568a3cafb6fca6ef71552806885bad3bc5bf669.zip |
[feat] odysee: implement fetch_traits for language support
-rw-r--r-- | searx/engines/odysee.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/searx/engines/odysee.py b/searx/engines/odysee.py index 4b0f49375..89d11d093 100644 --- a/searx/engines/odysee.py +++ b/searx/engines/odysee.py @@ -9,6 +9,14 @@ import time from urllib.parse import urlencode from datetime import datetime +import babel + +from searx.network import get +from searx.locales import language_tag +from searx.enginelib.traits import EngineTraits + +traits: EngineTraits + # Engine metadata about = { "website": "https://odysee.com/", @@ -46,6 +54,10 @@ def request(query, params): "mediaType": "video", } + lang = traits.get_language(params['searxng_locale'], None) + if lang is not None: + query_params['language'] = lang + if params['time_range'] in time_range_dict: query_params['time_filter'] = time_range_dict[params['time_range']] @@ -99,3 +111,35 @@ def response(resp): ) return results + + +def fetch_traits(engine_traits: EngineTraits): + """ + Fetch languages from Odysee's source code. + """ + + resp = get( + 'https://raw.githubusercontent.com/OdyseeTeam/odysee-frontend/master/ui/constants/supported_browser_languages.js', # pylint: disable=line-too-long + timeout=60, + ) + + if not resp.ok: + print("ERROR: can't determine languages from Odysee") + return + + for line in resp.text.split("\n")[1:-4]: + lang_tag = line.strip().split(": ")[0].replace("'", "") + + try: + sxng_tag = language_tag(babel.Locale.parse(lang_tag, sep="-")) + except babel.UnknownLocaleError: + print("ERROR: %s is unknown by babel" % lang_tag) + continue + + conflict = engine_traits.languages.get(sxng_tag) + if conflict: + if conflict != lang_tag: + print("CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, lang_tag)) + continue + + engine_traits.languages[sxng_tag] = lang_tag |