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

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

abhishekmj303
Copy link
Contributor

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
Contributor 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
Contributor 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).
Report is 1 commits behind head on main.

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

ytmusicapi/parsers/_utils.py Outdated Show resolved Hide resolved
@sigma67
Copy link
Owner

sigma67 commented Oct 15, 2024

@abhishekmj303 Thanks! Everything looks good now

@sigma67 sigma67 merged commit 8f479b1 into sigma67:main Oct 15, 2024
5 checks passed
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