diff options
| author | Zhijie He <hezhijie0327@hotmail.com> | 2025-03-02 20:16:24 +0800 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2025-03-02 13:31:31 +0100 |
| commit | b0beb307ca156e4d87370f2072cfd459354a640f (patch) | |
| tree | 94d5e6c7aba37f3fbb5a4f59933368a092b46dc1 | |
| parent | 76f52b5b45a08776ad09e9b670a80635ab303c96 (diff) | |
[chore] add `timediff` field for sogou_videos
Co-authored-by: Bnyro <bnyro@tutanota.com>
| -rw-r--r-- | searx/engines/sogou_videos.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/searx/engines/sogou_videos.py b/searx/engines/sogou_videos.py index 1149996c9..91c503e34 100644 --- a/searx/engines/sogou_videos.py +++ b/searx/engines/sogou_videos.py @@ -2,7 +2,7 @@ """Sogou-Videos: A search engine for retrieving videos from Sogou.""" from urllib.parse import urlencode -from datetime import datetime +from datetime import datetime, timedelta from searx.exceptions import SearxEngineAPIException @@ -53,16 +53,24 @@ def response(resp): published_date = None if entry.get("date") and entry.get("duration"): try: - date_time_str = f"{entry['date']} {entry['duration']}" - published_date = datetime.strptime(date_time_str, "%Y-%m-%d %H:%M") + published_date = datetime.strptime(entry['date'], "%Y-%m-%d") except (ValueError, TypeError): 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( { 'url': video_url, 'title': entry["titleEsc"], - 'content': f"{entry['site']} | {entry['duration']}", + 'content': entry['site'], + 'length': length, 'template': 'videos.html', 'publishedDate': published_date, 'thumbnail': entry["picurl"], |