Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added podcast/tunein radio support #451

Open
wants to merge 4 commits into
base: jasper-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions plugins/speechhandler/mpdcontrol/mpdclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down
32 changes: 28 additions & 4 deletions plugins/speechhandler/mpdcontrol/mpdcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import difflib
import logging
from jasper import plugin
from . import mpdclient
import mpdclient


class MPDControlPlugin(plugin.SpeechHandlerPlugin):
Expand All @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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.'))
Expand Down
7 changes: 5 additions & 2 deletions plugins/speechhandler/mpdcontrol/plugin.info
Original file line number Diff line number Diff line change
@@ -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/
URL = http://jasperproject.github.io/

Name = gglass
URL = https://github.com/gglass/jasper-client