From 395de16974a58486c59ab777c2ab453b1c9d33cd Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 6 Feb 2026 11:31:51 +0700 Subject: [PATCH] handle scientific timestamp string parsing --- backend/download/src/queue.py | 7 +++++++ backend/download/tests/test_src/test_pending_list.py | 6 ++++++ backend/video/src/index.py | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/backend/download/src/queue.py b/backend/download/src/queue.py index cb259f82..81ada735 100644 --- a/backend/download/src/queue.py +++ b/backend/download/src/queue.py @@ -409,6 +409,13 @@ class PendingList(PendingIndex): if timestamp and isinstance(timestamp, float): return int(timestamp) + if timestamp and isinstance(timestamp, str): + try: + # scientific string + return int(float(timestamp)) + except (TypeError, ValueError): + pass + upload_date = video_data.get("upload_date") if upload_date: try: diff --git a/backend/download/tests/test_src/test_pending_list.py b/backend/download/tests/test_src/test_pending_list.py index 244fa4f4..4c821959 100644 --- a/backend/download/tests/test_src/test_pending_list.py +++ b/backend/download/tests/test_src/test_pending_list.py @@ -11,6 +11,12 @@ def test_returns_scientific_timestamp_if_present(): assert result == 1513573200 +def test_returns_scientific_timestamp_string_if_present(): + video_data = {"timestamp": "1.5135732e9"} + result = PendingList._extract_published(video_data) + assert result == 1513573200 + + def test_returns_timestamp_if_present(): video_data = {"timestamp": 1508457600} result = PendingList._extract_published(video_data) diff --git a/backend/video/src/index.py b/backend/video/src/index.py index fff28c60..62ac7f74 100644 --- a/backend/video/src/index.py +++ b/backend/video/src/index.py @@ -225,6 +225,13 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): if timestamp and isinstance(timestamp, float): return int(timestamp) + if timestamp and isinstance(timestamp, str): + try: + # scientific string + return int(float(timestamp)) + except (TypeError, ValueError): + pass + upload_date = self.youtube_meta["upload_date"] if not upload_date: raise ValueError(