Parse setVideoId for unplayable items (closes #83)

This commit is contained in:
sigma67 2020-09-28 10:36:03 +02:00
commit 14daa31ab1
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0

View file

@ -12,22 +12,26 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
data = result['musicResponsiveListItemRenderer']
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):
videoId = nav(data,
PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
for item in nav(data, MENU_ITEMS):
# if the item has a menu, find its setVideoId
if 'menu' in data:
for item in reversed(nav(data, MENU_ITEMS)):
if 'menuServiceItemRenderer' in item and 'playlistEditEndpoint' in nav(
item, MENU_SERVICE):
setVideoId = nav(
item, MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['setVideoId']
videoId = nav(
item,
MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['removedVideoId']
break
# if item is not playable, the videoId was retrieved above
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
videoId = nav(data,
PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
if 'menu' in data:
like = nav(data, MENU_LIKE_STATUS, True)