From 92090512d05161c000d40b6f7f284aeba920ab06 Mon Sep 17 00:00:00 2001 From: yiannisha Date: Thu, 21 Oct 2021 23:15:09 +0300 Subject: [PATCH] Added get_artist_albums Added the get_artist_albums(access_token, artist_id) function that returns a list of tuples that each contain the name and the id of an album. --- zspotify.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zspotify.py b/zspotify.py index 89d36b99..820ec1ed 100755 --- a/zspotify.py +++ b/zspotify.py @@ -508,6 +508,16 @@ def get_album_name(access_token, album_id): f'https://api.spotify.com/v1/albums/{album_id}', headers=headers).json() return resp['artists'][0]['name'], sanitize_data(resp['name']) +# Extra functions directly related to spotify artists +def get_artist_albums(access_token, artist_id): + """ Returns artist's albums """ + headers = {'Authorization': f'Bearer {access_token}'} + resp = requests.get( + f'https://api.spotify.com/v1/artists/{artist_id}/albums', headers=headers).json() + # Return a list of tuples that contain each album's name and id + return [(resp['items'][i]['name'], resp['items'][i]['id']) + for i in range(len(resp['items']))] + # Extra functions directly related to our saved tracks def get_saved_tracks(access_token): """ Returns user's saved tracks """