From cc69b56c2049133c232d473b3d32921241773bfd Mon Sep 17 00:00:00 2001 From: sigma67 Date: Wed, 17 Feb 2021 15:44:26 +0100 Subject: [PATCH] Add videoId param for shuffling playlists (determines first video in shuffled playlist) --- tests/test.py | 4 ++-- ytmusicapi/mixins/watch.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test.py b/tests/test.py index db089a1..b8ab593 100644 --- a/tests/test.py +++ b/tests/test.py @@ -121,8 +121,8 @@ class TestYTMusic(unittest.TestCase): 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) ############### diff --git a/ytmusicapi/mixins/watch.py b/ytmusicapi/mixins/watch.py index 537492d..99e290f 100644 --- a/ytmusicapi/mixins/watch.py +++ b/ytmusicapi/mixins/watch.py @@ -50,12 +50,13 @@ class WatchMixin: 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 @@ -89,13 +90,15 @@ class WatchMixin: 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')