-
Notifications
You must be signed in to change notification settings - Fork 6
/
artist.py
45 lines (29 loc) · 1002 Bytes
/
artist.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
35
36
37
38
39
40
41
42
43
44
45
from spotify.client import Spotify
import logging
import os
log = logging.getLogger(__name__)
class App(object):
artist_uri = 'spotify:artist:4tZwfgrHOc3mvqYlEYSvVi' # Daft Punk
def __init__(self):
self.sp = Spotify()
self.tracks = None
self.album = None
def run(self):
@self.sp.login(os.environ['USERNAME'], os.environ['PASSWORD'])
def on_login():
# Fetch metadata for album
self.sp.metadata(self.artist_uri, self.on_artist)
def on_artist(self, artist):
self.sp.metadata(artist.albums[0].uri, self.on_album)
def on_album(self, album):
print album.name
self.sp.metadata([tr.uri for tr in album.tracks], self.on_tracks)
def on_tracks(self, tracks):
for track in tracks:
print '\t[%s] - %s' % (track.uri, track.name)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
app = App()
app.run()
while True:
raw_input()