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

Conversation

abhishekmj303
Copy link

Fixes #660

@sigma67
Copy link
Owner

sigma67 commented Oct 10, 2024

So I'm not sure what the correct behavior is here...

Afaik from sources on the internet, YT's max video duration is 12h.

Since the video you linked is not playable either I would assume that it's simply an invalid entry. Not sure we'd even want to parse the duration in that case.

Granted we should not crash but return None as duration instead.

@sigma67
Copy link
Owner

sigma67 commented Oct 10, 2024

The fix you provided here is also locale dependent and would break for German localization

duration: 13.165:23:44

@abhishekmj303
Copy link
Author

The fix you provided here is also locale dependent and would break for German localization

duration: 13.165:23:44

Good point, I did not think of this. If the locale is known then we can use the function locale.atoi. Reference

But if this is not possible then this the way:

Granted we should not crash but return None as duration instead.

@sigma67
Copy link
Owner

sigma67 commented Oct 10, 2024

Are there any videos with 1k+ hours that are actually playable? If yes I'd have a go with atoi. If no, don't bother and just return None

@sigma67
Copy link
Owner

sigma67 commented Oct 10, 2024

fyi there is already a to_int function that uses atoi

def to_int(string):

@abhishekmj303
Copy link
Author

Are there any videos with 1k+ hours that are actually playable?

I think they are not playable. The current longest playable video on youtube I was able to find is about 300hrs (https://youtu.be/kj4LxVhx2-A). So just returning None should be fine.

@sigma67
Copy link
Owner

sigma67 commented Oct 11, 2024

@abhishekmj303 ok yes, let's do that.

I guess you could check if the result of duration.split(":") contains any non-digit characters and then fall back to None

Copy link

codecov bot commented Oct 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.09%. Comparing base (2b5d19a) to head (faf1dc5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
+ Coverage   94.99%   95.09%   +0.09%     
==========================================
  Files          38       38              
  Lines        2278     2282       +4     
==========================================
+ Hits         2164     2170       +6     
+ Misses        114      112       -2     
Flag Coverage Δ
unittests 95.09% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abhishekmj303
Copy link
Author

@sigma67 Not sure what tests and where I need to add them. Can you help me here?

Copy link
Owner

@sigma67 sigma67 left a comment

Choose a reason for hiding this comment

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

Please add a test with a playlist that contains an applicable song with >1k hours

see https://github.com/sigma67/ytmusicapi/blob/main/tests/README.rst

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

parse_duration fails for very long videos
2 participants