mirror of
https://github.com/searxng/searxng.git
synced 2026-09-23 06:36:12 +00:00
[mod] c3tv: modernize engine (#6752)
This commit is contained in:
@@ -1,59 +1,63 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""media.ccc.de"""
|
"""media.ccc.de"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
import datetime
|
import datetime
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
from dateutil import parser
|
import dateutil.parser
|
||||||
|
|
||||||
|
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://media.ccc.de',
|
"website": "https://media.ccc.de",
|
||||||
'official_api_documentation': 'https://github.com/voc/voctoweb',
|
"official_api_documentation": "https://github.com/voc/voctoweb",
|
||||||
'use_official_api': True,
|
"use_official_api": True,
|
||||||
'require_api_key': False,
|
"require_api_key": False,
|
||||||
'results': 'JSON',
|
"results": "JSON",
|
||||||
}
|
}
|
||||||
categories = ['videos']
|
categories = ["videos"]
|
||||||
paging = True
|
paging = True
|
||||||
|
|
||||||
api_url = "https://api.media.ccc.de"
|
api_url = "https://api.media.ccc.de"
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query: str, params: "OnlineParams"):
|
||||||
args = {'q': query, 'page': params['pageno']}
|
args = {"q": query, "page": params["pageno"]}
|
||||||
params['url'] = f"{api_url}/public/events/search?{urlencode(args)}"
|
params["url"] = f"{api_url}/public/events/search?{urlencode(args)}"
|
||||||
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
def response(resp: "SXNG_Response") -> EngineResults:
|
||||||
results = []
|
res = EngineResults()
|
||||||
|
|
||||||
for item in resp.json()['events']:
|
for item in resp.json()["events"]:
|
||||||
publishedDate = None
|
publishedDate = None
|
||||||
if item.get('date'):
|
if item.get("date"):
|
||||||
publishedDate = parser.parse(item['date'])
|
publishedDate = dateutil.parser.parse(item["date"])
|
||||||
|
|
||||||
iframe_src = None
|
iframe_src = None
|
||||||
for rec in item['recordings']:
|
for rec in item["recordings"]:
|
||||||
if rec['mime_type'].startswith('video'):
|
if rec["mime_type"].startswith("video"):
|
||||||
if not iframe_src:
|
if not iframe_src:
|
||||||
iframe_src = rec['recording_url']
|
iframe_src = rec["recording_url"]
|
||||||
elif rec['mime_type'] == 'video/mp4':
|
elif rec["mime_type"] == "video/mp4":
|
||||||
# prefer mp4 (minimal data rates)
|
# prefer mp4 (minimal data rates)
|
||||||
iframe_src = rec['recording_url']
|
iframe_src = rec["recording_url"]
|
||||||
|
|
||||||
results.append(
|
res.add(
|
||||||
{
|
res.types.Video(
|
||||||
'template': 'videos.html',
|
url=item["frontend_link"],
|
||||||
'url': item['frontend_link'],
|
title=item["title"],
|
||||||
'title': item['title'],
|
content=item["description"],
|
||||||
'content': item['description'],
|
thumbnail=item["thumb_url"],
|
||||||
'thumbnail': item['thumb_url'],
|
publishedDate=publishedDate,
|
||||||
'publishedDate': publishedDate,
|
length=datetime.timedelta(seconds=item["length"]),
|
||||||
'length': datetime.timedelta(seconds=item['length']),
|
iframe_src=iframe_src or "",
|
||||||
'iframe_src': iframe_src,
|
)
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return results
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user