diff --git a/tests/test.py b/tests/test.py index e9a7f4b1..b223ae57 100644 --- a/tests/test.py +++ b/tests/test.py @@ -266,6 +266,8 @@ def test_get_album(self): results = self.yt_auth.get_album(sample_album) self.assertGreaterEqual(len(results), 9) self.assertTrue(results["tracks"][0]["isExplicit"]) + self.assertTrue(all(item["views"] is not None for item in results["tracks"])) + self.assertTrue(all(item["album"] is not None for item in results["tracks"])) self.assertIn("feedbackTokens", results["tracks"][0]) self.assertGreaterEqual(len(results["other_versions"]), 1) # appears to be regional results = self.yt.get_album("MPREb_BQZvl3BFGay") @@ -483,7 +485,9 @@ def test_subscribe_artists(self): def test_get_playlist_foreign(self): self.assertRaises(Exception, self.yt.get_playlist, "PLABC") - playlist = self.yt.get_playlist("PLk5BdzXBUiUe8Q5I13ZSCD8HbxMqJUUQA", limit=300, suggestions_limit=7) + playlist = self.yt_auth.get_playlist( + "PLk5BdzXBUiUe8Q5I13ZSCD8HbxMqJUUQA", limit=300, suggestions_limit=7 + ) self.assertGreater(len(playlist["duration"]), 5) self.assertGreater(len(playlist["tracks"]), 200) self.assertNotIn("suggestions", playlist) diff --git a/ytmusicapi/parsers/playlists.py b/ytmusicapi/parsers/playlists.py index a626f963..59c5ee2d 100644 --- a/ytmusicapi/parsers/playlists.py +++ b/ytmusicapi/parsers/playlists.py @@ -49,6 +49,12 @@ def parse_playlist_items(results, menu_entries: List[List] = None): album = parse_song_album(data, 2) + views = None + if album and album["id"] is None: + # views currently only present on albums and formatting is localization-dependent -> no parsing + if (views := (get_item_text(data, 2))) is not None: + album = None + duration = None if "fixedColumns" in data: if "simpleText" in get_fixed_column_item(data, 0)["text"]: @@ -85,6 +91,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None): "isAvailable": isAvailable, "isExplicit": isExplicit, "videoType": videoType, + "views": views, } if duration: song["duration"] = duration