Skip to content

Instantly share code, notes, and snippets.

@portothree
Created May 28, 2019 02:38
Show Gist options
  • Save portothree/ba0955e08d1469440713c016442fa410 to your computer and use it in GitHub Desktop.
Save portothree/ba0955e08d1469440713c016442fa410 to your computer and use it in GitHub Desktop.
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