Created
May 6, 2016 21:32
-
-
Save devStepsize/99d15eadde78fff67b959a2679d51c21 to your computer and use it in GitHub Desktop.
Get all tracks for a given album_id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
spotify_endpoint = "https://api.spotify.com/v1/" | |
def get_tracks(album_id): | |
tracks = [] | |
url = spotify_endpoint + 'albums/%s/tracks' % album_id | |
while url: | |
try: | |
r = requests.get(url).json() | |
tracks += r.get('items', []) | |
url = r.get('next') | |
except requests.exceptions.RequestException as e: | |
print e | |
return tracks | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment