mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-07-30 14:00:18 +00:00
refacord to support playlist editing
This commit is contained in:
32
examples/remove_specific_tracks_from_playlist.py
Normal file
32
examples/remove_specific_tracks_from_playlist.py
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
# Adds tracks to a playlist
|
||||
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import spotipy.util as util
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
username = sys.argv[1]
|
||||
playlist_id = sys.argv[2]
|
||||
track_ids_and_positions = sys.argv[3:]
|
||||
track_ids = [ ]
|
||||
for t_pos in sys.argv[3:]:
|
||||
tid, pos = t_pos.split(',')
|
||||
track_ids.append( { "uri" : tid, "positions": [ int(pos)] } )
|
||||
else:
|
||||
print "Usage: %s username playlist_id track_id,pos track_id,pos ..." % (sys.argv[0],)
|
||||
sys.exit()
|
||||
|
||||
scope = 'playlist-modify-public'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.user_playlist_remove_specific_occurrences_of_tracks(username, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print "Can't get token for", username
|
28
examples/remove_tracks_from_playlist.py
Normal file
28
examples/remove_tracks_from_playlist.py
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
# Adds tracks to a playlist
|
||||
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import spotipy.util as 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-public'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.user_playlist_remove_all_occurrences_of_tracks(username, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print "Can't get token for", username
|
28
examples/replace_tracks_in_playlist.py
Normal file
28
examples/replace_tracks_in_playlist.py
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
# Replaces all tracks in a playlist
|
||||
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import spotipy.util as 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-public'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.user_playlist_replace_tracks(username, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print "Can't get token for", username
|
@@ -10,5 +10,7 @@ else:
|
||||
urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu'
|
||||
|
||||
sp = spotipy.Spotify()
|
||||
|
||||
artist = sp.artist(urn)
|
||||
|
||||
pprint.pprint(artist)
|
||||
|
Reference in New Issue
Block a user