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

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mpember committed Jun 10, 2018
1 parent 45a0600 commit 4030386
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 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
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 4030386

Please sign in to comment.