handle scientific timestamp string parsing

This commit is contained in:
Simon 2026-02-06 11:31:51 +07:00
parent 1e06c40a2c
commit 395de16974
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 20 additions and 0 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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(