33 lines
962 B
Python
33 lines
962 B
Python
import spotipy
|
|
from spotipy.oauth2 import SpotifyOAuth
|
|
|
|
def spotify_client():
|
|
return spotipy.Spotify(auth_manager=SpotifyOAuth(
|
|
scope="user-library-read playlist-read-private playlist-read-collaborative"
|
|
))
|
|
|
|
def get_playlists(sp):
|
|
return sp.current_user_playlists(limit=50)["items"]
|
|
|
|
def get_playlist_tracks(sp, playlist_id):
|
|
tracks = []
|
|
results = sp.playlist_items(playlist_id, additional_types=["track"])
|
|
while results:
|
|
for item in results["items"]:
|
|
if item["track"]:
|
|
tracks.append(item["track"])
|
|
results = sp.next(results) if results["next"] else None
|
|
return tracks
|
|
|
|
|
|
def get_liked_tracks(sp):
|
|
tracks = []
|
|
results = sp.current_user_saved_tracks(limit=50)
|
|
|
|
while results:
|
|
for item in results["items"]:
|
|
if item["track"]:
|
|
tracks.append(item["track"])
|
|
results = sp.next(results) if results["next"] else None
|
|
|
|
return tracks
|