from os import environ
if 'DEBUG' in environ or 'PYTHONASYNCIODEBUG' in environ:
+ # environ['PYTHONASYNCIODEBUG'] = '1'
logging.basicConfig(level=logging.DEBUG)
HELLO_PREFIX = "OK MPD "
class CommandError(MPDError):
pass
-class CommandListError(MPDError):
- pass
-
-class PendingCommandError(MPDError):
- pass
-
-class IteratingError(MPDError):
- pass
-
class Response:
def __init__(self):
self.version)
class MPDProto(asyncio.Protocol):
- def __init__(self, future, payload, pwd):
- self.pwd = pwd
+ def __init__(self, future, payload):
+ logging.debug('payload: "%s"', payload)
self.transport = None
self.future = future
self.payload = payload
return rcv
class MPDClient:
+ """MPD Client
+ :param string host: Server name or IP, default to 'localhost'
+ :param integer port: Server port, default to 6600
+ :param string passwd: Password, default to ``None``
+
+ """
def __init__(self, host='localhost', port=6600, passwd=None):
self._evloop = asyncio.get_event_loop()
self.futures = []
self._host = host
self._port = port
- self._pwd = passwd
+ #self._pwd = passwd # TODO: authentication yet to implement
self._commands = {
'currentsong',
'stats',
'playlistinfo',
+ 'next',
+ 'find',
}
def __getattr__(self, attr):
proto.future.set_exception(ConnectionError(err))
def _command(self, command, args):
- payload = '{} {}'.format(command, ''.join(args))
+ payload = command
+ for arg in args:
+ payload += ' "{}"'.format(escape(arg))
future = asyncio.Future()
# kick off a task to create the connection to MPD
- coro = self._connect(MPDProto(future, payload, self._pwd))
+ coro = self._connect(MPDProto(future, payload))
asyncio.async(coro)
self.futures.append(future)
if not self.asio:
self.futures = []
else:
logging.info('No task found in queue, need to set self.asio?')
+
+
+def escape(text):
+ """Escapting quotes and backslash"""
+ return text.replace('\\', '\\\\').replace('"', '\\"')
+