-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPDFacade.py
97 lines (70 loc) · 1.83 KB
/
MPDFacade.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import mpd2 as mpd
class MPDFacade :
def __init__(self, send_message_function=None, host='localhost', port=6600):
self.__host = host
self.__port = port
self.__client = mpd.MPDClient()
self.__client.timeout = 10
def connect(self):
# TODO : exception handling
self.__client.connect(self.__host, self.__port)
####################################
# Getters
def currentSong(self) :
return self.__client.currentsong()
def status(self) :
return self.__client.status()
####################################
# Playback commands
def play(self):
self.__client.play()
def pause(self):
self.__client.pause()
def stop(self):
self.__client.stop()
def next(self):
self.__client.next()
def prev(self):
self.__client.previous()
def volumeUp(self):
st = self.__client.status()
curVolume = int(st['volume'])
curVolume += 5
if ( curVolume > 100 ) :
curVolume = 100
song = self.__client.setvol(curVolume)
def volumeDown(self):
st = self.__client.status()
curVolume = int(st['volume'])
curVolume -= 5
if ( curVolume < 0 ) :
curVolume = 0
song = self.__client.setvol(curVolume)
def setPos(self, pos) :
st = self.__client.status()
id = st['song']
p = 0
if 'time' in st :
length = int(st['time'].split(':')[1])
p = pos * length / 100
self.__client.seek(id, p)
def random(self, on) :
self.__client.random( 1 if on == "true" else 0 )
####################################
# Outputs
def outputs(self) :
res = self.__client.outputs()
return res
def enableOutput(self, index, enable) :
if enable :
self.__client.enableoutput(index)
else:
self.__client.disableoutput(index)
####################################
# Playlist
def playlist(self) :
list = self.__client.playlistid()
return list
def playSong(self, id) :
self.__client.playid(id)