[fix] bing engine: query string only support 2 letter language code

The 'language:xx' query string in the request() function does only support the 2
letter language codes from the "Display languages" list.

Examples of items from the "Display languages" not sopported in the query
string:

  pt-BR, pt-BR, mn-Cyrl-MN, chr-cher, zh-Hans, ha-latn, ca-es-valencia

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2022-04-10 15:43:41 +02:00
parent 864aeebc2f
commit d97e1a479f
3 changed files with 64 additions and 83 deletions

View file

@ -4,14 +4,13 @@
"am", "am",
"ar", "ar",
"as", "as",
"az-latn", "az",
"be", "be",
"bg", "bg",
"bn", "bn",
"bs-latn", "bs",
"ca", "ca",
"ca-es-valencia", "chr",
"chr-cher",
"cs", "cs",
"cy", "cy",
"da", "da",
@ -29,7 +28,7 @@
"gd", "gd",
"gl", "gl",
"gu", "gu",
"ha-latn", "ha",
"he", "he",
"hi", "hi",
"hr", "hr",
@ -46,7 +45,7 @@
"kn", "kn",
"ko", "ko",
"kok", "kok",
"ku-arab", "ku",
"ky", "ky",
"lb", "lb",
"lo", "lo",
@ -55,7 +54,7 @@
"mi", "mi",
"mk", "mk",
"ml", "ml",
"mn-Cyrl-MN", "mn",
"mr", "mr",
"ms", "ms",
"mt", "mt",
@ -65,29 +64,26 @@
"nn", "nn",
"nso", "nso",
"or", "or",
"pa-arab", "pa",
"pa-guru",
"pl", "pl",
"prs", "prs",
"pt-BR", "pt",
"pt-PT",
"quc", "quc",
"quz", "quz",
"ro", "ro",
"ru", "ru",
"rw", "rw",
"sd-arab", "sd",
"si", "si",
"sk", "sk",
"sl", "sl",
"sq", "sq",
"sr-cyrl", "sr",
"sr-latn",
"sv", "sv",
"sw", "sw",
"ta", "ta",
"te", "te",
"tg-cyrl", "tg",
"th", "th",
"ti", "ti",
"tk", "tk",
@ -97,13 +93,12 @@
"ug", "ug",
"uk", "uk",
"ur", "ur",
"uz-latn", "uz",
"vi", "vi",
"wo", "wo",
"xh", "xh",
"yo", "yo",
"zh-Hans", "zh",
"zh-Hant",
"zu" "zu"
], ],
"bing images": [ "bing images": [
@ -111,14 +106,13 @@
"am", "am",
"ar", "ar",
"as", "as",
"az-latn", "az",
"be", "be",
"bg", "bg",
"bn", "bn",
"bs-latn", "bs",
"ca", "ca",
"ca-es-valencia", "chr",
"chr-cher",
"cs", "cs",
"cy", "cy",
"da", "da",
@ -136,7 +130,7 @@
"gd", "gd",
"gl", "gl",
"gu", "gu",
"ha-latn", "ha",
"he", "he",
"hi", "hi",
"hr", "hr",
@ -153,7 +147,7 @@
"kn", "kn",
"ko", "ko",
"kok", "kok",
"ku-arab", "ku",
"ky", "ky",
"lb", "lb",
"lo", "lo",
@ -162,7 +156,7 @@
"mi", "mi",
"mk", "mk",
"ml", "ml",
"mn-Cyrl-MN", "mn",
"mr", "mr",
"ms", "ms",
"mt", "mt",
@ -172,29 +166,26 @@
"nn", "nn",
"nso", "nso",
"or", "or",
"pa-arab", "pa",
"pa-guru",
"pl", "pl",
"prs", "prs",
"pt-BR", "pt",
"pt-PT",
"quc", "quc",
"quz", "quz",
"ro", "ro",
"ru", "ru",
"rw", "rw",
"sd-arab", "sd",
"si", "si",
"sk", "sk",
"sl", "sl",
"sq", "sq",
"sr-cyrl", "sr",
"sr-latn",
"sv", "sv",
"sw", "sw",
"ta", "ta",
"te", "te",
"tg-cyrl", "tg",
"th", "th",
"ti", "ti",
"tk", "tk",
@ -204,13 +195,12 @@
"ug", "ug",
"uk", "uk",
"ur", "ur",
"uz-latn", "uz",
"vi", "vi",
"wo", "wo",
"xh", "xh",
"yo", "yo",
"zh-Hans", "zh",
"zh-Hant",
"zu" "zu"
], ],
"bing news": [ "bing news": [
@ -218,14 +208,13 @@
"am", "am",
"ar", "ar",
"as", "as",
"az-latn", "az",
"be", "be",
"bg", "bg",
"bn", "bn",
"bs-latn", "bs",
"ca", "ca",
"ca-es-valencia", "chr",
"chr-cher",
"cs", "cs",
"cy", "cy",
"da", "da",
@ -243,7 +232,7 @@
"gd", "gd",
"gl", "gl",
"gu", "gu",
"ha-latn", "ha",
"he", "he",
"hi", "hi",
"hr", "hr",
@ -260,7 +249,7 @@
"kn", "kn",
"ko", "ko",
"kok", "kok",
"ku-arab", "ku",
"ky", "ky",
"lb", "lb",
"lo", "lo",
@ -269,7 +258,7 @@
"mi", "mi",
"mk", "mk",
"ml", "ml",
"mn-Cyrl-MN", "mn",
"mr", "mr",
"ms", "ms",
"mt", "mt",
@ -279,29 +268,26 @@
"nn", "nn",
"nso", "nso",
"or", "or",
"pa-arab", "pa",
"pa-guru",
"pl", "pl",
"prs", "prs",
"pt-BR", "pt",
"pt-PT",
"quc", "quc",
"quz", "quz",
"ro", "ro",
"ru", "ru",
"rw", "rw",
"sd-arab", "sd",
"si", "si",
"sk", "sk",
"sl", "sl",
"sq", "sq",
"sr-cyrl", "sr",
"sr-latn",
"sv", "sv",
"sw", "sw",
"ta", "ta",
"te", "te",
"tg-cyrl", "tg",
"th", "th",
"ti", "ti",
"tk", "tk",
@ -311,13 +297,12 @@
"ug", "ug",
"uk", "uk",
"ur", "ur",
"uz-latn", "uz",
"vi", "vi",
"wo", "wo",
"xh", "xh",
"yo", "yo",
"zh-Hans", "zh",
"zh-Hant",
"zu" "zu"
], ],
"bing videos": [ "bing videos": [
@ -325,14 +310,13 @@
"am", "am",
"ar", "ar",
"as", "as",
"az-latn", "az",
"be", "be",
"bg", "bg",
"bn", "bn",
"bs-latn", "bs",
"ca", "ca",
"ca-es-valencia", "chr",
"chr-cher",
"cs", "cs",
"cy", "cy",
"da", "da",
@ -350,7 +334,7 @@
"gd", "gd",
"gl", "gl",
"gu", "gu",
"ha-latn", "ha",
"he", "he",
"hi", "hi",
"hr", "hr",
@ -367,7 +351,7 @@
"kn", "kn",
"ko", "ko",
"kok", "kok",
"ku-arab", "ku",
"ky", "ky",
"lb", "lb",
"lo", "lo",
@ -376,7 +360,7 @@
"mi", "mi",
"mk", "mk",
"ml", "ml",
"mn-Cyrl-MN", "mn",
"mr", "mr",
"ms", "ms",
"mt", "mt",
@ -386,29 +370,26 @@
"nn", "nn",
"nso", "nso",
"or", "or",
"pa-arab", "pa",
"pa-guru",
"pl", "pl",
"prs", "prs",
"pt-BR", "pt",
"pt-PT",
"quc", "quc",
"quz", "quz",
"ro", "ro",
"ru", "ru",
"rw", "rw",
"sd-arab", "sd",
"si", "si",
"sk", "sk",
"sl", "sl",
"sq", "sq",
"sr-cyrl", "sr",
"sr-latn",
"sv", "sv",
"sw", "sw",
"ta", "ta",
"te", "te",
"tg-cyrl", "tg",
"th", "th",
"ti", "ti",
"tk", "tk",
@ -418,13 +399,12 @@
"ug", "ug",
"uk", "uk",
"ur", "ur",
"uz-latn", "uz",
"vi", "vi",
"wo", "wo",
"xh", "xh",
"yo", "yo",
"zh-Hans", "zh",
"zh-Hant",
"zu" "zu"
], ],
"dailymotion": [ "dailymotion": [

View file

@ -131,21 +131,24 @@ def _fetch_supported_languages(resp):
lang_tags = set() lang_tags = set()
dom = html.fromstring(resp.text) dom = html.fromstring(resp.text)
lang_links = eval_xpath(dom, '//div[@id="language-section"]//li')
for _li in lang_links: # Selector to get items from "Display language"
ui_lang_links = eval_xpath(dom, '//div[@id="language-section"]//li')
for _li in ui_lang_links:
href = eval_xpath(_li, './/@href')[0] href = eval_xpath(_li, './/@href')[0]
(_scheme, _netloc, _path, _params, query, _fragment) = urlparse(href) (_scheme, _netloc, _path, _params, query, _fragment) = urlparse(href)
query = parse_qs(query, keep_blank_values=True) query = parse_qs(query, keep_blank_values=True)
# fmt: off # The 'language:xx' query string in the request function (above) does
setlang = query.get('setlang', [None, ])[0] # only support the 2 letter language codes from the "Display languages"
# example: 'mn-Cyrl-MN' --> '['mn', 'Cyrl-MN'] # list. Examples of items from the "Display languages" not sopported in
lang, nation = (setlang.split('-', maxsplit=1) + [None,])[:2] # fmt: skip # the query string:
# fmt: on # 'mn-Cyrl-MN', 'chr-cher', 'zh-Hans', ha-latn, 'ca-es-valencia'
tag = lang + '-' + nation if nation else lang setlang = query.get('setlang', [None, ])[0]
lang_tags.add(tag) lang = setlang.split('-')[0]
lang_tags.add(lang)
return list(lang_tags) return list(lang_tags)

View file

@ -49,8 +49,6 @@ language_codes = (
('nl-BE', 'Nederlands', 'België', 'Dutch', '\U0001f1e7\U0001f1ea'), ('nl-BE', 'Nederlands', 'België', 'Dutch', '\U0001f1e7\U0001f1ea'),
('nl-NL', 'Nederlands', 'Nederland', 'Dutch', '\U0001f1f3\U0001f1f1'), ('nl-NL', 'Nederlands', 'Nederland', 'Dutch', '\U0001f1f3\U0001f1f1'),
('pl-PL', 'Polski', 'Polska', 'Polish', '\U0001f1f5\U0001f1f1'), ('pl-PL', 'Polski', 'Polska', 'Polish', '\U0001f1f5\U0001f1f1'),
('pt', 'Português', '', 'Portuguese', '\U0001f310'),
('pt-BR', 'Português', 'Brasil', 'Portuguese', '\U0001f1e7\U0001f1f7'),
('pt-PT', 'Português', 'Portugal', 'Portuguese', '\U0001f1f5\U0001f1f9'), ('pt-PT', 'Português', 'Portugal', 'Portuguese', '\U0001f1f5\U0001f1f9'),
('ro-RO', 'Română', 'România', 'Romanian', '\U0001f1f7\U0001f1f4'), ('ro-RO', 'Română', 'România', 'Romanian', '\U0001f1f7\U0001f1f4'),
('ru-RU', 'Русский', 'Россия', 'Russian', '\U0001f1f7\U0001f1fa'), ('ru-RU', 'Русский', 'Россия', 'Russian', '\U0001f1f7\U0001f1fa'),