mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-06 14:52:50 +00:00
Merge pull request #196 from nathancoleman/playlist_description_support
Playlist description support
This commit is contained in:
commit
328fc1a4ae
@ -19,9 +19,13 @@ if len(sys.argv) > 3:
|
|||||||
if len(sys.argv) > 5:
|
if len(sys.argv) > 5:
|
||||||
collaborative = sys.argv[5].lower() == 'true'
|
collaborative = sys.argv[5].lower() == 'true'
|
||||||
|
|
||||||
|
description = None
|
||||||
|
if len(sys.argv) > 6:
|
||||||
|
description = sys.argv[6]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print ("Usage: %s username playlist_id name [public collaborative]" %
|
print ("Usage: %s username playlist_id name [public collaborative "
|
||||||
(sys.argv[0]))
|
"description]" % (sys.argv[0]))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
scope = 'playlist-modify-public playlist-modify-private'
|
scope = 'playlist-modify-public playlist-modify-private'
|
||||||
@ -32,7 +36,7 @@ if token:
|
|||||||
sp.trace = False
|
sp.trace = False
|
||||||
results = sp.user_playlist_change_details(
|
results = sp.user_playlist_change_details(
|
||||||
username, playlist_id, name=name, public=public,
|
username, playlist_id, name=name, public=public,
|
||||||
collaborative=collaborative)
|
collaborative=collaborative, description=description)
|
||||||
print results
|
print results
|
||||||
else:
|
else:
|
||||||
print "Can't get token for", username
|
print "Can't get token for", username
|
||||||
|
@ -12,8 +12,9 @@ import spotipy.util as util
|
|||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
playlist_name = sys.argv[2]
|
playlist_name = sys.argv[2]
|
||||||
|
playlist_description = sys.argv[3]
|
||||||
else:
|
else:
|
||||||
print("Usage: %s username playlist-name" % (sys.argv[0],))
|
print("Usage: %s username playlist-name playlist-description" % (sys.argv[0],))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
token = util.prompt_for_user_token(username)
|
token = util.prompt_for_user_token(username)
|
||||||
@ -21,7 +22,8 @@ token = util.prompt_for_user_token(username)
|
|||||||
if token:
|
if token:
|
||||||
sp = spotipy.Spotify(auth=token)
|
sp = spotipy.Spotify(auth=token)
|
||||||
sp.trace = False
|
sp.trace = False
|
||||||
playlists = sp.user_playlist_create(username, playlist_name)
|
playlists = sp.user_playlist_create(username, playlist_name,
|
||||||
|
playlist_description)
|
||||||
pprint.pprint(playlists)
|
pprint.pprint(playlists)
|
||||||
else:
|
else:
|
||||||
print("Can't get token for", username)
|
print("Can't get token for", username)
|
||||||
|
@ -399,20 +399,24 @@ class Spotify(object):
|
|||||||
limit=limit, offset=offset, fields=fields,
|
limit=limit, offset=offset, fields=fields,
|
||||||
market=market)
|
market=market)
|
||||||
|
|
||||||
def user_playlist_create(self, user, name, public=True):
|
|
||||||
|
def user_playlist_create(self, user, name, public=True, description=''):
|
||||||
""" Creates a playlist for a user
|
""" Creates a playlist for a user
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- user - the id of the user
|
- user - the id of the user
|
||||||
- name - the name of the playlist
|
- name - the name of the playlist
|
||||||
- public - is the created playlist public
|
- public - is the created playlist public
|
||||||
|
- description - the description of the playlist
|
||||||
"""
|
"""
|
||||||
data = {'name': name, 'public': public}
|
data = {'name': name, 'public': public, 'description': description}
|
||||||
|
|
||||||
|
|
||||||
return self._post("users/%s/playlists" % (user,), payload=data)
|
return self._post("users/%s/playlists" % (user,), payload=data)
|
||||||
|
|
||||||
def user_playlist_change_details(
|
def user_playlist_change_details(
|
||||||
self, user, playlist_id, name=None, public=None,
|
self, user, playlist_id, name=None, public=None,
|
||||||
collaborative=None):
|
collaborative=None, description=None):
|
||||||
""" Changes a playlist's name and/or public/private state
|
""" Changes a playlist's name and/or public/private state
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
@ -421,7 +425,9 @@ class Spotify(object):
|
|||||||
- name - optional name of the playlist
|
- name - optional name of the playlist
|
||||||
- public - optional is the playlist public
|
- public - optional is the playlist public
|
||||||
- collaborative - optional is the playlist collaborative
|
- collaborative - optional is the playlist collaborative
|
||||||
|
- description - optional description of the playlist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
if isinstance(name, six.string_types):
|
if isinstance(name, six.string_types):
|
||||||
data['name'] = name
|
data['name'] = name
|
||||||
@ -429,6 +435,8 @@ class Spotify(object):
|
|||||||
data['public'] = public
|
data['public'] = public
|
||||||
if isinstance(collaborative, bool):
|
if isinstance(collaborative, bool):
|
||||||
data['collaborative'] = collaborative
|
data['collaborative'] = collaborative
|
||||||
|
if isinstance(description, six.string_types):
|
||||||
|
data['description'] = description
|
||||||
return self._put("users/%s/playlists/%s" % (user, playlist_id),
|
return self._put("users/%s/playlists/%s" % (user, playlist_id),
|
||||||
payload=data)
|
payload=data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user