Skip to content

Instantly share code, notes, and snippets.

@spencerkittleson
Created May 17, 2023 22:05
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 spencerkittleson/97b595ad841ff61df396118a0bdc853e to your computer and use it in GitHub Desktop.
Save spencerkittleson/97b595ad841ff61df396118a0bdc853e to your computer and use it in GitHub Desktop.
Python Spotify Playlist User Retrieval
from simple_http_server import route, server
from threading import Thread
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import os
from simple_http_server import route, server
@route("/")
def index():
print("redirect was successful")
return {"hello": "world"}
def startServer():
server.start(port=8888)
if __name__ == "__main__":
os.environ["SPOTIPY_REDIRECT_URI"] = 'http://localhost:8888'
(Thread(target=startServer)).start()
scope = "user-library-read"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
server.stop()
more = True
offset = 0
while more:
results = sp.current_user_saved_tracks(limit=50, offset=offset)
if len(results) <= 0:
more = False
continue
offset += 50
for idx, item in enumerate(results['items']):
track = item['track']
print(idx, track['artists'][0]['name'], " – ", track['name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment