2017-11-03 04:08:47 +01:00
|
|
|
import mpd
|
|
|
|
|
2017-12-13 04:21:26 +01:00
|
|
|
from platypush.message.response import Response
|
2017-12-13 03:37:28 +01:00
|
|
|
|
2017-11-03 04:08:47 +01:00
|
|
|
from .. import MusicPlugin
|
|
|
|
|
|
|
|
class MusicMpdPlugin(MusicPlugin):
|
|
|
|
def _init(self):
|
|
|
|
self.client = mpd.MPDClient(use_unicode=True)
|
|
|
|
self.client.connect(self.config['host'], self.config['port'])
|
|
|
|
|
2017-12-13 03:37:28 +01:00
|
|
|
def _exec(self, method, *args, **kwargs):
|
|
|
|
getattr(self.client, method)(*args, **kwargs)
|
|
|
|
return self.status()
|
|
|
|
|
2017-11-03 04:08:47 +01:00
|
|
|
def play(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('play')
|
2017-11-03 04:08:47 +01:00
|
|
|
|
|
|
|
def pause(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('pause')
|
2017-11-03 04:08:47 +01:00
|
|
|
|
|
|
|
def stop(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('stop')
|
2017-11-03 04:08:47 +01:00
|
|
|
|
2017-11-03 15:06:29 +01:00
|
|
|
def next(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('next')
|
2017-11-03 15:06:29 +01:00
|
|
|
|
|
|
|
def previous(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('previous')
|
2017-11-03 15:06:29 +01:00
|
|
|
|
|
|
|
def setvol(self, vol):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('setvol', vol)
|
2017-11-03 15:06:29 +01:00
|
|
|
|
|
|
|
def add(self, content):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('add', content)
|
2017-11-03 15:06:29 +01:00
|
|
|
|
|
|
|
def playlistadd(self, playlist):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('playlistadd', playlist)
|
2017-11-03 15:06:29 +01:00
|
|
|
|
|
|
|
def clear(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return self._exec('clear')
|
2017-11-03 15:06:29 +01:00
|
|
|
|
2017-11-03 04:08:47 +01:00
|
|
|
def status(self):
|
2017-12-13 03:37:28 +01:00
|
|
|
return Response(output=self.client.status())
|
2017-11-03 04:08:47 +01:00
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|
|
|
|
|