3 class MPDError(Exception):
5 class ConnectionError(MPDError
):
7 class ProtocolError(MPDError
):
9 class CommandError(MPDError
):
11 class CommandListError(MPDError
):
22 def connect(self
, host
, port
, type=socket
.SOCK_STREAM
):
24 raise ConnectionError("Already connected")
26 self
._csock
=socket
.socket(socket
.AF_INET
, type)
27 self
._csock
.connect((host
, port
))
28 self
._file
= self
._csock
.makefile("rwb")
29 handshake
=self
._read
()
30 if handshake
[0:len("hello jmpd")]!="hello jmpd":
31 print("Failed to handshake: %s" % (handshake
))
38 return self
._file
.readline().strip()
39 def _write(self
, line
):
40 self
._file
.write("%s\n" % (line
))
46 def command_list_ok_begin(self
):
49 def command_list_end(self
):
83 def setvol(newvolume
):
87 def listallinfo(self
):
89 def listplaylistinfo(self
):
91 def currentsong(self
):
97 client
.connect('localhost', port
)