From 20755c3ed15202117a528c8f8ef2424e8d09e358 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Tue, 17 Dec 2024 18:21:59 +0100 Subject: [PATCH] fix #675 --- tests/mixins/test_browsing.py | 9 +++++++++ ytmusicapi/parsers/albums.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/mixins/test_browsing.py b/tests/mixins/test_browsing.py index 0c530a14..83c9909c 100644 --- a/tests/mixins/test_browsing.py +++ b/tests/mixins/test_browsing.py @@ -110,17 +110,26 @@ def test_get_album(self, yt, yt_auth, sample_album): assert album["tracks"][0]["isExplicit"] assert all(item["views"] is not None for item in album["tracks"]) assert all(item["album"] is not None for item in album["tracks"]) + assert album["likeStatus"] is not None + assert album["audioPlaylistId"] is not None assert album["tracks"][0]["trackNumber"] == 1 assert "feedbackTokens" in album["tracks"][0] album = yt.get_album("MPREb_BQZvl3BFGay") + assert album["audioPlaylistId"] is not None assert len(album["tracks"]) == 7 assert len(album["tracks"][0]["artists"]) == 1 album = yt.get_album("MPREb_rqH94Zr3NN0") + assert album["likeStatus"] is not None + assert album["audioPlaylistId"] is not None assert len(album["tracks"][0]["artists"]) == 2 album = yt.get_album("MPREb_TPH4WqN5pUo") # album with tracks completely removed/missing + assert album["likeStatus"] is not None + assert album["audioPlaylistId"] is not None assert album["tracks"][0]["trackNumber"] == 3 assert album["tracks"][13]["trackNumber"] == 18 album = yt.get_album("MPREb_YuigcYm2erf") # album with track (#8) disabled/greyed out + assert album["likeStatus"] is not None + assert album["audioPlaylistId"] is not None assert album["tracks"][7]["trackNumber"] is None def test_get_album_errors(self, yt): diff --git a/ytmusicapi/parsers/albums.py b/ytmusicapi/parsers/albums.py index 0d9ba9af..b2ab35f6 100644 --- a/ytmusicapi/parsers/albums.py +++ b/ytmusicapi/parsers/albums.py @@ -63,9 +63,16 @@ def parse_album_header_2024(response): # add to library/uploaded buttons = header["buttons"] album["audioPlaylistId"] = nav( - buttons, [1, "musicPlayButtonRenderer", "playNavigationEndpoint", *WATCH_PLAYLIST_ID], True + find_object_by_key(buttons, "musicPlayButtonRenderer"), + ["musicPlayButtonRenderer", "playNavigationEndpoint", *WATCH_PLAYLIST_ID], + True, ) - service = nav(buttons, [0, "toggleButtonRenderer", "defaultServiceEndpoint"], True) + service = nav( + find_object_by_key(buttons, "toggleButtonRenderer"), + ["toggleButtonRenderer", "defaultServiceEndpoint"], + True, + ) + album["likeStatus"] = "INDIFFERENT" if service: album["likeStatus"] = parse_like_status(service)