From 71bb395dfa86d70447008265025c4f36017b2cf0 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Tue, 17 Jun 2014 07:40:20 -0400 Subject: [PATCH] Added 'add_to_playlist' example --- examples/add_tracks_to_playlist.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/add_tracks_to_playlist.py diff --git a/examples/add_tracks_to_playlist.py b/examples/add_tracks_to_playlist.py new file mode 100644 index 0000000..16aaaba --- /dev/null +++ b/examples/add_tracks_to_playlist.py @@ -0,0 +1,28 @@ + +# Adds tracks to a playlist + +import pprint +import sys + +import spotipy +import spotipy.oauth2 as oauth2 +import util + +if len(sys.argv) > 3: + username = sys.argv[1] + playlist_id = sys.argv[2] + track_ids = sys.argv[3:] +else: + print "Usage: %s username playlist_id track_id ..." % (sys.argv[0],) + sys.exit() + +scope = 'playlist-modify' +token = util.prompt_for_user_token(username, scope) + +if token: + sp = spotipy.Spotify(auth=token) + sp.trace = False + results = sp.user_playlist_add_tracks(username, playlist_id, track_ids) + pprint.pprint(results) +else: + print "Can't get token for", username