Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Last active July 11, 2020 21:45
Show Gist options
  • Select an option

  • Save jmeridth/129e63d79b1d27e786ff8a9bbea61356 to your computer and use it in GitHub Desktop.

Select an option

Save jmeridth/129e63d79b1d27e786ff8a9bbea61356 to your computer and use it in GitHub Desktop.

Revisions

  1. jmeridth revised this gist Jul 11, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions move_saved_songs_from_one_account_to_another.py
    Original file line number Diff line number Diff line change
    @@ -14,20 +14,20 @@
    offset = 0
    limit = 50
    while(True):
    tracks = spotify.saved_tracks(limit=50, offset=offset)
    tracks = spotify.saved_tracks(limit=limit, offset=offset)
    if(len(tracks.items) == 0):
    break;
    saved_tracks.extend(tracks.items)
    if(len(tracks.items) < 20):
    if(len(tracks.items) < offset):
    break
    offset += 20
    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),) * 50):
    for chunk in zip(*(iter(saved_track_ids),) * limit):
    try:
    spotify.saved_tracks_add(track_ids=chunk)
    except Exception as e:
  2. jmeridth revised this gist Jul 11, 2020. No changes.
  3. jmeridth created this gist Jul 11, 2020.
    3 changes: 3 additions & 0 deletions .env.template
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    CLIENT_ID=PUT_CLIENT_ID_HERE
    CLIENT_SECRET=PUT_CLIENT_SECRET_HERE
    REDIRECT_URI=PUT_REDIRECT_URI_HERE
    36 changes: 36 additions & 0 deletions move_saved_songs_from_one_account_to_another.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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=50, offset=offset)
    if(len(tracks.items) == 0):
    break;
    saved_tracks.extend(tracks.items)
    if(len(tracks.items) < 20):
    break
    offset += 20

    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),) * 50):
    try:
    spotify.saved_tracks_add(track_ids=chunk)
    except Exception as e:
    print(e)

    print('done adding saved songs to new account')
    7 changes: 7 additions & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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
    8 changes: 8 additions & 0 deletions run_all_the_things.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #!/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