Skip to content

Commit

Permalink
fix empty liked songs crash caused by #399
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Jul 2, 2023
1 parent e26335e commit 94f1513
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions ytmusicapi/mixins/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94f1513

Please sign in to comment.