[GH-ISSUE #462] parsing returned playlist fails when using browser header based authentication #345

Closed
opened 2026-02-27 23:00:18 +03:00 by kerem · 1 comment
Owner

Originally created by @mgoltzsche on GitHub (Oct 22, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/462

Describe the bug
get_liked_songs() function fails with KeyError: 'setVideoId' within the playlist parser when authenticated using a browser.json file with headers copied from the browser.

To Reproduce
To reproduce the problem, run the following with headers containing the HTTP request headers from a POST /browse request listing your liked videos on music.youtube.com:

headers = '<YOUR_YTMUSIC_HTTP_REQUEST_HEADERS>'
ytmusicapi.setup(filepath='./browser.json', headers_raw=headers)
yt = ytmusicapi.YTMusic('./browser.json')
likes = yt.get_liked_songs()

The get_liked_songs() call fails with the following error:

Traceback (most recent call last):
  File "/usr/local/bin/beet", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/beets/ui/__init__.py", line 1285, in main
    _raw_main(args)
  File "/usr/local/lib/python3.12/site-packages/beets/ui/__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/home/beets/.local/lib/python3.12/site-packages/beetsplug/ytimport/__init__.py", line 36, in run_import_cmd
    likedIds = youtube.likes(auth, opts.max_likes)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/beets/.local/lib/python3.12/site-packages/beetsplug/ytimport/youtube.py", line 14, in likes
    likes = yt.get_liked_songs(max_tracks)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/beets/.local/lib/python3.12/site-packages/ytmusicapi/mixins/library.py", line 194, in get_liked_songs
    return self.get_playlist('LM', limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/beets/.local/lib/python3.12/site-packages/ytmusicapi/mixins/playlists.py", line 186, in get_playlist
    playlist['tracks'] = parse_playlist_items(results['contents'])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/beets/.local/lib/python3.12/site-packages/ytmusicapi/parsers/playlists.py", line 23, in parse_playlist_items
    setVideoId = menu_service['playlistEditEndpoint']['actions'][0][
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'setVideoId'

Additional context
The error happens only when using browser header authentication. It does not happen when using OAuth.

Issue #450 might be related.

Originally created by @mgoltzsche on GitHub (Oct 22, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/462 **Describe the bug** `get_liked_songs()` function fails with `KeyError: 'setVideoId'` within the playlist parser when authenticated using a browser.json file with headers copied from the browser. **To Reproduce** To reproduce the problem, run the following with `headers` containing the HTTP request headers from a POST `/browse` request listing your liked videos on music.youtube.com: ```python headers = '<YOUR_YTMUSIC_HTTP_REQUEST_HEADERS>' ytmusicapi.setup(filepath='./browser.json', headers_raw=headers) yt = ytmusicapi.YTMusic('./browser.json') likes = yt.get_liked_songs() ``` The `get_liked_songs()` call fails with the following error: ``` Traceback (most recent call last): File "/usr/local/bin/beet", line 8, in <module> sys.exit(main()) ^^^^^^ File "/usr/local/lib/python3.12/site-packages/beets/ui/__init__.py", line 1285, in main _raw_main(args) File "/usr/local/lib/python3.12/site-packages/beets/ui/__init__.py", line 1272, in _raw_main subcommand.func(lib, suboptions, subargs) File "/home/beets/.local/lib/python3.12/site-packages/beetsplug/ytimport/__init__.py", line 36, in run_import_cmd likedIds = youtube.likes(auth, opts.max_likes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/beets/.local/lib/python3.12/site-packages/beetsplug/ytimport/youtube.py", line 14, in likes likes = yt.get_liked_songs(max_tracks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/beets/.local/lib/python3.12/site-packages/ytmusicapi/mixins/library.py", line 194, in get_liked_songs return self.get_playlist('LM', limit) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/beets/.local/lib/python3.12/site-packages/ytmusicapi/mixins/playlists.py", line 186, in get_playlist playlist['tracks'] = parse_playlist_items(results['contents']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/beets/.local/lib/python3.12/site-packages/ytmusicapi/parsers/playlists.py", line 23, in parse_playlist_items setVideoId = menu_service['playlistEditEndpoint']['actions'][0][ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: 'setVideoId' ``` **Additional context** The error happens only when using browser header authentication. It does not happen when using OAuth. Issue #450 might be related.
kerem 2026-02-27 23:00:18 +03:00
  • closed this issue
  • added the
    yt-update
    label
Author
Owner

@sigma67 commented on GitHub (Oct 23, 2023):

You must be using different accounts, I don't see why there should be any difference between browser auth and oauth.

This is probably part of some A/B test, so I'm a bit hesitant to merge.

setVideoId is also essential to move items within a playlist, so the fix isn't to just ignore it if it's not there. Instead we need to find the new location within the data (or the new mechanism if it works entirely different now).

<!-- gh-comment-id:1774641048 --> @sigma67 commented on GitHub (Oct 23, 2023): You must be using different accounts, I don't see why there should be any difference between browser auth and oauth. This is probably part of some A/B test, so I'm a bit hesitant to merge. `setVideoId` is also essential to move items within a playlist, so the fix isn't to just ignore it if it's not there. Instead we need to find the new location within the data (or the new mechanism if it works entirely different now).
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#345
No description provided.