From f4f9e7cd1243dfe486946984e883429019e82953 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Wed, 3 Jul 2024 21:27:24 +0200 Subject: [PATCH] fix get_album other_versions attribute --- ytmusicapi/mixins/browsing.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index f447ce6..1ae88d2 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -7,7 +7,7 @@ get_reloadable_continuation_params, ) from ytmusicapi.helpers import YTM_DOMAIN, sum_total_duration -from ytmusicapi.parsers.albums import parse_album_header, parse_album_header_2024 +from ytmusicapi.parsers.albums import parse_album_header_2024 from ytmusicapi.parsers.browsing import parse_album, parse_content_list, parse_mixed_content, parse_playlist from ytmusicapi.parsers.library import parse_albums from ytmusicapi.parsers.playlists import parse_playlist_items @@ -515,19 +515,16 @@ def get_album(self, browseId: str) -> Dict: body = {"browseId": browseId} endpoint = "browse" response = self._send_request(endpoint, body) - if "header" in response: - album = parse_album_header(response) - else: - album = parse_album_header_2024(response) - results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF, True) or nav( - # fallback for 2024 format - response, - [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION_LIST_ITEM, *MUSIC_SHELF], - ) + album = parse_album_header_2024(response) + + results = nav(response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION_LIST_ITEM, *MUSIC_SHELF]) album["tracks"] = parse_playlist_items(results["contents"], is_album=True) - results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + CAROUSEL, True) - if results is not None: - album["other_versions"] = parse_content_list(results["contents"], parse_album) + + other_versions = nav( + response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION_LIST, 1, *CAROUSEL] + ) + if other_versions is not None: + album["other_versions"] = parse_content_list(other_versions["contents"], parse_album) album["duration_seconds"] = sum_total_duration(album) for i, track in enumerate(album["tracks"]): album["tracks"][i]["album"] = album["title"]