[chore] add timediff field for sogou_videos

Co-authored-by: Bnyro <bnyro@tutanota.com>
This commit is contained in:
Zhijie He 2025-03-02 20:16:24 +08:00 committed by Bnyro
parent b87c127139
commit 75e77ad44e
No known key found for this signature in database

View File

@ -2,7 +2,7 @@
"""Sogou-Videos: A search engine for retrieving videos from Sogou.""" """Sogou-Videos: A search engine for retrieving videos from Sogou."""
from urllib.parse import urlencode from urllib.parse import urlencode
from datetime import datetime from datetime import datetime, timedelta
from searx.exceptions import SearxEngineAPIException from searx.exceptions import SearxEngineAPIException
@ -53,16 +53,24 @@ def response(resp):
published_date = None published_date = None
if entry.get("date") and entry.get("duration"): if entry.get("date") and entry.get("duration"):
try: try:
date_time_str = f"{entry['date']} {entry['duration']}" published_date = datetime.strptime(entry['date'], "%Y-%m-%d")
published_date = datetime.strptime(date_time_str, "%Y-%m-%d %H:%M")
except (ValueError, TypeError): except (ValueError, TypeError):
published_date = None published_date = None
length = None
if entry.get("date") and entry.get("duration"):
try:
timediff = datetime.strptime(entry['duration'], "%M:%S")
length = timedelta(minutes=timediff.minute, seconds=timediff.second)
except (ValueError, TypeError):
length = None
results.append( results.append(
{ {
'url': video_url, 'url': video_url,
'title': entry["titleEsc"], 'title': entry["titleEsc"],
'content': f"{entry['site']} | {entry['duration']}", 'content': entry['site'],
'length': length,
'template': 'videos.html', 'template': 'videos.html',
'publishedDate': published_date, 'publishedDate': published_date,
'thumbnail': entry["picurl"], 'thumbnail': entry["picurl"],