Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duration parsing for very long videos #661

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ytmusicapi/parsers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def parse_duration(duration):
# duration may be falsy or a single space: ' '
if not duration or not duration.strip():
return duration
mapped_increments = zip([1, 60, 3600], reversed(duration.split(":")))
duration_split = duration.strip().split(":")
for d in duration_split:
if not d.isdigit(): # For e.g: "2,343"
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to return None ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both return and return None are the same in python

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but being explicit is preferred here

https://stackoverflow.com/a/15300671

mapped_increments = zip([1, 60, 3600], reversed(duration_split))
seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments)
return seconds

Expand Down