From 2fb58e9e94ef7d57c92ef3a68e67e9cfc90d5ef5 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 13 Dec 2025 14:56:12 +0700 Subject: [PATCH] handle invalid timestamp and upload dates, #1094 --- backend/download/src/queue.py | 18 ++++++++++++------ backend/video/src/index.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/download/src/queue.py b/backend/download/src/queue.py index e03a8871..52ae114c 100644 --- a/backend/download/src/queue.py +++ b/backend/download/src/queue.py @@ -393,18 +393,24 @@ class PendingList(PendingIndex): return None @staticmethod - def _extract_published(video_data) -> str | int | None: + def _extract_published(video_data) -> int | None: """build published date or timestamp""" timestamp = video_data.get("timestamp") - if timestamp: + if timestamp and isinstance(timestamp, int): return timestamp upload_date = video_data.get("upload_date") if upload_date: - upload_date_time = datetime.strptime(upload_date, "%Y%m%d") - return upload_date_time.replace( - tzinfo=ZoneInfo(EnvironmentSettings.TZ) - ).timestamp() + try: + upload_date_time = datetime.strptime(upload_date, "%Y%m%d") + except ValueError: + youtube_id = video_data["id"] + print(f"{youtube_id}: published date extraction failed.") + return None + + tz = ZoneInfo(EnvironmentSettings.TZ) + timestamp = int(upload_date_time.replace(tzinfo=tz).timestamp()) + return timestamp return None diff --git a/backend/video/src/index.py b/backend/video/src/index.py index 0dbb2aae..1d5cf839 100644 --- a/backend/video/src/index.py +++ b/backend/video/src/index.py @@ -220,7 +220,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): def _build_published(self): """build published date or timestamp""" timestamp = self.youtube_meta.get("timestamp") - if timestamp: + if timestamp and isinstance(timestamp, int): return timestamp upload_date = self.youtube_meta["upload_date"]