diff --git a/plugins/speechhandler/mpdcontrol/mpdclient.py b/plugins/speechhandler/mpdcontrol/mpdclient.py index c796bf546..9f77b4f5b 100644 --- a/plugins/speechhandler/mpdcontrol/mpdclient.py +++ b/plugins/speechhandler/mpdcontrol/mpdclient.py @@ -53,6 +53,12 @@ def connection(self): except Exception: pass + def find_podcasts(self, text): + with self.connection() as conn: + self._podcasts = conn.search('Album',text) + return self._podcasts + + def get_playlists(self): if self._playlists is not None: return self._playlists @@ -95,13 +101,8 @@ def get_playback_state(self): raise RuntimeError('Unknown playback state!') def play(self): - state = self.get_playback_state() - if state == PLAYBACK_STATE_STOPPED: - with self.connection() as conn: - conn.play() - elif state == PLAYBACK_STATE_PAUSED: - with self.connection() as conn: - conn.pause(0) + with self.connection() as conn: + conn.play() def pause(self): state = self.get_playback_state() @@ -128,6 +129,12 @@ def load_playlist(self, playlist): conn.clear() conn.load(playlist) + def load_podcast(self, podcast): + with self.connection() as conn: + conn.clear() + conn.add(podcast['file']) + print conn.playlist() + def volume(self, volume, relative=False): with self.connection() as conn: if relative: diff --git a/plugins/speechhandler/mpdcontrol/mpdcontrol.py b/plugins/speechhandler/mpdcontrol/mpdcontrol.py index 5777af28f..4824dd7da 100644 --- a/plugins/speechhandler/mpdcontrol/mpdcontrol.py +++ b/plugins/speechhandler/mpdcontrol/mpdcontrol.py @@ -2,7 +2,7 @@ import difflib import logging from jasper import plugin -from . import mpdclient +import mpdclient class MPDControlPlugin(plugin.SpeechHandlerPlugin): @@ -28,7 +28,7 @@ def __init__(self, *args, **kwargs): self._music = mpdclient.MPDClient(server=server, port=port) def get_phrases(self): - return [self.gettext('MUSIC'), self.gettext('SPOTIFY')] + return [self.gettext('RADIO'), self.gettext('TUNEIN'), self.gettext('PODCAST')] def handle(self, text, mic): """ @@ -48,11 +48,13 @@ def handle(self, text, mic): _('NEXT'), _('PREVIOUS'), _('LOUDER'), _('SOFTER'), _('PLAYLIST'), + _('PODCAST'), + _('RADIO'), _('CLOSE'), _('EXIT') ] - self._logger.debug('Loading playlists...') - phrases.extend([pl.upper() for pl in self._music.get_playlists()]) +# self._logger.debug('Loading playlists...') +# phrases.extend([pl.upper() for pl in self._music.get_playlists()]) self._logger.debug('Starting music mode...') with mic.special_mode('music', phrases): @@ -108,6 +110,28 @@ def handle_music_command(self, command, mic): self._music.play() else: mic.say(_("Sorry, I can't find a playlist with that name.")) + elif _('PODCAST').upper() in command: + self._music.stop() + text = command.replace(_('PLAY'), '').replace(_('PODCAST'), '').strip() + podcasts = self._music.find_podcasts(text) + print podcasts + podcasts_upper = [pc['title'].upper() for pc in podcasts] + matches = difflib.get_close_matches(text, podcasts_upper) + if len(matches) > 0: + podcast_index = podcasts_upper.index(matches[0]) + podcast = podcasts[podcast_index] + else: + podcast = None + + #Load podcast + if podcast: + playback_state = self._music.get_playback_state() + self._music.load_podcast(podcast) + mic.say(_('Podcast %s loaded.') % podcast['title']) + self._music.play() + else: + mic.say(_("Sorry, I can't find a podcast with that name.")) + elif _('STOP').upper() in command: self._music.stop() mic.say(_('Music stopped.')) diff --git a/plugins/speechhandler/mpdcontrol/plugin.info b/plugins/speechhandler/mpdcontrol/plugin.info index 33471986c..112000f81 100644 --- a/plugins/speechhandler/mpdcontrol/plugin.info +++ b/plugins/speechhandler/mpdcontrol/plugin.info @@ -1,10 +1,13 @@ [Plugin] Name = mpdcontrol -Version = 1.0.0 +Version = 1.0.1 License = MIT URL = http://jasperproject.github.io/ Description = Control your MPD server and listen to music [Author] Name = Jasper Project -URL = http://jasperproject.github.io/ \ No newline at end of file +URL = http://jasperproject.github.io/ + +Name = gglass +URL = https://github.com/gglass/jasper-client