SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[feat] mediathekviewweb: modernize engine to use EngineResults (#6717)
Bnyro71a2424c24c2
diff --git a/searx/engines/mediathekviewweb.py b/searx/engines/mediathekviewweb.pyindex 70afc4057..2125b5a88 100644--- a/searx/engines/mediathekviewweb.py+++ b/searx/engines/mediathekviewweb.py@@ -1,73 +1,77 @@# SPDX-License-Identifier: AGPL-3.0-or-later"""MediathekViewWeb (API)"""+import typing as timport datetime-from json import loads, dumps++from searx.result_types import EngineResults++if t.TYPE_CHECKING:+ from searx.extended_types import SXNG_Response+ from searx.search.processors import OnlineParamsabout = {- "website": 'https://mediathekviewweb.de/',- "wikidata_id": 'Q27877380',- "official_api_documentation": 'https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de',+ "website": "https://mediathekviewweb.de/",+ "wikidata_id": "Q27877380",+ "official_api_documentation": "https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de","use_official_api": True,"require_api_key": False,- "results": 'JSON',+ "results": "JSON",}language = "de"-categories = ['videos']+categories = ["videos"]paging = Truetime_range_support = Falsesafesearch = False-def request(query, params):+def request(query: str, params: "OnlineParams"):- params['url'] = 'https://mediathekviewweb.de/api/query'- params['method'] = 'POST'- params['headers']['Content-type'] = 'text/plain'- params['data'] = dumps(- {- 'queries': [- {- 'fields': [- 'title',- 'topic',- ],- 'query': query,- },- ],- 'sortBy': 'timestamp',- 'sortOrder': 'desc',- 'future': True,- 'offset': (params['pageno'] - 1) * 10,- 'size': 10,- }- )- return params+ params["url"] = "https://mediathekviewweb.de/api/query"+ params["method"] = "POST"+ params["headers"]["Content-type"] = "text/plain"+ params["json"] = {+ "queries": [+ {+ "fields": [+ "title",+ "topic",+ ],+ "query": query,+ },+ ],+ "sortBy": "timestamp",+ "sortOrder": "desc",+ "future": True,+ "offset": (params["pageno"] - 1) * 10,+ "size": 10,+ }-def response(resp):+def response(resp: "SXNG_Response") -> EngineResults:- resp = loads(resp.text)+ json_resp: dict[str, t.Any] = resp.json()- mwv_result = resp['result']- mwv_result_list = mwv_result['results']+ mwv_result = json_resp["result"]+ mwv_result_list = mwv_result["results"]- results = []+ res = EngineResults()for item in mwv_result_list:+ item["hms"] = str(datetime.timedelta(seconds=item["duration"]))- item['hms'] = str(datetime.timedelta(seconds=item['duration']))+ video_url = item["url_video_hd"]- results.append(- {- 'url': item['url_video_hd'].replace("http://", "https://"),- 'title': "%(channel)s: %(title)s (%(hms)s)" % item,- 'length': item['hms'],- 'content': "%(description)s" % item,- 'iframe_src': item['url_video_hd'].replace("http://", "https://"),- 'template': 'videos.html',- }+ res.add(+ res.types.LegacyResult(+ url=video_url,+ title="%(channel)s: %(title)s (%(hms)s)" % item,+ length=item["hms"],+ content="%(description)s" % item,+ iframe_src=video_url,+ template="videos.html",+ ))- return results+ return res