forked from zaclys/searxng
[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>
This commit is contained in:
parent
61383edb27
commit
fc0c775030
|
@ -2020,7 +2020,56 @@
|
||||||
"custom": {},
|
"custom": {},
|
||||||
"data_type": "supported_languages",
|
"data_type": "supported_languages",
|
||||||
"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": [
|
"supported_languages": [
|
||||||
"ar_AA",
|
"ar_AA",
|
||||||
"ar_AE",
|
"ar_AE",
|
||||||
|
|
|
@ -10,8 +10,9 @@ import time
|
||||||
import babel
|
import babel
|
||||||
|
|
||||||
from searx.exceptions import SearxEngineAPIException
|
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.utils import html_to_text
|
||||||
|
from searx.enginelib.traits import EngineTraits
|
||||||
|
|
||||||
# about
|
# about
|
||||||
about = {
|
about = {
|
||||||
|
@ -123,7 +124,7 @@ def response(resp):
|
||||||
if 'error' in search_res:
|
if 'error' in search_res:
|
||||||
raise SearxEngineAPIException(search_res['error'].get('message'))
|
raise SearxEngineAPIException(search_res['error'].get('message'))
|
||||||
|
|
||||||
raise_for_httperror(resp)
|
network.raise_for_httperror(resp)
|
||||||
|
|
||||||
# parse results
|
# parse results
|
||||||
for res in search_res.get('list', []):
|
for res in search_res.get('list', []):
|
||||||
|
@ -171,3 +172,41 @@ def response(resp):
|
||||||
def _fetch_supported_languages(resp):
|
def _fetch_supported_languages(resp):
|
||||||
response_json = resp.json()
|
response_json = resp.json()
|
||||||
return [item['locale'] for item in response_json['list']]
|
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
|
||||||
|
|
Loading…
Reference in New Issue