From 951ea80bb468882796835f0756e271c21aff59a7 Mon Sep 17 00:00:00 2001 From: gglass Date: Mon, 15 Feb 2016 12:28:01 -0600 Subject: [PATCH 1/4] Update plugin.info --- plugins/speechhandler/mpdcontrol/plugin.info | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/speechhandler/mpdcontrol/plugin.info b/plugins/speechhandler/mpdcontrol/plugin.info index 33471986c..5f5f511c4 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.1.0 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 From 5102daed70d8d1366bdef2c5b7186d52233e2a02 Mon Sep 17 00:00:00 2001 From: gglass Date: Mon, 15 Feb 2016 12:28:10 -0600 Subject: [PATCH 2/4] Update plugin.info --- plugins/speechhandler/mpdcontrol/plugin.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/speechhandler/mpdcontrol/plugin.info b/plugins/speechhandler/mpdcontrol/plugin.info index 5f5f511c4..112000f81 100644 --- a/plugins/speechhandler/mpdcontrol/plugin.info +++ b/plugins/speechhandler/mpdcontrol/plugin.info @@ -1,6 +1,6 @@ [Plugin] Name = mpdcontrol -Version = 1.1.0 +Version = 1.0.1 License = MIT URL = http://jasperproject.github.io/ Description = Control your MPD server and listen to music From 5c53178c966e3dc52e0755dbbb94f1b73189af7c Mon Sep 17 00:00:00 2001 From: gglass Date: Mon, 15 Feb 2016 12:29:19 -0600 Subject: [PATCH 3/4] Adding tunein/itunespodcast support Adding podcast search/playback support --- plugins/speechhandler/mpdcontrol/mpdclient.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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: From cbc13d01f5151f394db5dc20d6acc2bd50c27226 Mon Sep 17 00:00:00 2001 From: gglass Date: Mon, 15 Feb 2016 12:31:43 -0600 Subject: [PATCH 4/4] Adding tuneinradio/itunespodcast support Adding search/playback for itunes podcast/tunineradio extensions --- .../speechhandler/mpdcontrol/mpdcontrol.py | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) 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.'))