The function:
def get_album_tracks(sp, album_id):
try:
album_tracks = sp.album_tracks(album_id)
tracks = album_tracks["items"]
# Create a list to hold track details
track_details = []
for track in tracks:
track_info = {
"track_name": track["name"],
"track_id": track["id"],
"artists": [artist["name"] for artist in track["artists"]],
}
track_details.append(track_info)
return track_details
except SpotifyException as e:
print(f"Spotify API error {e.code}: {e.msg}")
return None
I call the function with the album_id of selected ambient works from Aphex Twin
album_tracks = get_album_tracks(sp, "7aNclGRxTysfh6z0d8671k")
print(album_tracks)
I tried to catch errors but it does not print out errors.
The search_album
function works great.
You missing tracks['items']
This is demo code
This is result
You can use Web API directly instead of using 'spotipy'
result