Created
April 17, 2018 03:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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