first commit
This commit is contained in:
commit
f2db1af089
9 changed files with 270 additions and 0 deletions
33
spotify.py
Normal file
33
spotify.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue