From 93d744897f9b8c8d0e7e2b1f273b14548a23e73e Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 18 Jun 2020 12:48:42 +0200 Subject: [PATCH] Fix bugs in playlist parsing (unavailable and uploaded songs) (closes #30) --- ytmusicapi/parsers.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ytmusicapi/parsers.py b/ytmusicapi/parsers.py index 67f14a1..48ab054 100644 --- a/ytmusicapi/parsers.py +++ b/ytmusicapi/parsers.py @@ -110,6 +110,7 @@ def parse_playlist_items(results): try: # if playlist is not owned, the playlist item can't be interacted with videoId = setVideoId = None + like = None # if item is not playable, there is no videoId if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON): @@ -123,6 +124,9 @@ def parse_playlist_items(results): item, MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['setVideoId'] break + if 'menu' in data: + like = nav(data, MENU_LIKE_STATUS) + title = get_item_text(data, 0) if title == 'Song deleted': continue @@ -141,10 +145,6 @@ def parse_playlist_items(results): duration = data['fixedColumns'][0][ 'musicResponsiveListItemFixedColumnRenderer']['text']['runs'][0]['text'] - like = None - if 'menu' in data and 'topLevelButtons' in nav(data, MENU): - like = nav(data, MENU_LIKE_STATUS) - thumbnails = None if 'thumbnail' in data: thumbnails = nav(data, THUMBNAILS) @@ -255,6 +255,8 @@ def parse_search_result(data, resultType=None): def parse_song_artists(data, index): flex_item = get_flex_column_item(data, index) + if not flex_item: + return None artists = [] for j in range(int(len(flex_item['text']['runs']) / 2) + 1): artists.append({