allow duration_sec extraction to fail cleanly for add to queue

This commit is contained in:
simon 2021-10-17 09:40:46 +07:00
parent 559a4c9a58
commit 63be6afcfe
2 changed files with 6 additions and 0 deletions

View File

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

View File

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