-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.py
More file actions
25 lines (19 loc) · 704 Bytes
/
Copy pathfetch.py
File metadata and controls
25 lines (19 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from auth import authenticate_spotify
def get_user_playlists():
"""Fetch all playlists in the user's Spotify library."""
sp = authenticate_spotify()
playlists = {}
results = sp.current_user_playlists()
for playlist in results['items']:
playlists[playlist['id']] = playlist['name']
return playlists
def get_playlist_tracks(playlist_id):
"""Fetch all track names from a given playlist ID."""
sp = authenticate_spotify()
tracks = []
results = sp.playlist_tracks(playlist_id)
for item in results['items']:
track = item['track']
if track:
tracks.append(f"{track['name']} - {track['artists'][0]['name']}")
return tracks