sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.59k stars 182 forks source link

KeyError: "Unable to find 'menu' using path #587

Closed ClintGreen5150 closed 1 month ago

ClintGreen5150 commented 1 month ago

I am very new to this so I apologize if I'm doing this wrong...

I'm trying to create playlists of a few thousand tracks but I keep hitting this keyerror. It's completely intermittent, occurs on a different track each time. I am using the search function to find an album, grabbing the albumID and using that to browse to the album, then selecting a random track and using its ID to add it to the playlist. This seems to happen around the 200 track mark but it has also happened after adding about 80 tracks in this manner.

I've tried batching the artist/album data to chunks of 100 but the issue persists.

To Reproduce Steps to reproduce the behavior: I really am not sure unfortunately, it is intermittent, it just happens on a random track when trying to add to a playlist.

Additional context Using the latest version, 1.7.2

sigma67 commented 1 month ago

Hi, thanks for the report.

Please provide the full stack trace and error message, including the search term you used.

ClintGreen5150 commented 1 month ago

I hope this is correct and what you are looking for - I am still learning code, 2 months in :)

Search results for blackened entrails - manifesto sepulcral: [{'title': 'manifesto sepulcral', 'artist': 'blackened entrails', 'browseId': 'MPREb_RME6sh1SHeK', 'resultType': 'album'}] Traceback (most recent call last): File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator.conda\Lib\site-packages\ytmusicapi\navigation.py", line 106, in nav root = root[k]


KeyError: 'menu'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator\YT_playlist_gen.py", line 127, in <module>
    search_results = yt.search(search_query)
                     ^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator\.conda\Lib\site-packages\ytmusicapi\mixins\search.py", line 236, in search
    parse_search_results(shelf_contents, search_result_types, result_type, category)
  File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator\.conda\Lib\site-packages\ytmusicapi\parsers\search.py", line 178, in parse_search_results
    parse_search_result(result[MRLIR], search_result_types, resultType, category) for result in results
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator\.conda\Lib\site-packages\ytmusicapi\parsers\search.py", line 91, in parse_search_result
    parse_menu_playlists(data, search_result)
  File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator\.conda\Lib\site-packages\ytmusicapi\parsers\_utils.py", line 7, in parse_menu_playlists
    watch_menu = find_objects_by_key(nav(data, MENU_ITEMS), MNIR)
                                     ^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\User\PycharmProjects\YT-Music-Playlist-Generator\.conda\Lib\site-packages\ytmusicapi\navigation.py", line 110, in nav
    raise type(e)(f"Unable to find '{k}' using path {items!r} on {root!r}, exception: {e}")
KeyError: "Unable to find 'menu' using path ['menu', 'menuRenderer', 'items'] on {'trackingParams': 'CBAQyfQCGAAiEwi9rbHTwqSGAxWJyEkHHdMEDDM=', 'thumbnail': {'musicThumbnailRenderer': {'thumbnail': 
{}, 'thumbnailCrop': 'MUSIC_THUMBNAIL_CROP_CIRCLE', 'thumbnailScale': 'MUSIC_THUMBNAIL_SCALE_ASPECT_FILL', 'trackingParams': 'CBEQhL8CIhMIva2x08KkhgMVichJBx3TBAwz'}}, 'flexColumns': [{'musicResponsiveListItemFlexColumnRenderer': {'text': {'runs': [{'text': 'Jianxin Li'}]}, 'displayPriority': 'MUSIC_RESPONSIVE_LIST_ITEM_COLUMN_DISPLAY_PRIORITY_HIGH'}}, {'musicResponsiveListItemFlexColumnRenderer': {'text': {'runs': [{'text': 'Profile'}]}, 'displayPriority': 'MUSIC_RESPONSIVE_LIST_ITEM_COLUMN_DISPLAY_PRIORITY_HIGH'}}], 'flexColumnDisplayStyle': 'MUSIC_RESPONSIVE_LIST_ITEM_FLEX_COLUMN_DISPLAY_STYLE_TWO_LINE_STACK', 'navigationEndpoint': {'clickTrackingParams': 'CBAQyfQCGAAiEwi9rbHTwqSGAxWJyEkHHdMEDDM=', 'browseEndpoint': {'browseId': 'UC_usPjyxDU93yOVnY32_b_Q', 'browseEndpointContextSupportedConfigs': {'browseEndpointContextMusicConfig': {'pageType': 'MUSIC_PAGE_TYPE_UNKNOWN'}}}}, 'itemHeight': 'MUSIC_RESPONSIVE_LIST_ITEM_HEIGHT_TALL'}, exception: 'menu'"
sigma67 commented 1 month ago

@ClintGreen5150 please check if the linked PR fixes it