From 63be6afcfee9da61ba2eebf2c9381927889f7a6e Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 17 Oct 2021 09:40:46 +0700 Subject: [PATCH] allow duration_sec extraction to fail cleanly for add to queue --- tubearchivist/home/src/download.py | 2 ++ tubearchivist/home/src/helper.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 66cd19e..8c114a5 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -129,6 +129,8 @@ class PendingList: # parse response seconds = vid["duration"] duration_str = DurationConverter.get_str(seconds) + if duration_str == "NA": + print(f"skip extracting duration for: {youtube_id}") upload_date = vid["upload_date"] upload_dt = datetime.strptime(upload_date, "%Y%m%d") published = upload_dt.strftime("%Y-%m-%d") diff --git a/tubearchivist/home/src/helper.py b/tubearchivist/home/src/helper.py index 1a67340..d9d34d5 100644 --- a/tubearchivist/home/src/helper.py +++ b/tubearchivist/home/src/helper.py @@ -237,6 +237,10 @@ class DurationConverter: @staticmethod def get_str(duration_sec): """takes duration in sec and returns clean string""" + if not duration_sec: + # failed to extract + return "NA" + hours = duration_sec // 3600 minutes = (duration_sec - (hours * 3600)) // 60 secs = duration_sec - (hours * 3600) - (minutes * 60)