Created
May 28, 2019 02:38
-
-
Save portothree/ba0955e08d1469440713c016442fa410 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 | |
import pprint | |
pp = pprint.PrettyPrinter(indent=4) | |
headers = {'Authorization': 'Bearer '} | |
playlistID = '76BJ3Y6aE7TR0hW5QCop5n' | |
userInfo = 'https://api.spotify.com/v1/playlists/{}'.format(playlistID) | |
endpoint = 'https://api.spotify.com/v1/playlists/{}/tracks?offset=0&limit=200'.format(playlistID) | |
r_userInfo = requests.get(userInfo, headers=headers).json() | |
userName = r_userInfo['owner']['display_name'] | |
totalTracks = r_userInfo['tracks']['total'] | |
data = requests.get(endpoint, headers=headers) | |
binary = data.content | |
output = json.loads(binary) | |
trackInfo = output['items'] | |
fullPlaylist = [] | |
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) | |
fullPlaylist.append(musicTitle) | |
pp.pprint(fullPlaylist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment