Always try to obtain setVideoId of playlist items
Collaborative playlists allow collaborators to remove items, so the items have setVideoId assigned, but the playlists themselves do not appear editable - they are not owned. Make it so that attempt to obtain setVideoId is performed also in such cases. Signed-off-by: Nikola Forró <nforro@redhat.com>
This commit is contained in:
parent
97b34bcf5a
commit
c86d4de662
2 changed files with 18 additions and 18 deletions
|
|
@ -88,7 +88,7 @@ def parse_albums(results):
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
|
|
||||||
def parse_playlist_items(results, owned=False):
|
def parse_playlist_items(results):
|
||||||
songs = []
|
songs = []
|
||||||
count = 1
|
count = 1
|
||||||
for result in results:
|
for result in results:
|
||||||
|
|
@ -100,21 +100,21 @@ def parse_playlist_items(results, owned=False):
|
||||||
try:
|
try:
|
||||||
# if playlist is not owned, the playlist item can't be interacted with
|
# if playlist is not owned, the playlist item can't be interacted with
|
||||||
videoId = setVideoId = None
|
videoId = setVideoId = None
|
||||||
if owned:
|
|
||||||
for item in nav(data, MENU_ITEMS):
|
# if item is not playable, there is no videoId
|
||||||
if 'menuServiceItemRenderer' in item and 'playlistEditEndpoint' in nav(
|
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
|
||||||
item, MENU_SERVICE):
|
videoId = nav(
|
||||||
setVideoId = nav(
|
data, PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
|
||||||
item, MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['setVideoId']
|
|
||||||
videoId = nav(
|
for item in nav(data, MENU_ITEMS):
|
||||||
item,
|
if 'menuServiceItemRenderer' in item and 'playlistEditEndpoint' in nav(
|
||||||
MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['removedVideoId']
|
item, MENU_SERVICE):
|
||||||
break
|
setVideoId = nav(
|
||||||
else:
|
item, MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['setVideoId']
|
||||||
# if item is not playable, there is no videoId
|
|
||||||
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
|
|
||||||
videoId = nav(
|
videoId = nav(
|
||||||
data, PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
|
item,
|
||||||
|
MENU_SERVICE)['playlistEditEndpoint']['actions'][0]['removedVideoId']
|
||||||
|
break
|
||||||
|
|
||||||
title = get_item_text(data, 0)
|
title = get_item_text(data, 0)
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ def parse_playlist_items(results, owned=False):
|
||||||
song = {'videoId': videoId, 'title': title, 'artists': artists, 'album': album}
|
song = {'videoId': videoId, 'title': title, 'artists': artists, 'album': album}
|
||||||
if duration:
|
if duration:
|
||||||
song['duration'] = duration
|
song['duration'] = duration
|
||||||
if owned:
|
if setVideoId:
|
||||||
song['setVideoId'] = setVideoId
|
song['setVideoId'] = setVideoId
|
||||||
|
|
||||||
songs.append(song)
|
songs.append(song)
|
||||||
|
|
|
||||||
|
|
@ -737,13 +737,13 @@ class YTMusic:
|
||||||
playlist['tracks'] = []
|
playlist['tracks'] = []
|
||||||
|
|
||||||
if song_count > 0:
|
if song_count > 0:
|
||||||
playlist['tracks'].extend(parse_playlist_items(results['contents'], own_playlist))
|
playlist['tracks'].extend(parse_playlist_items(results['contents']))
|
||||||
songs_to_get = min(limit, song_count)
|
songs_to_get = min(limit, song_count)
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
request_func = lambda additionalParams: self.__send_request(
|
request_func = lambda additionalParams: self.__send_request(
|
||||||
endpoint, body, additionalParams)
|
endpoint, body, additionalParams)
|
||||||
parse_func = lambda contents: parse_playlist_items(contents, own_playlist)
|
parse_func = lambda contents: parse_playlist_items(contents)
|
||||||
playlist['tracks'].extend(
|
playlist['tracks'].extend(
|
||||||
get_continuations(results, 'musicPlaylistShelfContinuation', 100, songs_to_get,
|
get_continuations(results, 'musicPlaylistShelfContinuation', 100, songs_to_get,
|
||||||
request_func, parse_func))
|
request_func, parse_func))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue