mirror of
https://github.com/searxng/searxng.git
synced 2026-09-25 15:46:06 +00:00
[mod] migration of some engine results to the video class (#6743)
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
committed by
Markus Heiser
parent
ce48993997
commit
2e41cf7407
@@ -4,14 +4,19 @@
|
||||
.. _Odysee: https://github.com/OdyseeTeam/odysee-frontend
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
import typing as t
|
||||
from datetime import datetime, timedelta
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import babel
|
||||
|
||||
from searx.enginelib.traits import EngineTraits
|
||||
from searx.locales import language_tag
|
||||
from searx.utils import format_duration
|
||||
from searx.result_types import EngineResults
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from searx.extended_types import SXNG_Response
|
||||
from searx.search.processors import OnlineParams
|
||||
|
||||
# Engine metadata
|
||||
about = {
|
||||
@@ -34,7 +39,7 @@ categories = ["videos"]
|
||||
base_url = "https://lighthouse.odysee.tv/search"
|
||||
|
||||
|
||||
def request(query, params):
|
||||
def request(query: str, params: "OnlineParams"):
|
||||
time_range_dict = {
|
||||
"day": "today",
|
||||
"week": "thisweek",
|
||||
@@ -59,22 +64,17 @@ def request(query, params):
|
||||
query_params["time_filter"] = time_range_dict[params["time_range"]]
|
||||
|
||||
params["url"] = f"{base_url}?{urlencode(query_params)}"
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
def response(resp: "SXNG_Response") -> EngineResults:
|
||||
res = EngineResults()
|
||||
data = resp.json()
|
||||
results = []
|
||||
|
||||
for item in data:
|
||||
name = item["name"]
|
||||
claim_id = item["claimId"]
|
||||
title = item["title"]
|
||||
thumbnail_url = item["thumbnail_url"]
|
||||
description = item["description"] or ""
|
||||
channel = item["channel"]
|
||||
release_time = item["release_time"]
|
||||
duration = item["duration"]
|
||||
|
||||
release_date = datetime.fromisoformat(release_time.split("T")[0])
|
||||
formatted_date = datetime.fromtimestamp(release_date.timestamp())
|
||||
@@ -82,23 +82,21 @@ def response(resp):
|
||||
url = f"https://odysee.com/{name}:{claim_id}"
|
||||
iframe_url = f"https://odysee.com/$/embed/{name}:{claim_id}"
|
||||
odysee_thumbnail = f"https://thumbnails.odycdn.com/optimize/s:390:0/quality:85/plain/{thumbnail_url}"
|
||||
formatted_duration = format_duration(duration)
|
||||
|
||||
results.append(
|
||||
{
|
||||
"title": title,
|
||||
"url": url,
|
||||
"content": description,
|
||||
"author": channel,
|
||||
"publishedDate": formatted_date,
|
||||
"length": formatted_duration,
|
||||
"thumbnail": odysee_thumbnail,
|
||||
"iframe_src": iframe_url,
|
||||
"template": "videos.html",
|
||||
}
|
||||
res.add(
|
||||
res.types.Video(
|
||||
title=item["title"],
|
||||
url=url,
|
||||
content=item["description"] or "",
|
||||
author=item["channel"],
|
||||
publishedDate=formatted_date,
|
||||
length=timedelta(seconds=item["duration"]),
|
||||
thumbnail=odysee_thumbnail,
|
||||
iframe_src=iframe_url,
|
||||
)
|
||||
)
|
||||
|
||||
return results
|
||||
return res
|
||||
|
||||
|
||||
def fetch_traits(engine_traits: EngineTraits):
|
||||
|
||||
Reference in New Issue
Block a user