Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2021 Recap playlist breaking get_playlist #242

Closed
kenbier opened this issue Dec 11, 2021 · 3 comments
Closed

2021 Recap playlist breaking get_playlist #242

kenbier opened this issue Dec 11, 2021 · 3 comments

Comments

@kenbier
Copy link
Contributor

kenbier commented Dec 11, 2021

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
@kenbier
Copy link
Contributor Author

kenbier commented 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.

@sigma67
Copy link
Owner

sigma67 commented 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.

@kenbier
Copy link
Contributor Author

kenbier commented 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.

kenbier added a commit to kenbier/ytmusicapi that referenced this issue Dec 11, 2021
Fix issue [242](sigma67#242) by changing run_count check to == 5.
@kenbier kenbier mentioned this issue Dec 11, 2021
sigma67 pushed a commit that referenced this issue Dec 12, 2021
Fix issue [242](#242) by changing run_count check to == 5.
@sigma67 sigma67 closed this as completed Dec 12, 2021
chaosgen added a commit to chaosgen/ytmusicapi that referenced this issue Oct 31, 2024
Fix issue [242](sigma67/ytmusicapi#242) by changing run_count check to == 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants