summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-10-03 18:09:37 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2023-03-24 10:37:42 +0100
commitfc0c7750301b3475631ddd34a031451e068235b0 (patch)
tree1ed80f0c8069064d35d75f285e5484924b384feb
parent61383edb27c50c3316226f88c60837d4a3c4f540 (diff)
downloadsearxng-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>
-rw-r--r--searx/data/engine_traits.json51
-rw-r--r--searx/engines/dailymotion.py43
2 files changed, 91 insertions, 3 deletions
diff --git a/searx/data/engine_traits.json b/searx/data/engine_traits.json
index db7c428aa..945ed2644 100644
--- a/searx/data/engine_traits.json
+++ b/searx/data/engine_traits.json
@@ -2020,7 +2020,56 @@
"custom": {},
"data_type": "supported_languages",
"languages": {},
- "regions": {},
+ "regions": {
+ "ar-AE": "ar_AE",
+ "ar-EG": "ar_EG",
+ "ar-SA": "ar_SA",
+ "de-AT": "de_AT",
+ "de-CH": "de_CH",
+ "de-DE": "de_DE",
+ "el-GR": "el_GR",
+ "en-AU": "en_AU",
+ "en-CA": "en_CA",
+ "en-GB": "en_GB",
+ "en-HK": "en_HK",
+ "en-IE": "en_IE",
+ "en-IN": "en_IN",
+ "en-NG": "en_NG",
+ "en-PH": "en_PH",
+ "en-PK": "en_PK",
+ "en-SG": "en_SG",
+ "en-US": "en_US",
+ "en-ZA": "en_ZA",
+ "es-AR": "es_AR",
+ "es-ES": "es_ES",
+ "es-MX": "es_MX",
+ "fr-BE": "fr_BE",
+ "fr-CA": "fr_CA",
+ "fr-CH": "fr_CH",
+ "fr-CI": "fr_CI",
+ "fr-FR": "fr_FR",
+ "fr-MA": "fr_MA",
+ "fr-SN": "fr_SN",
+ "fr-TN": "fr_TN",
+ "id-ID": "id_ID",
+ "it-CH": "it_CH",
+ "it-IT": "it_IT",
+ "ja-JP": "ja_JP",
+ "ko-KR": "ko_KR",
+ "ms-MY": "ms_MY",
+ "nl-BE": "nl_BE",
+ "nl-NL": "nl_NL",
+ "pl-PL": "pl_PL",
+ "pt-BR": "pt_BR",
+ "pt-PT": "pt_PT",
+ "ro-RO": "ro_RO",
+ "ru-RU": "ru_RU",
+ "th-TH": "th_TH",
+ "tr-TR": "tr_TR",
+ "vi-VN": "vi_VN",
+ "zh-CN": "zh_CN",
+ "zh-TW": "zh_TW"
+ },
"supported_languages": [
"ar_AA",
"ar_AE",
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