Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
June Updates
Browse files Browse the repository at this point in the history
Podcast commands:
+ Add support for "play <podcast name> podcast" variation of command.
* Resolve incorrect detection of empty feeds.
* Resolve handling of "&" in podcast or episode name.

Kodi commands:
+ Add "update tv shows" command to scan for new episodes.

Power commands:
* Improve command detection method

MPD connection:
* Handle timeout of MPD connection, when MPD is not used.
  • Loading branch information
mpember authored and Michael Pemberton committed Jun 10, 2018
1 parent 83f9f36 commit 94279e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ def process_event(assistant, event):
if _music.getConfirmPlayback() == True:
assistant.start_conversation()

elif text.startswith('play ') and text.endswith(' podcast'):
assistant.stop_conversation()
_music.run('podcast', text[5:][:-8])
if _music.getConfirmPlayback() == True:
assistant.start_conversation()

elif text.startswith('radio '):
assistant.stop_conversation()
_music.run('radio', text[6:])
Expand Down
2 changes: 1 addition & 1 deletion src/modules/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run(self, voice_command):
result = self.kodi.Player.Stop(playerid=1)
logging.info('Kodi response: ' + str(result))

elif voice_command in ['play','pause','paws','resume']:
elif voice_command == 'play' or voice_command == 'pause' or voice_command == 'paws' or voice_command == 'resume':
result = self.kodi.Player.PlayPause(playerid=1)
logging.info('Kodi response: ' + str(result))

Expand Down
26 changes: 20 additions & 6 deletions src/modules/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ def run(self, module, voice_command):
logging.info('Music stopped playing')
self.mpd.clear()

self.mpd.close()
self.mpd.disconnect()
try:
self.mpd.close()
self.mpd.disconnect()
except ConnectionError:
logging.info('MPD connection timed out')
pass

def playRadio(self, station):
config = configparser.ConfigParser()
Expand Down Expand Up @@ -112,7 +116,8 @@ def playPodcast(self, podcast):
aiy.audio.say('Recent podcasts are')
for title,url in podcasts.items():
podcastInfo = self.getPodcastItem(podcast, url, offset)
aiy.audio.say(title + ' uploaded an episode ' + str(int(podcastInfo['age']/24)) + ' days ago')
if not podcastInfo == None:
aiy.audio.say(title + ' uploaded an episode ' + str(int(podcastInfo['age']/24)) + ' days ago')
return

elif podcast == 'today':
Expand All @@ -121,6 +126,15 @@ def playPodcast(self, podcast):
podcastInfo = self.getPodcastItem(podcast, url, offset)
if podcastInfo['age'] < 36:
aiy.audio.say(title + ' uploaded an episode ' + str(int(podcastInfo['age'])) + ' hours ago')
self._cancelAction = True
return

elif podcast == 'yesterday':
aiy.audio.say('Yesterday\'s podcasts are')
for title,url in podcasts.items():
podcastInfo = self.getPodcastItem(podcast, url, offset)
if podcastInfo['age'] < 60 and podcastInfo['age'] > 36:
aiy.audio.say(title + ' uploaded an episode ' + str(int(podcastInfo['age'])) + ' hours ago')
return

elif podcast.startswith('previous '):
Expand Down Expand Up @@ -176,20 +190,20 @@ def getPodcastItem(self, podcast, src, offset):
logging.info('feed contains ' + str(resCount) + ' items')

# exit out if empty
if resCount < offset or resCount == 0:
if not resCount > offset:
logging.info(podcast + ' podcast feed is empty')
aiy.audio.say('There are no episodes available of ' + podcast)
return None

if 'title' in rss.feed:
result['title'] = rss.feed.title
result['title'] = rss.feed.title.replace(" & ", " and ")

rssItem = rss.entries[offset]

# Extract infromation about requested item

if 'title' in rssItem:
result['ep_title'] = rssItem.title
result['ep_title'] = rssItem.title.replace(" & ", " and ")

if 'published_parsed' in rssItem:
result['age'] = int((time.time() - time.mktime(rssItem['published_parsed'])) / 3600)
Expand Down

0 comments on commit 94279e0

Please sign in to comment.