fix get_album other_versions attribute

This commit is contained in:
sigma67 2024-07-03 21:27:24 +02:00
commit f4f9e7cd12
No known key found for this signature in database

View file

@ -7,7 +7,7 @@ from ytmusicapi.continuations import (
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 @@ class BrowsingMixin(MixinProtocol):
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"]