prevent KeyError when parsing missing author data (#788)
`get_album` no longer errors on albums with no artist metadata, instead returning `"artist": None` Co-authored-by: sigma67 <sigma67.github@gmail.com>
This commit is contained in:
parent
ccd281ce29
commit
39a480eace
3 changed files with 14 additions and 5 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue