-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathspotify.py
36 lines (27 loc) · 1.16 KB
/
spotify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
GET_ARTIST_ENDPOINT = 'https://api.spotify.com/v1/artists/{id}'
SEARCH_ENDPOINT = 'https://api.spotify.com/v1/search'
RELATED_ARTISTS_ENDPOINT = 'https://api.spotify.com/v1/artists/{id}/related-artists'
TOP_TRACKS_ENDPOINT = 'https://api.spotify.com/v1/artists/{id}/top-tracks'
# https://developer.spotify.com/web-api/get-artist/
def get_artist(artist_id):
url = GET_ARTIST_ENDPOINT.format(id=artist_id)
resp = requests.get(url)
return resp.json()
# https://developer.spotify.com/web-api/search-item/
def search_by_artist_name(name):
myparams = {'type': 'artist'}
myparams['q'] = name
resp = requests.get(SEARCH_ENDPOINT, params=myparams)
return resp.json()
# https://developer.spotify.com/web-api/get-related-artists/
def get_related_artists(artist_id):
url = RELATED_ARTISTS_ENDPOINT.format(id=artist_id)
resp = requests.get(url)
return resp.json()
# https://developer.spotify.com/web-api/get-artists-top-tracks/
def get_artist_top_tracks(artist_id, country='US'):
url = TOP_TRACKS_ENDPOINT.format(id=artist_id)
myparams = {'country': country}
resp = requests.get(url, params=myparams)
return resp.json()