summaryrefslogtreecommitdiff
path: root/searx/engines/bing_videos.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2023-09-27 18:24:33 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2023-10-01 08:01:38 +0200
commit32a4ea350ee0bbbc1b1a941391626b53e4894920 (patch)
treef434e25770dcc33d5d71ab0767966ba996006e0d /searx/engines/bing_videos.py
parent079636c0795aafed9306703a4decdc92447ed57f (diff)
downloadsearxng-32a4ea350ee0bbbc1b1a941391626b53e4894920.tar.gz
searxng-32a4ea350ee0bbbc1b1a941391626b53e4894920.zip
[fix] Revision of the Bing engines
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/bing_videos.py')
-rw-r--r--searx/engines/bing_videos.py42
1 files changed, 8 insertions, 34 deletions
diff --git a/searx/engines/bing_videos.py b/searx/engines/bing_videos.py
index d4cb6058b..41bf2d3e1 100644
--- a/searx/engines/bing_videos.py
+++ b/searx/engines/bing_videos.py
@@ -11,10 +11,9 @@ from urllib.parse import urlencode
from lxml import html
from searx.enginelib.traits import EngineTraits
-from searx.engines.bing import (
- set_bing_cookies,
- _fetch_traits,
-)
+from searx.engines.bing import set_bing_cookies
+from searx.engines.bing import fetch_traits # pylint: disable=unused-import
+from searx.engines.bing_images import time_map
if TYPE_CHECKING:
import logging
@@ -42,25 +41,12 @@ time_range_support = True
base_url = 'https://www.bing.com/videos/asyncv2'
"""Bing (Videos) async search URL."""
-bing_traits_url = 'https://learn.microsoft.com/en-us/bing/search-apis/bing-video-search/reference/market-codes'
-"""Bing (Video) search API description"""
-
-time_map = {
- # fmt: off
- 'day': 60 * 24,
- 'week': 60 * 24 * 7,
- 'month': 60 * 24 * 31,
- 'year': 60 * 24 * 365,
- # fmt: on
-}
-
def request(query, params):
"""Assemble a Bing-Video request."""
- engine_region = traits.get_region(params['searxng_locale'], 'en-us')
- engine_language = traits.get_language(params['searxng_locale'], 'en-us')
-
+ engine_region = traits.get_region(params['searxng_locale'], traits.all_locale) # type: ignore
+ engine_language = traits.get_language(params['searxng_locale'], 'en') # type: ignore
set_bing_cookies(params, engine_language, engine_region)
# build URL query
@@ -68,13 +54,11 @@ def request(query, params):
# example: https://www.bing.com/videos/asyncv2?q=foo&async=content&first=1&count=35
query_params = {
- # fmt: off
'q': query,
- 'async' : 'content',
+ 'async': 'content',
# to simplify the page count lets use the default of 35 images per page
- 'first' : (int(params.get('pageno', 1)) - 1) * 35 + 1,
- 'count' : 35,
- # fmt: on
+ 'first': (int(params.get('pageno', 1)) - 1) * 35 + 1,
+ 'count': 35,
}
# time range
@@ -113,13 +97,3 @@ def response(resp):
)
return results
-
-
-def fetch_traits(engine_traits: EngineTraits):
- """Fetch languages and regions from Bing-Videos."""
-
- xpath_market_codes = '//table[1]/tbody/tr/td[3]'
- # xpath_country_codes = '//table[2]/tbody/tr/td[2]'
- xpath_language_codes = '//table[3]/tbody/tr/td[2]'
-
- _fetch_traits(engine_traits, bing_traits_url, xpath_language_codes, xpath_market_codes)