Skip to content

Commit

Permalink
create_playlist: return error if unsuccessful (closes #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed May 18, 2020
1 parent 932827d commit 396a76a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ytmusicapi/ytmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def create_playlist(self,
description: str,
privacy_status: str = "PRIVATE",
video_ids: List = None,
source_playlist: str = None) -> str:
source_playlist: str = None) -> Union[str, Dict]:
"""
Creates a new empty playlist and returns its id.
Expand All @@ -766,7 +766,7 @@ def create_playlist(self,
:param privacy_status: Playlists can be 'PUBLIC', 'PRIVATE', or 'UNLISTED'. Default: 'PRIVATE'
:param video_ids: IDs of songs to create the playlist with
:param source_playlist: Another playlist whose songs should be added to the new playlist
:return: ID of the YouTube playlist
:return: ID of the YouTube playlist or full response if there was an error
"""
self.__check_auth()
body = {
Expand All @@ -782,7 +782,7 @@ def create_playlist(self,

endpoint = 'playlist/create'
response = self.__send_request(endpoint, body)
return response['playlistId']
return response['playlistId'] if 'playlistId' in response else response

def edit_playlist(self,
playlistId: str,
Expand All @@ -807,7 +807,10 @@ def edit_playlist(self,
body = {'playlistId': playlistId}
actions = []
if title:
actions.append({'action': 'ACTION_SET_PLAYLIST_NAME', 'playlistName': title})
actions.append({
'action': 'ACTION_SET_PLAYLIST_NAME',
'playlistName': title
})

if description:
actions.append({
Expand All @@ -831,8 +834,8 @@ def edit_playlist(self,
if addPlaylistId:
actions.append({
'action': 'ACTION_ADD_PLAYLIST',
'addedFullListId': addPlaylistId
})
'addedFullListId': addPlaylistId}
)

body['actions'] = actions
endpoint = 'browse/edit_playlist'
Expand Down

0 comments on commit 396a76a

Please sign in to comment.