From ab2aa28992b98e64789a9ef8eaef54b20ec8bab3 Mon Sep 17 00:00:00 2001 From: Adwait Thattey Date: Thu, 4 Jul 2024 01:53:03 +0530 Subject: [PATCH] fix sum_total_duration failing if duration_seconds is not an int (#598) * fix sum_total_duration failing if duration_seconds is not an int Signed-off-by: Adwait Thattey * format --------- Signed-off-by: Adwait Thattey Co-authored-by: sigma67 --- ytmusicapi/helpers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ytmusicapi/helpers.py b/ytmusicapi/helpers.py index 40eec562..65d39fab 100644 --- a/ytmusicapi/helpers.py +++ b/ytmusicapi/helpers.py @@ -71,4 +71,11 @@ def to_int(string): def sum_total_duration(item): if "tracks" not in item: return 0 - return sum([track["duration_seconds"] if "duration_seconds" in track else 0 for track in item["tracks"]]) + return sum( + [ + track["duration_seconds"] + if ("duration_seconds" in track and isinstance(track["duration_seconds"], int)) + else 0 + for track in item["tracks"] + ] + )