handle invalid timestamp and upload dates, #1094

This commit is contained in:
Simon 2025-12-13 14:56:12 +07:00
parent cceab5fe2b
commit 2fb58e9e94
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 13 additions and 7 deletions

View File

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

View File

@ -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"]