[GH-ISSUE #8] get_uploaded_songs() fails #7

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

Originally created by @beville on GitHub (Apr 18, 2020).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/8

Thanks for this amazing API! I've been uploading my personal music library using the upload_song function, and it's way more convenient than the web UI.

But I've noticed that if I try to run get_uploaded_songs(), I get an error:

Traceback (most recent call last):
  File "./ytmusic.py", line 46, in <module>
    main()
  File "./ytmusic.py", line 39, in main
    songs = ytmusic.get_uploaded_songs(1)  
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/ytmusic.py", line 607, in get_uploaded_songs
    results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + ITEM_SECTION)['musicShelfRenderer']
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/helpers.py", line 19, in nav
    for k in items: root = root[k]
IndexError: list index out of range

Maybe something on the server side changed since you implemented this?

Originally created by @beville on GitHub (Apr 18, 2020). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/8 Thanks for this amazing API! I've been uploading my personal music library using the upload_song function, and it's way more convenient than the web UI. But I've noticed that if I try to run get_uploaded_songs(), I get an error: ``` Traceback (most recent call last): File "./ytmusic.py", line 46, in <module> main() File "./ytmusic.py", line 39, in main songs = ytmusic.get_uploaded_songs(1) File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/ytmusic.py", line 607, in get_uploaded_songs results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + ITEM_SECTION)['musicShelfRenderer'] File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/helpers.py", line 19, in nav for k in items: root = root[k] IndexError: list index out of range ``` Maybe something on the server side changed since you implemented this?
kerem closed this issue 2026-02-27 22:07:31 +03:00
Author
Owner

@sigma67 commented on GitHub (Apr 19, 2020):

I'm having no issues with my account, so it should still work provided you have uploaded songs. Could you attempt to debug this and post the API response (l. 610 of ytmusic.py) here?

<!-- gh-comment-id:616166082 --> @sigma67 commented on GitHub (Apr 19, 2020): I'm having no issues with my account, so it should still work provided you have uploaded songs. Could you attempt to debug this and post the API response (l. 610 of ytmusic.py) here?
Author
Owner

@beville commented on GitHub (Apr 19, 2020):

I've got probably 1000 songs up so far, and the first one alphabetically has the title "(Am I Just) Fooling Myself"

OK, after these lines:

    endpoint = 'browse'
    body = {"browseId": "FEmusic_library_privately_owned_tracks"}
    response = self.__send_request(endpoint, body)

I added this:

    print(json.dumps(response,indent=2))

My call is:

    songs = ytmusic.get_uploaded_songs(limit=1)

Output was rather voluminous:
response.txt

<!-- gh-comment-id:616188944 --> @beville commented on GitHub (Apr 19, 2020): I've got probably 1000 songs up so far, and the first one alphabetically has the title "(Am I Just) Fooling Myself" OK, after these lines: ``` endpoint = 'browse' body = {"browseId": "FEmusic_library_privately_owned_tracks"} response = self.__send_request(endpoint, body) ``` I added this: ``` print(json.dumps(response,indent=2)) ``` My call is: ``` songs = ytmusic.get_uploaded_songs(limit=1) ``` Output was rather voluminous: [response.txt](https://github.com/sigma67/ytmusicapi/files/4499804/response.txt)
Author
Owner

@sigma67 commented on GitHub (Apr 20, 2020):

Thanks, that was quite helpful. It seems that for you the Carousel up top with the "Last played" entries is not being returned with the request. This can be fixed by looking for the 'itemSectionRenderer' entry instead of a fixed index.

Before I push a fix, could you please check if the same issue appears with get_playlists? It currently uses the same JSON path with a fixed index.

<!-- gh-comment-id:616410521 --> @sigma67 commented on GitHub (Apr 20, 2020): Thanks, that was quite helpful. It seems that for you the Carousel up top with the "Last played" entries is not being returned with the request. This can be fixed by looking for the 'itemSectionRenderer' entry instead of a fixed index. Before I push a fix, could you please check if the same issue appears with `get_playlists`? It currently uses the same JSON path with a fixed index.
Author
Owner

@beville commented on GitHub (Apr 21, 2020):

Looks like I do, in fact, get the same error with get_playlists:

Traceback (most recent call last):
  File "./ytmusic.py", line 34, in <module>
    main()
  File "./ytmusic.py", line 26, in main
    playlists = ytmusic.get_playlists()  
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/ytmusic.py", line 363, in get_playlists
    results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + ITEM_SECTION)['gridRenderer']['items']
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/helpers.py", line 19, in nav
    for k in items: root = root[k]
IndexError: list index out of range
<!-- gh-comment-id:616930631 --> @beville commented on GitHub (Apr 21, 2020): Looks like I do, in fact, get the same error with `get_playlists`: ``` Traceback (most recent call last): File "./ytmusic.py", line 34, in <module> main() File "./ytmusic.py", line 26, in main playlists = ytmusic.get_playlists() File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/ytmusic.py", line 363, in get_playlists results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + ITEM_SECTION)['gridRenderer']['items'] File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/helpers.py", line 19, in nav for k in items: root = root[k] IndexError: list index out of range ```
Author
Owner

@sigma67 commented on GitHub (Apr 21, 2020):

Hey, I've attempted to fix this in 826a72c. Please try the latest version 0.6.1 and reopen if you still have issues.

<!-- gh-comment-id:617085880 --> @sigma67 commented on GitHub (Apr 21, 2020): Hey, I've attempted to fix this in 826a72c. Please try the latest version 0.6.1 and reopen if you still have issues.
Author
Owner

@beville commented on GitHub (Apr 22, 2020):

So, the call to get_playlists now works for me, but when I call get_uploaded_songs, there is now a different error:

Traceback (most recent call last):
  File "./ytmusic.py", line 36, in <module>
    main()
  File "./ytmusic.py", line 30, in main
    songs = ytmusic.get_uploaded_songs(limit=1)  
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/ytmusic.py", line 622, in get_uploaded_songs
    songs.extend(parse_uploaded_items(results['contents'][1:]))
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/parsers.py", line 68, in parse_uploaded_items
    entityId = nav(data, MENU_ITEMS)[-1]['menuNavigationItemRenderer']['navigationEndpoint'][
  File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/parsers.py", line 139, in nav
    for k in items: root = root[k]
KeyError: 'menu'
<!-- gh-comment-id:617554871 --> @beville commented on GitHub (Apr 22, 2020): So, the call to get_playlists now works for me, but when I call get_uploaded_songs, there is now a different error: ``` Traceback (most recent call last): File "./ytmusic.py", line 36, in <module> main() File "./ytmusic.py", line 30, in main songs = ytmusic.get_uploaded_songs(limit=1) File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/ytmusic.py", line 622, in get_uploaded_songs songs.extend(parse_uploaded_items(results['contents'][1:])) File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/parsers.py", line 68, in parse_uploaded_items entityId = nav(data, MENU_ITEMS)[-1]['menuNavigationItemRenderer']['navigationEndpoint'][ File "/usr/local/lib/python3.7/dist-packages/ytmusicapi/parsers.py", line 139, in nav for k in items: root = root[k] KeyError: 'menu' ```
Author
Owner

@sigma67 commented on GitHub (Apr 22, 2020):

Hey, I think this happened because you had a song processing while you requested your tracks. I'll push a fix shortly.

<!-- gh-comment-id:617722937 --> @sigma67 commented on GitHub (Apr 22, 2020): Hey, I think this happened because you had a song processing while you requested your tracks. I'll push a fix shortly.
Author
Owner

@beville commented on GitHub (Apr 22, 2020):

OK, I did sudo pip3 install git+https://github.com/sigma67/ytmusicapi -U, and have the latest from github.

The function now succeeds! But oddly, I'm getting 25 results, even though the limit is set to 1. Not really an issue for me, since I was only setting that for test purposes.

[I'll probably post a question in the future as I pursue my goal of generating playlists of shuffled-by-album (picking a list of random albums, and playing each album in order). I implemented this with the gmusicapi, and am looking ahead in case it all gets deprecated.]

<!-- gh-comment-id:617857760 --> @beville commented on GitHub (Apr 22, 2020): OK, I did `sudo pip3 install git+https://github.com/sigma67/ytmusicapi -U`, and have the latest from github. The function now succeeds! But oddly, I'm getting 25 results, even though the limit is set to 1. Not really an issue for me, since I was only setting that for test purposes. [I'll probably post a question in the future as I pursue my goal of generating playlists of shuffled-by-album (picking a list of random albums, and playing each album in order). I implemented this with the gmusicapi, and am looking ahead in case it all gets deprecated.]
Author
Owner

@sigma67 commented on GitHub (Apr 22, 2020):

Good point. YoutubeMusic only returns data in 25 increments. Since the API is fetching the data anyway, I thought it may be useful to just return it. It would be trivial though to cut the results to the limit (by subsetting the result list).

Great that you're working with the library, it definitely needs testing from other users. Just to let you know, I'm currently working on the rest of the library functionality. This includes getting library artists and albums, in case you need that for your app.

<!-- gh-comment-id:617874359 --> @sigma67 commented on GitHub (Apr 22, 2020): Good point. YoutubeMusic only returns data in 25 increments. Since the API is fetching the data anyway, I thought it may be useful to just return it. It would be trivial though to cut the results to the limit (by subsetting the result list). Great that you're working with the library, it definitely needs testing from other users. Just to let you know, I'm currently working on the rest of the library functionality. This includes getting library artists and albums, in case you need that for your app.
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#7
No description provided.