From c3e65f5026245778fd873260908dcf441b975ee5 Mon Sep 17 00:00:00 2001 From: Marvin Schenkel Date: Sun, 25 Jun 2023 20:28:26 +0200 Subject: [PATCH] Fix 'secondSubtitle' KeyError for some playlists (#399) * Fix 'secondSubtitle' KeyError for some playlists * Feedback. --- ytmusicapi/mixins/playlists.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 70f0dfef..1dfebd64 100644 --- a/ytmusicapi/mixins/playlists.py +++ b/ytmusicapi/mixins/playlists.py @@ -132,14 +132,16 @@ def get_playlist(self, if run_count == 5: playlist['year'] = nav(header, SUBTITLE3) - second_subtitle_runs = header['secondSubtitle']['runs'] - - has_views = (len(second_subtitle_runs) > 3) * 2 - playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text']) - has_duration = (len(second_subtitle_runs) > 1) * 2 - playlist['duration'] = None if not has_duration else second_subtitle_runs[has_views + has_duration]['text'] - song_count = second_subtitle_runs[has_views + 0]['text'].split(" ") - song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 + playlist['views'] = None + playlist['duration'] = None + if 'runs' in header['secondSubtitle']: + second_subtitle_runs = header['secondSubtitle']['runs'] + has_views = (len(second_subtitle_runs) > 3) * 2 + playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text']) + has_duration = (len(second_subtitle_runs) > 1) * 2 + playlist['duration'] = None if not has_duration else second_subtitle_runs[has_views + has_duration]['text'] + + song_count = len(results['contents']) playlist['trackCount'] = song_count request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams)