Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Last active July 11, 2020 21:45
Show Gist options
  • Save jmeridth/129e63d79b1d27e786ff8a9bbea61356 to your computer and use it in GitHub Desktop.
Save jmeridth/129e63d79b1d27e786ff8a9bbea61356 to your computer and use it in GitHub Desktop.
python code using tekore package to moved saved (liked) tracks from one spotify account to another.
CLIENT_ID=PUT_CLIENT_ID_HERE
CLIENT_SECRET=PUT_CLIENT_SECRET_HERE
REDIRECT_URI=PUT_REDIRECT_URI_HERE
import tekore as tk
import os
client_id = os.environ.get("CLIENT_ID")
client_secret = os.environ.get("CLIENT_SECRET")
redirect_uri = os.environ.get("REDIRECT_URI")
conf = (client_id, client_secret, redirect_uri)
token = tk.prompt_for_user_token(*conf, scope=tk.scope.every)
# will open webpage for you to log into first account
spotify = tk.Spotify(token)
saved_tracks = []
offset = 0
limit = 50
while(True):
tracks = spotify.saved_tracks(limit=limit, offset=offset)
if(len(tracks.items) == 0):
break;
saved_tracks.extend(tracks.items)
if(len(tracks.items) < offset):
break
offset += offset
print("{} Saved Songs Found".format(len(saved_tracks)))
token = tk.prompt_for_user_token(*conf, scope=tk.scope.every)
spotify = tk.Spotify(token)
saved_track_ids = [track.track.id for track in saved_tracks]
for chunk in zip(*(iter(saved_track_ids),) * limit):
try:
spotify.saved_tracks_add(track_ids=chunk)
except Exception as e:
print(e)
print('done adding saved songs to new account')
certifi==2020.6.20
chardet==3.0.4
idna==2.10
requests==2.24.0
six==1.15.0
spotipy==2.13.0
urllib3==1.25.9
#!/bin/bash
cp .env.template .env
source .env
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
python move_saved_songs_from_one_account_to_another.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment