+ def _hello(self, rcv):
+ """Consume HELLO_PREFIX"""
+
+ if rcv.startswith(HELLO_PREFIX):
+ self.sess.version = rcv.split('\n')[0][len(HELLO_PREFIX):]
+ #print('consumed hello prefix: %s' % self.sess.version)
+ return rcv[rcv.find('\n')+1:]
+ return rcv
+
+class MPDClient:
+ loop = asyncio.get_event_loop()
+
+ def __init__(self, host='localhost', port=6600, cred=None):
+ self._host = host
+ self._port = port
+ self._cred = cred
+ self._commands = {
+ 'currentsong',
+ 'stats',
+ 'playlistinfo',
+ }
+
+ def __getattr__(self, attr):
+ command = attr
+ wrapper = self._command
+ if command not in self._commands:
+ command = command.replace("_", " ")
+ if command not in self._commands:
+ raise AttributeError("'%s' object has no attribute '%s'" %
+ (self.__class__.__name__, attr))
+ return lambda *args: wrapper(command, args)
+
+ def _command(self, command, args):
+ payload = '{} {}'.format(command ,''.join(args))
+ future = asyncio.Future()