[GH-ISSUE #481] get_playlist(playlist_id) throws an error at line 112 due to structural page changes #358

Closed
opened 2026-02-27 23:00:22 +03:00 by kerem · 2 comments
Owner

Originally created by @marcuma on GitHub (Dec 1, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/481

Describe the bug
When attempting to get the songs from a playlist, a Key Error is thrown when attempting to get the playlistId from the nav result.

Traceback (most recent call last):
  File "/Users/marcuma/Documents/VSCode Workspace/ytapitest/ytapitest.py", line 28, in <module>
    songs = ytmusic.get_playlist(playlist_id, 1)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/ytmusicapi/mixins/playlists.py", line 112, in get_playlist
    playlist = {'id': results['playlistId']}
                      ~~~~~~~^^^^^^^^^^^^^^
KeyError: 'playlistId'

In the reference docs, under get_artist it says to call get_playlist with the browseId, but uder get_playlist and the function header it says to use playlistId, so I tried it with both. b browseId returns a 404 and playlistId throws the above error.

I could be doing something wrong, but from what I can tell, it looks like the data structure being returned from nav isn't as expected and the key can't be located.

Here is the client code that produced the error (Note that the channel ID is hard coded).

from ytmusicapi import YTMusic
import json

ytmusic = YTMusic()

artists = ytmusic.search("Red", "artists")

for artist in artists:
    print(artist)
    print("\r\r")


artist = ytmusic.get_artist("UCxZlJwRYVVaZSqRS4RArrhw")

params = artist["albums"]["params"]
albums = ytmusic.get_artist_albums(artist["channelId"], params)

for album in albums:
    playlist_id = album["playlistId"]
    browse_id = album["browseId"]
    print("Title: ", album["title"])
    print("playlist_id = ", playlist_id)
    print("browse_id = ", browse_id)
    print("\r\r")
  
songs = ytmusic.get_playlist(playlist_id, 1)
Originally created by @marcuma on GitHub (Dec 1, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/481 **Describe the bug** When attempting to get the songs from a playlist, a Key Error is thrown when attempting to get the playlistId from the nav result. ``` Traceback (most recent call last): File "/Users/marcuma/Documents/VSCode Workspace/ytapitest/ytapitest.py", line 28, in <module> songs = ytmusic.get_playlist(playlist_id, 1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/ytmusicapi/mixins/playlists.py", line 112, in get_playlist playlist = {'id': results['playlistId']} ~~~~~~~^^^^^^^^^^^^^^ KeyError: 'playlistId' ``` In the reference docs, under get_artist it says to call get_playlist with the browseId, but uder get_playlist and the function header it says to use playlistId, so I tried it with both. b browseId returns a 404 and playlistId throws the above error. I could be doing something wrong, but from what I can tell, it looks like the data structure being returned from nav isn't as expected and the key can't be located. Here is the client code that produced the error (Note that the channel ID is hard coded). ```python from ytmusicapi import YTMusic import json ytmusic = YTMusic() artists = ytmusic.search("Red", "artists") for artist in artists: print(artist) print("\r\r") artist = ytmusic.get_artist("UCxZlJwRYVVaZSqRS4RArrhw") params = artist["albums"]["params"] albums = ytmusic.get_artist_albums(artist["channelId"], params) for album in albums: playlist_id = album["playlistId"] browse_id = album["browseId"] print("Title: ", album["title"]) print("playlist_id = ", playlist_id) print("browse_id = ", browse_id) print("\r\r") songs = ytmusic.get_playlist(playlist_id, 1) ```
kerem 2026-02-27 23:00:22 +03:00
  • closed this issue
  • added the
    invalid
    label
Author
Owner

@marcuma commented on GitHub (Dec 1, 2023):

I looked at this for a little bit. It looks like they changed the format of the page/json. Some keys were removed and some added, and the track data is much deeper. Most of playlist.py after the response returns would have to be rewritten to accommodate the change.

<!-- gh-comment-id:1835554340 --> @marcuma commented on GitHub (Dec 1, 2023): I looked at this for a little bit. It looks like they changed the format of the page/json. Some keys were removed and some added, and the track data is much deeper. Most of playlist.py after the response returns would have to be rewritten to accommodate the change.
Author
Owner

@sigma67 commented on GitHub (Dec 18, 2023):

You're using get_playlist to retrieve an album, of course it's not working.

Use get_album_browse_id to retrieve the browseId belonging to a audioPlaylistId, then call get_album.

<!-- gh-comment-id:1861448536 --> @sigma67 commented on GitHub (Dec 18, 2023): You're using `get_playlist` to retrieve an album, of course it's not working. Use `get_album_browse_id` to retrieve the `browseId` belonging to a `audioPlaylistId`, then call `get_album`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#358
No description provided.