Created
June 17, 2025 21:30
-
-
Save MrCheatEugene/2b590861c6ec5e0ee45a922261240c92 to your computer and use it in GitHub Desktop.
Sync Liked Songs with a public playlist
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 spotipy | |
from spotipy.oauth2 import SpotifyOAuth | |
def process_results(r): sp.playlist_add_items('PLAYLIST_ID', items=[x['track']['uri'] for x in r['items']]) | |
scope = "user-library-read playlist-modify-private playlist-modify-public" | |
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope, client_id="", client_secret="", redirect_uri="http://example.org")) | |
limit = 50 | |
results = sp.current_user_saved_tracks(limit=limit) | |
offset = 0 | |
dobreak = False | |
while results['total'] > offset and not dobreak: | |
process_results(sp.current_user_saved_tracks(limit=limit, offset=offset)) | |
offset = offset+limit if results['total'] > offset+limit else results['total']-offset | |
dobreak = False if results['total'] > offset+limit else True | |
print(f"Offset {offset}") | |
process_results(sp.current_user_saved_tracks(limit=limit, offset=offset)) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment