sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.59k stars 182 forks source link

get_album() fails if the album artist is 'Various Artists' #613

Open RazorTwig opened 4 days ago

RazorTwig commented 4 days ago

This seems to occur only when I attempt to run get_album on an album which shows 'Various Artists' as the album artist. 'Various Artists' doesn't come with a 'browseId' field (or even a 'navigationEndpoint' field) to parse, so the attempt to get the browseId throws the error below. if I use search() to find the album, it correctly returns name='Various Artists', id=None so it is parsing it correctly elsewhere.

I can do this with other albums which are 'Various Artists', but the one that showed up first is 'Bass Dreams, Vol. 3', album id 'MPREb_VpY0Pu4Fle2'. Just run get_album with any album id for any 'Various Artists' album and it'll fail.

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\navigation.py", line 106, in nav
    root = root[k]
           ~~~~^^^
KeyError: 'navigationEndpoint'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user\Documents\Personal\MusicTools\git-MusicTools\utils\ytmusic.py", line 53, in get_playlist_tracks
    tracks = [self.get_virtual_track(track) for track in raw_tracks]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\Documents\Personal\MusicTools\git-MusicTools\utils\ytmusic.py", line 73, in get_virtual_track
    yt_album = self.yt.get_album(album_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\mixins\browsing.py", line 521, in get_album
    album = parse_album_header_2024(response)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\parsers\albums.py", line 54, in parse_album_header_2024
    album_info["artists"] = [parse_base_header(header)["author"]]
                             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\parsers\podcasts.py", line 67, in parse_base_header
    "id": nav(strapline, ["runs", 0, *NAVIGATION_BROWSE_ID]),
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\navigation.py", line 110, in nav
    raise type(e)(f"Unable to find '{k}' using path {items!r} on {root!r}, exception: {e}")
KeyError: "Unable to find 'navigationEndpoint' using path ['runs', 0, 'navigationEndpoint', 'browseEndpoint', 'browseId'] on {'text': 'Various Artists'}, exception: 'navigationEndpoint'"

header that it's trying to parse:

{
    "thumbnail":
    {...},
    "buttons":
    [...],
    "title":
    {...},
    "subtitle":
    {...},
    "trackingParams": "CAQQneEIGAAiEwi1tIyukIaHAxWemeQGHRv9BC8=",
    "straplineTextOne":
    {
        "runs":
        [
            {
                "text": "Various Artists"
            }
        ]
    },
    "subtitleBadge":
    [...],
    "secondSubtitle":
    {...}
}

edit: Not simply 'Various Artists', but any time the artist doesn't have a profile to link back to. For instance, the EP 'Different Ways' by DJ Disrespect does not link back to any artist profile so there is no browseId to link back to the artist and it fails for that as well. (album id 'MPREb_KD7lv9ifzCH')

sigma67 commented 1 day ago

PR welcome