Skip to content

Instantly share code, notes, and snippets.

@MartinWeiss12
Last active January 4, 2024 05:10
Show Gist options
  • Save MartinWeiss12/2f7dc13605ca6414f9edc0a01decd6d7 to your computer and use it in GitHub Desktop.
Save MartinWeiss12/2f7dc13605ca6414f9edc0a01decd6d7 to your computer and use it in GitHub Desktop.
Get Artist Image URL With Spotify API
artistImageUrlList = []
print('Total artists streamed:', len(uniqueArtistUriList))
for uri in range(49):
spotifyUrl = requests.get('https://open.spotify.com/artist/' +
str(uniqueArtistUriList[uri]))
spoifyHtmlData = str(soup(spotifyUrl.text, 'html.parser'))
spoifyHtmlData = spoifyHtmlData.split('<')
artistName = spoifyHtmlData[5].split('>')
artistName = artistName[1].split('|')
artistApiResults = requests.get('https://api.spotify.com/v1/search',
headers={ 'authorization': 'Bearer ' + token},
params={ 'q': artistName[0], 'type': 'artist' })
artistSearchResults = str(soup(artistApiResults.text, 'html.parser'))
artistInfoJson = json.loads(artistSearchResults)
listFromDict = artistInfoJson['artists']['items']
artistImageUrl = listFromDict[0]['images'][0]['url']
for i in range(len(listFromDict)):
if(artistName[0].strip() == listFromDict[i]['name']):
artistImageUrlList.append(artistImageUrl)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment