Skip to content

Commit

Permalink
edit_playlist: change addToTop function parameter to Optional[bool] (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Oct 3, 2023
1 parent 6f7dfce commit 369ac93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ def test_end2end(self):
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"])
Expand Down
12 changes: 8 additions & 4 deletions ytmusicapi/mixins/playlists.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Union, Tuple
from typing import Dict, Union, Tuple, Optional
from ._utils import *

from ytmusicapi.continuations import *
Expand Down Expand Up @@ -233,7 +233,7 @@ def edit_playlist(self,
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.
Expand All @@ -244,8 +244,9 @@ def edit_playlist(self,
: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)}
Expand Down Expand Up @@ -278,6 +279,9 @@ def edit_playlist(self,
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)
Expand Down

0 comments on commit 369ac93

Please sign in to comment.