Skip to content

Commit

Permalink
Add videoId param for shuffling playlists (determines first video in …
Browse files Browse the repository at this point in the history
…shuffled playlist)
  • Loading branch information
sigma67 committed Feb 17, 2021
1 parent 23f278c commit cc69b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def test_get_watch_playlist_shuffle(self):
self.assertEqual(len(playlist['tracks']), 12)

def test_get_watch_playlist_shuffle_playlist(self):
playlist = youtube.get_watch_playlist_shuffle(
playlistId="PL528pVfw3ao0x8jlW3kwdIx1FEMMeeghb", limit=99)
playlist = youtube_auth.get_watch_playlist_shuffle(
videoId="u6XiiXJD0jg", playlistId="PL528pVfw3ao2VzfY6zE1TOZm1cBSdk7Q0", limit=99)
self.assertGreaterEqual(len(playlist['tracks']), 80)

###############
Expand Down
15 changes: 9 additions & 6 deletions ytmusicapi/mixins/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def get_watch_playlist(self,
body = {'enablePersistentPlaylistPanel': True, 'isAudioOnly': True}
if videoId:
body['videoId'] = videoId
body['watchEndpointMusicSupportedConfigs'] = {
'watchEndpointMusicConfig': {
'hasPersistentPlaylistPanel': True,
'musicVideoType': "MUSIC_VIDEO_TYPE_OMV",
if not params:
body['watchEndpointMusicSupportedConfigs'] = {
'watchEndpointMusicConfig': {
'hasPersistentPlaylistPanel': True,
'musicVideoType': "MUSIC_VIDEO_TYPE_OMV",
}
}
}
is_playlist = False
if playlistId:
body['playlistId'] = playlistId
Expand Down Expand Up @@ -89,13 +90,15 @@ def get_watch_playlist(self,
return {'tracks': tracks, 'lyrics': lyrics_browse_id}

def get_watch_playlist_shuffle(self,
videoId: str = None,
playlistId: str = None,
limit=50) -> Dict[List[Dict], str]:
"""
Shuffle any playlist
:param videoId: Optional video id of the first video in the shuffled playlist
:param playlistId: Playlist id
:param limit: The number of watch playlist items to return
:return: A list of watch playlist items (see :py:func:`get_watch_playlist`)
"""
return self.get_watch_playlist(playlistId=playlistId, limit=limit, params='wAEB8gECGAE%3D')
return self.get_watch_playlist(videoId=videoId, playlistId=playlistId, limit=limit, params='wAEB8gECKAE%3D')

0 comments on commit cc69b56

Please sign in to comment.