Skip to content

Commit

Permalink
get_album: return new "views" key for each track
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Dec 31, 2023
1 parent 1971121 commit f3e7471
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions ytmusicapi/parsers/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f3e7471

Please sign in to comment.