From 7d7d4b27ef763159b99881a2bad4b92a76f3eea9 Mon Sep 17 00:00:00 2001 From: Abhishek M J <85760664+abhishekmj303@users.noreply.github.com> Date: Thu, 10 Oct 2024 06:26:19 +0000 Subject: [PATCH 1/4] Fix duration parsing for very long videos sigma67#660 --- ytmusicapi/parsers/_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ytmusicapi/parsers/_utils.py b/ytmusicapi/parsers/_utils.py index 1131dd54..05eded17 100644 --- a/ytmusicapi/parsers/_utils.py +++ b/ytmusicapi/parsers/_utils.py @@ -67,6 +67,7 @@ def parse_duration(duration): # duration may be falsy or a single space: ' ' if not duration or not duration.strip(): return duration + duration = duration.replace(",", "") # may be more than thousand hours mapped_increments = zip([1, 60, 3600], reversed(duration.split(":"))) seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments) return seconds From d3d822b820a295bbeec7cb047408297578c07840 Mon Sep 17 00:00:00 2001 From: Abhishek M J <85760664+abhishekmj303@users.noreply.github.com> Date: Sun, 13 Oct 2024 04:56:07 +0000 Subject: [PATCH 2/4] parse duration only when digits are present --- ytmusicapi/parsers/_utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ytmusicapi/parsers/_utils.py b/ytmusicapi/parsers/_utils.py index 05eded17..10a61f5c 100644 --- a/ytmusicapi/parsers/_utils.py +++ b/ytmusicapi/parsers/_utils.py @@ -67,8 +67,11 @@ def parse_duration(duration): # duration may be falsy or a single space: ' ' if not duration or not duration.strip(): return duration - duration = duration.replace(",", "") # may be more than thousand hours - 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 + mapped_increments = zip([1, 60, 3600], reversed(duration_split)) seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments) return seconds From 3a8e6b317c3f51be1ea47a97c28404b4d1718180 Mon Sep 17 00:00:00 2001 From: Abhishek M J <85760664+abhishekmj303@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:56:01 +0000 Subject: [PATCH 3/4] explicit return None --- ytmusicapi/parsers/_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ytmusicapi/parsers/_utils.py b/ytmusicapi/parsers/_utils.py index 10a61f5c..4df215b5 100644 --- a/ytmusicapi/parsers/_utils.py +++ b/ytmusicapi/parsers/_utils.py @@ -69,8 +69,8 @@ def parse_duration(duration): return duration duration_split = duration.strip().split(":") for d in duration_split: - if not d.isdigit(): # For e.g: "2,343" - return + 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) return seconds From faf1dc5af087c1b0d51a958954ba611f87abafc0 Mon Sep 17 00:00:00 2001 From: Abhishek M J <85760664+abhishekmj303@users.noreply.github.com> Date: Mon, 14 Oct 2024 09:56:09 +0000 Subject: [PATCH 4/4] Add test for track dur > 1k hrs --- tests/mixins/test_playlists.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mixins/test_playlists.py b/tests/mixins/test_playlists.py index b7ed2dc2..20dc627c 100644 --- a/tests/mixins/test_playlists.py +++ b/tests/mixins/test_playlists.py @@ -49,6 +49,7 @@ def test_get_playlist_2024(self, yt, test_file, owned): ("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", 200, 0), # no related tracks ("PL6bPxvf5dW5clc3y9wAoslzqUrmkZ5c-u", 1000, 10), # very large ("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):