From 94f15138229cd6bca80a8968eae3ec14e1e2baee Mon Sep 17 00:00:00 2001 From: sigma67 Date: Sun, 2 Jul 2023 22:15:38 +0200 Subject: [PATCH] fix empty liked songs crash caused by #399 --- tests/test.py | 7 +++++-- ytmusicapi/mixins/playlists.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test.py b/tests/test.py index 6a5929e..0180d2c 100644 --- a/tests/test.py +++ b/tests/test.py @@ -388,20 +388,23 @@ def test_subscribe_artists(self): # PLAYLISTS ############### - def test_get_foreign_playlist(self): + def test_get_playlist_foreign(self): self.assertRaises(Exception, self.yt.get_playlist, "PLABC") playlist = self.yt.get_playlist(sample_playlist, limit=300, suggestions_limit=7) self.assertGreater(len(playlist['duration']), 5) self.assertGreater(len(playlist["tracks"]), 200) self.assertNotIn("suggestions", playlist) + self.yt.get_playlist("RDATgXd-") + self.assertGreaterEqual(len(playlist["tracks"]), 100) + playlist = self.yt_oauth.get_playlist("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", limit=None, related=True) self.assertGreater(len(playlist["tracks"]), 200) self.assertEqual(len(playlist["related"]), 0) - def test_get_owned_playlist(self): + def test_get_playlist_owned(self): playlist = self.yt_brand.get_playlist(config["playlists"]["own"], related=True, suggestions_limit=21) diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 1dfebd6..1e6f882 100644 --- a/ytmusicapi/mixins/playlists.py +++ b/ytmusicapi/mixins/playlists.py @@ -140,8 +140,11 @@ def get_playlist(self, 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']) + song_count = second_subtitle_runs[has_views + 0]['text'].split(" ") + song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 + else: + song_count = len(results['contents']) + playlist['trackCount'] = song_count request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams)