Skip to content

Instantly share code, notes, and snippets.

@isidroamv
Created April 17, 2018 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isidroamv/27313759d39adfb0a66017bf63c71d25 to your computer and use it in GitHub Desktop.
Save isidroamv/27313759d39adfb0a66017bf63c71d25 to your computer and use it in GitHub Desktop.
Use this script to migrate your spotify library from one account to another
import requests
old_token = ''
new_token = ''
h = {
'Authorization': 'Bearer ' + old_token
}
tracks = []
index = 0
while True:
url = 'https://api.spotify.com/v1/me/tracks?limit=20&offset='+str(index)
print("url", url)
r = requests.get(url, headers=h)
d = r.json()
if len(d['items']) == 0:
break
else:
tracks = tracks + d['items']
print("total", len(tracks))
index += 20
h = {
'Authorization': 'Bearer ' + new_token
}
for track in tracks:
track_id = track['track']['id']
url = 'https://api.spotify.com/v1/me/tracks?ids=' + track_id
requests.put(url, headers=h)
print(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment