[GH-ISSUE #242] 2021 Recap playlist breaking get_playlist #187

Closed
opened 2026-02-27 22:08:30 +03:00 by kerem · 3 comments
Owner

Originally created by @kenbier on GitHub (Dec 11, 2021).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/242

Python 3.9, ytmusicapi 0.19.5

I am trying to pull the 2021 Recap playlist. When I pull a different playlist (change index on first line to 0, 2, etc) the code works.

Seems to be the 2021 Recap playlist only.

code:

recap = ytmusic.get_library_playlists()[1] ## My 2021 Recap playlist is the second playlist in the list.
print(recap)
id = recap['playlistId']
print(id)
ytmusic.get_playlist(id)

Stack trace:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/var/folders/tw/0871sv955631wvlml90j8c7h0000gn/T/ipykernel_53517/4079440716.py in <module>
      4 id = recap['playlistId']
      5 print(id)
----> 6 ytmusic.get_playlist(id)

~/miniconda3/envs/emails/lib/python3.9/site-packages/ytmusicapi/mixins/playlists.py in get_playlist(self, playlistId, limit)
     88             }
     89             if run_count > 3:
---> 90                 playlist['year'] = nav(header, SUBTITLE3)
     91 
     92         song_count = to_int(

~/miniconda3/envs/emails/lib/python3.9/site-packages/ytmusicapi/parsers/utils.py in nav(root, items, none_if_absent)
    153             return None
    154         else:
--> 155             raise err
    156 
    157 

~/miniconda3/envs/emails/lib/python3.9/site-packages/ytmusicapi/parsers/utils.py in nav(root, items, none_if_absent)
    147     try:
    148         for k in items:
--> 149             root = root[k]
    150         return root
    151     except Exception as err:

IndexError: list index out of range
Originally created by @kenbier on GitHub (Dec 11, 2021). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/242 **Python 3.9, ytmusicapi 0.19.5** I am trying to pull the 2021 Recap playlist. When I pull a different playlist (change index on first line to 0, 2, etc) the code works. Seems to be the 2021 Recap playlist only. code: ```python3 recap = ytmusic.get_library_playlists()[1] ## My 2021 Recap playlist is the second playlist in the list. print(recap) id = recap['playlistId'] print(id) ytmusic.get_playlist(id) ``` Stack trace: ``` --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /var/folders/tw/0871sv955631wvlml90j8c7h0000gn/T/ipykernel_53517/4079440716.py in <module> 4 id = recap['playlistId'] 5 print(id) ----> 6 ytmusic.get_playlist(id) ~/miniconda3/envs/emails/lib/python3.9/site-packages/ytmusicapi/mixins/playlists.py in get_playlist(self, playlistId, limit) 88 } 89 if run_count > 3: ---> 90 playlist['year'] = nav(header, SUBTITLE3) 91 92 song_count = to_int( ~/miniconda3/envs/emails/lib/python3.9/site-packages/ytmusicapi/parsers/utils.py in nav(root, items, none_if_absent) 153 return None 154 else: --> 155 raise err 156 157 ~/miniconda3/envs/emails/lib/python3.9/site-packages/ytmusicapi/parsers/utils.py in nav(root, items, none_if_absent) 147 try: 148 for k in items: --> 149 root = root[k] 150 return root 151 except Exception as err: IndexError: list index out of range ```
kerem closed this issue 2026-02-27 22:08:30 +03:00
Author
Owner

@kenbier commented on GitHub (Dec 11, 2021):

I believe the issue is that you are assuming the playlist year is in fifth index of the subtitle runs here. I.e.

{'text': 'Playlist'}
{'text': ' • '}
{'text': 'YouTube Music'}
{'text': ' • '}
{'text': '2021'}  ### <-- HERE

However for the 2021 recap it looks like this:

{'text': 'Unlisted'}
{'text': ' • '}
{'text': 'Made for '}
{'text': 'ACCOUNT_USERNAME'}

You should guard against the case where the runs list is EXACTLY 4 in length, which is causing the index out of bounds (different schema). You can look for the playlist year elsewhere or just set it to be empty.

<!-- gh-comment-id:991477303 --> @kenbier commented on GitHub (Dec 11, 2021): I believe the issue is that you are assuming the playlist year is in fifth index of the subtitle runs [here](https://github.com/sigma67/ytmusicapi/blob/0.19.5/ytmusicapi/mixins/playlists.py#L90). I.e. ```python3 {'text': 'Playlist'} {'text': ' • '} {'text': 'YouTube Music'} {'text': ' • '} {'text': '2021'} ### <-- HERE ``` However for the 2021 recap it looks like this: ```python3 {'text': 'Unlisted'} {'text': ' • '} {'text': 'Made for '} {'text': 'ACCOUNT_USERNAME'} ``` You should guard against the case where the runs list is EXACTLY 4 in length, which is causing the index out of bounds (different schema). You can look for the playlist year elsewhere or just set it to be empty.
Author
Owner

@sigma67 commented on GitHub (Dec 11, 2021):

Unfortunately I don't have access to the recap yet so I can't test it. I don't suppose it's shareable?

I think we should change > 3 to = 5 to be more precise.

<!-- gh-comment-id:991726542 --> @sigma67 commented on GitHub (Dec 11, 2021): Unfortunately I don't have access to the recap yet so I can't test it. I don't suppose it's shareable? I think we should change > 3 to = 5 to be more precise.
Author
Owner

@kenbier commented on GitHub (Dec 11, 2021):

That seems like the right fix yes, since you are assuming the fifth index is non null. If it is null, just ignoring the year seems like the simplest action for now.

If you want a 2021 Recap test case, you need to save your 2021 Recap as a playlist and make it pubic before the API can access it I believe.

<!-- gh-comment-id:991751111 --> @kenbier commented on GitHub (Dec 11, 2021): That seems like the right fix yes, since you are assuming the fifth index is non null. If it is null, just ignoring the year seems like the simplest action for now. If you want a 2021 Recap test case, you need to save your 2021 Recap as a playlist and make it pubic before the API can access it I believe.
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#187
No description provided.