Created
May 26, 2019 00:57
-
-
Save portothree/87711455c0ed02ab1c69790befc8d3bd to your computer and use it in GitHub Desktop.
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 | |
import json | |
headers = {'Authorization': 'Bearer '} | |
playlistID = '76BJ3Y6aE7TR0hW5QCop5n' | |
userInfo = 'https://api.spotify.com/v1/playlists/{}'.format(playlistID) | |
endpoint_100 = 'https://api.spotify.com/v1/playlists/{}/tracks?offset=0&limit=100'.format(playlistID) | |
endpoint_200 = 'https://api.spotify.com/v1/playlists/{}/tracks?offset=100&limit=100'.format(playlistID) | |
endpoint_300 = 'https://api.spotify.com/v1/playlists/{}/tracks?offset=200&limit=100'.format(playlistID) | |
endpoint_400 = 'https://api.spotify.com/v1/playlists/{}/tracks?offset=300&limit=100'.format(playlistID) | |
r_userInfo = requests.get(userInfo, headers=headers).json() | |
userName = r_userInfo['owner']['display_name'] | |
totalTracks = r_userInfo['tracks']['total'] | |
fullPlaylist = [] | |
if totalTracks < 100: | |
r_endpoint_100 = requests.get(endpoint_100, headers=headers).json() | |
ate100 = True | |
ate200 = False | |
ate300 = False | |
ate400 = False | |
else: | |
r_endpoint_100 = requests.get(endpoint_100, headers=headers).json() | |
r_endpoint_200 = requests.get(endpoint_200, headers=headers).json() | |
ate100 = False | |
ate200 = True | |
ate300 = False | |
ate400 = False | |
if totalTracks < 300: | |
r_endpoint_300 = requests.get(endpoint_300, headers=headers).json() | |
ate100 = False | |
ate200 = False | |
ate300 = True | |
ate400 = False | |
else: | |
r_endpoint_300 = requests.get(endpoint_300, headers=headers).json() | |
r_endpoint_400 = requests.get(endpoint_400, headers=headers).json() | |
ate100 = False | |
ate200 = False | |
ate300 = False | |
ate400 = True | |
if ate100 == True: | |
data = requests.get(r_endpoint_100, headers=headers) | |
binary = data.content | |
output = json.loads(binary) | |
trackInfo = output['items'] | |
for track in trackInfo: | |
artistsNames = track['track']['artists'] | |
trackName = track['track']['name'] | |
artistss = [] | |
for artists in artistsNames: | |
artistss.append(artists['name']) | |
musicTitle = str(artistss) + ' ' +str(trackName) | |
print(musicTitle) | |
else: | |
pass | |
if ate200 == True: | |
data = requests.get(r_endpoint_200, headers=headers) | |
binary = data.content | |
output = json.loads(binary) | |
trackInfo = output['items'] | |
for track in trackInfo: | |
artistsNames = track['track']['artists'] | |
trackName = track['track']['name'] | |
artistss = [] | |
for artists in artistsNames: | |
artistss.append(artists['name']) | |
musicTitle = str(artistss) + ' ' +str(trackName) | |
print(musicTitle) | |
else: | |
pass | |
print(fullPlaylist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment