mirror of
https://github.com/searxng/searxng.git
synced 2026-09-23 06:36:12 +00:00
[feat] mediathekviewweb: modernize engine to use EngineResults (#6717)
This commit is contained in:
@@ -1,73 +1,77 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""MediathekViewWeb (API)"""
|
"""MediathekViewWeb (API)"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
import datetime
|
import 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 OnlineParams
|
||||||
|
|
||||||
about = {
|
about = {
|
||||||
"website": 'https://mediathekviewweb.de/',
|
"website": "https://mediathekviewweb.de/",
|
||||||
"wikidata_id": 'Q27877380',
|
"wikidata_id": "Q27877380",
|
||||||
"official_api_documentation": 'https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de',
|
"official_api_documentation": "https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de",
|
||||||
"use_official_api": True,
|
"use_official_api": True,
|
||||||
"require_api_key": False,
|
"require_api_key": False,
|
||||||
"results": 'JSON',
|
"results": "JSON",
|
||||||
}
|
}
|
||||||
|
|
||||||
language = "de"
|
language = "de"
|
||||||
categories = ['videos']
|
categories = ["videos"]
|
||||||
paging = True
|
paging = True
|
||||||
time_range_support = False
|
time_range_support = False
|
||||||
safesearch = False
|
safesearch = False
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query: str, params: "OnlineParams"):
|
||||||
|
|
||||||
params['url'] = 'https://mediathekviewweb.de/api/query'
|
params["url"] = "https://mediathekviewweb.de/api/query"
|
||||||
params['method'] = 'POST'
|
params["method"] = "POST"
|
||||||
params['headers']['Content-type'] = 'text/plain'
|
params["headers"]["Content-type"] = "text/plain"
|
||||||
params['data'] = dumps(
|
params["json"] = {
|
||||||
{
|
"queries": [
|
||||||
'queries': [
|
{
|
||||||
{
|
"fields": [
|
||||||
'fields': [
|
"title",
|
||||||
'title',
|
"topic",
|
||||||
'topic',
|
],
|
||||||
],
|
"query": query,
|
||||||
'query': query,
|
},
|
||||||
},
|
],
|
||||||
],
|
"sortBy": "timestamp",
|
||||||
'sortBy': 'timestamp',
|
"sortOrder": "desc",
|
||||||
'sortOrder': 'desc',
|
"future": True,
|
||||||
'future': True,
|
"offset": (params["pageno"] - 1) * 10,
|
||||||
'offset': (params['pageno'] - 1) * 10,
|
"size": 10,
|
||||||
'size': 10,
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
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 = json_resp["result"]
|
||||||
mwv_result_list = mwv_result['results']
|
mwv_result_list = mwv_result["results"]
|
||||||
|
|
||||||
results = []
|
res = EngineResults()
|
||||||
|
|
||||||
for item in mwv_result_list:
|
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(
|
res.add(
|
||||||
{
|
res.types.LegacyResult(
|
||||||
'url': item['url_video_hd'].replace("http://", "https://"),
|
url=video_url,
|
||||||
'title': "%(channel)s: %(title)s (%(hms)s)" % item,
|
title="%(channel)s: %(title)s (%(hms)s)" % item,
|
||||||
'length': item['hms'],
|
length=item["hms"],
|
||||||
'content': "%(description)s" % item,
|
content="%(description)s" % item,
|
||||||
'iframe_src': item['url_video_hd'].replace("http://", "https://"),
|
iframe_src=video_url,
|
||||||
'template': 'videos.html',
|
template="videos.html",
|
||||||
}
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return results
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user