def get_tracks(sp: spotipy.client, playlist_uri_dict: dict, user: str, n_tracks: int = 5) -> dict: """Returns the information of `n_tracks` out of a particular playlist""" uri = playlist_uri_dict.get(user) playlist = sp.playlist(uri) tracks = playlist.get("tracks").get("items") tracks = [x.get("track").get("preview_url") for x in tracks] tracks = [x for x in tracks if x is not None] n_tracks = min(len(tracks), n_tracks) tracks = random.sample(tracks, n_tracks) return tracks
def getSpotifyPlaylist(sp: spotipy.client, playlistId: str) -> []: playlist = sp.playlist(playlistId) return playlist