diff --git a/tests/mixins/test_browsing.py b/tests/mixins/test_browsing.py index 9bdae05..6fc6e32 100644 --- a/tests/mixins/test_browsing.py +++ b/tests/mixins/test_browsing.py @@ -135,6 +135,12 @@ class TestBrowsing: with pytest.raises(Exception, match="Invalid album browseId"): yt.get_album("asdf") + def test_get_album_without_artist(self, yt): + album = yt.get_album("MPREb_n1AxZ9F8rF7") # soundtrack album with no artist info + assert album["artists"] is None + assert album["audioPlaylistId"] is not None + assert len(album["tracks"]) == 11 + def test_get_album_other_versions(self, yt): # Eminem - Curtain Call: The Hits (Explicit Variant) album = yt.get_album("MPREb_LQCAymzbaKJ") diff --git a/ytmusicapi/parsers/albums.py b/ytmusicapi/parsers/albums.py index 5679ab2..6ffb56e 100644 --- a/ytmusicapi/parsers/albums.py +++ b/ytmusicapi/parsers/albums.py @@ -52,7 +52,7 @@ def parse_album_header_2024(response: JsonDict) -> JsonDict: album["description"] = nav(header, ["description", *DESCRIPTION_SHELF, *DESCRIPTION], True) album_info = parse_song_runs(header["subtitle"]["runs"][2:]) - album_info["artists"] = [parse_base_header(header)["author"]] + album_info["artists"] = [author] if (author := parse_base_header(header)["author"]) else None album.update(album_info) if len(header["secondSubtitle"]["runs"]) > 1: diff --git a/ytmusicapi/parsers/podcasts.py b/ytmusicapi/parsers/podcasts.py index 5858b09..6eba3e0 100644 --- a/ytmusicapi/parsers/podcasts.py +++ b/ytmusicapi/parsers/podcasts.py @@ -67,11 +67,14 @@ class Description(list[DescriptionElement]): def parse_base_header(header: JsonDict) -> JsonDict: """parse common left hand side (header) items of an episode or podcast page""" strapline = nav(header, ["straplineTextOne"]) + + author = { + "name": nav(strapline, [*RUN_TEXT], True), + "id": nav(strapline, ["runs", 0, *NAVIGATION_BROWSE_ID], True), + } + return { - "author": { - "name": nav(strapline, [*RUN_TEXT]), - "id": nav(strapline, ["runs", 0, *NAVIGATION_BROWSE_ID], True), - }, + "author": author if author["name"] else None, "title": nav(header, TITLE_TEXT), "thumbnails": nav(header, THUMBNAILS), }