-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathitunes.py
68 lines (42 loc) · 1.92 KB
/
itunes.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import dacp
class ITunesController(dacp.DACPTouchableConnection):
def __init__(self, **kwargs):
dacp.DACPTouchableConnection.__init__(self, **kwargs)
self._cmsr = 1
def play_pause(self):
self.send_cmd('/ctrl-int/1/playpause')
def next_item(self):
self.send_cmd('/ctrl-int/1/nextitem')
def prev_item(self):
self.send_cmd('/ctrl-int/1/previtem')
def shuffle(self, value=None):
if not value:
d = dacp.Parser(list(self.send_cmd('/ctrl-int/1/getproperty', {'properties': 'dacp.shufflestate'})))
return d.int('cash')
if 0 <= value <= 1:
self.send_cmd('/ctrl-int/1/setproperty', {'dacp.shufflestate': value})
def repeat(self, value=None):
if not value:
d = dacp.Parser(list(self.send_cmd('/ctrl-int/1/getproperty', {'properties': 'dacp.repeatstate'})))
return d.int('carp')
if 0 <= value <= 2:
self.send_cmd('/ctrl-int/1/setproperty', {'dacp.repeatstate': value})
def volume(self, value=None):
if not value:
d = dacp.Parser(list(self.send_cmd('/ctrl-int/1/getproperty', {'properties': 'dmcp.volume'})))
return d.int('cmvo')
if 0.0 <= value <= 100.0:
self.send_cmd('/ctrl-int/1/setproperty?dmcp.volume', {'dmcp.volume': value})
def artwork(self, min_w, min_h):
return self.send_cmd('/ctrl-int/1/nowplayingartwork', {'mw': min_w, 'mh': min_h})
def status(self, **kwargs):
if kwargs.get('wait', False):
rev = self._cmsr
else:
rev = 1
d = dacp.Parser(self.send_cmd('/ctrl-int/1/playstatusupdate', {'revision-number': rev}))
self._cmsr = d.int('cmsr')
return d
@property
def revision_number(self):
return self._cmsr