initial commit

This commit is contained in:
2022-08-13 18:00:14 +02:00
commit 03151f246d
5 changed files with 310 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
auth_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(auth_manager=auth_manager)
def get_playlists_by_user(username: str) -> list:
def fetch_playlists(username: str, playlists: list = None, limit=50) -> list:
if playlists is None:
playlists = list()
batch = sp.user_playlists(username, limit=limit, offset=len(playlists))["items"]
new_playlists = playlists + batch
if len(batch) < limit:
return new_playlists
return fetch_playlists(username, new_playlists)
return fetch_playlists(username)
def get_playlist_info(playlist_uri: str) -> dict:
# extract id from uri and remove query parameters
playlist_id = playlist_uri.split('/')[-1].split('?')[0]
return sp.playlist(playlist_id)