From 369ac9323f858ac0a7332f47e0a93f62c2f3a2ce Mon Sep 17 00:00:00 2001 From: sigma67 Date: Tue, 3 Oct 2023 16:02:49 +0200 Subject: [PATCH] edit_playlist: change addToTop function parameter to Optional[bool] (#444) --- tests/test.py | 1 + ytmusicapi/mixins/playlists.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test.py b/tests/test.py index 59f09a9..020fd18 100644 --- a/tests/test.py +++ b/tests/test.py @@ -480,6 +480,7 @@ class TestYTMusic(unittest.TestCase): self.assertEqual(response["status"], "STATUS_SUCCEEDED", "Adding playlist item failed") self.assertGreater(len(response["playlistEditResults"]), 0, "Adding playlist item failed") time.sleep(2) + self.yt_brand.edit_playlist(playlistId, addToTop=False) playlist = self.yt_brand.get_playlist(playlistId, related=True) self.assertEqual(len(playlist["tracks"]), 46, "Getting playlist items failed") response = self.yt_brand.remove_playlist_items(playlistId, playlist["tracks"]) diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 8446290..997918c 100644 --- a/ytmusicapi/mixins/playlists.py +++ b/ytmusicapi/mixins/playlists.py @@ -1,4 +1,4 @@ -from typing import Dict, Union, Tuple +from typing import Dict, Union, Tuple, Optional from ._utils import * from ytmusicapi.continuations import * @@ -233,7 +233,7 @@ class PlaylistsMixin: privacyStatus: str = None, moveItem: Tuple[str, str] = None, addPlaylistId: str = None, - addToTop: bool = False) -> Union[str, Dict]: + addToTop: Optional[bool] = None) -> Union[str, Dict]: """ Edit title, description or privacyStatus of a playlist. You may also move an item within a playlist or append another playlist to this playlist. @@ -244,8 +244,9 @@ class PlaylistsMixin: :param privacyStatus: Optional. New privacy status for the playlist :param moveItem: Optional. Move one item before another. Items are specified by setVideoId, see :py:func:`get_playlist` :param addPlaylistId: Optional. Id of another playlist to add to this playlist - :param addToTop: Optional. Change the state of this playlist to add items to the top of the playlist by default. - :return: Status String or full responwwwse + :param addToTop: Optional. Change the state of this playlist to add items to the top of the playlist (if True) + or the bottom of the playlist (if False - this is also the default of a new playlist). + :return: Status String or full response """ self._check_auth() body = {'playlistId': validate_playlist_id(playlistId)} @@ -278,6 +279,9 @@ class PlaylistsMixin: if addToTop: actions.append({'action': 'ACTION_SET_ADD_TO_TOP', 'addToTop': 'true'}) + if addToTop is not None: + actions.append({'action': 'ACTION_SET_ADD_TO_TOP', 'addToTop': str(addToTop)}) + body['actions'] = actions endpoint = 'browse/edit_playlist' response = self._send_request(endpoint, body)