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.
This commit is contained in:
yiannisha 2021-10-21 23:15:09 +03:00
parent 822b696dc4
commit 92090512d0

View File

@ -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 """