-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify.py
54 lines (32 loc) · 987 Bytes
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
#from Foundation import *
from ScriptingBridge import SBApplication
class Spotify(object):
PLAYING = 1800426320
PAUSED = 1800426352
def __init__(self):
self.client = SBApplication.applicationWithBundleIdentifier_("com.spotify.client")
def play_uri(self, uri):
print "Playing", uri
self.pause()
self.client.setRepeating_(False)
self.client.setShuffling_(False)
self.client.playTrack_inContext_(uri, uri)
self.play()
def pause(self):
self.client.pause()
def play(self):
self.client.play()
def toggle(self):
self.client.playpause()
@property
def state(self):
return self.client.playerState()
def next(self):
self.client.nextTrack()
def previous(self):
self.client.previousTrack()
class Album(object):
def __init__(self, uri):
self.uri = uri
self.id = uri.split(":")[-1]