Fix duration parsing for very long videos (#661)
* Fix duration parsing for very long videos sigma67#660 * parse duration only when digits are present * explicit return None * Add test for track dur > 1k hrs
This commit is contained in:
parent
2b5d19abb1
commit
8f479b1b5b
2 changed files with 6 additions and 1 deletions
|
|
@ -49,6 +49,7 @@ class TestPlaylists:
|
||||||
("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", 200, 0), # no related tracks
|
("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", 200, 0), # no related tracks
|
||||||
("PL6bPxvf5dW5clc3y9wAoslzqUrmkZ5c-u", 1000, 10), # very large
|
("PL6bPxvf5dW5clc3y9wAoslzqUrmkZ5c-u", 1000, 10), # very large
|
||||||
("PLZ6Ih9wLHQ2Hm2d3Cb0iV48Z2hQjGRyNz", 300, 10), # runs in subtitle, not title
|
("PLZ6Ih9wLHQ2Hm2d3Cb0iV48Z2hQjGRyNz", 300, 10), # runs in subtitle, not title
|
||||||
|
("PL5ZNf-B8WWSZFIvpJWRjgt7iRqWT7_KF1", 10, 10), # track duration > 1k hours
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_playlist_foreign(self, yt_oauth, playlist_id, tracks_len, related_len):
|
def test_get_playlist_foreign(self, yt_oauth, playlist_id, tracks_len, related_len):
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,11 @@ def parse_duration(duration):
|
||||||
# duration may be falsy or a single space: ' '
|
# duration may be falsy or a single space: ' '
|
||||||
if not duration or not duration.strip():
|
if not duration or not duration.strip():
|
||||||
return duration
|
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 None
|
||||||
|
mapped_increments = zip([1, 60, 3600], reversed(duration_split))
|
||||||
seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments)
|
seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments)
|
||||||
return seconds
|
return seconds
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue