def alexa_continue_show(slots): card_title = 'Playing the next unwatched episode of the last show watched' print card_title sys.stdout.flush() last_show_obj = kodi.GetLastWatchedShow() try: last_show_id = last_show_obj['result']['episodes'][0]['tvshowid'] next_episode_id = kodi.GetNextUnwatchedEpisode(last_show_id) if next_episode_id: episode_details = kodi.GetEpisodeDetails(next_episode_id) if episode_details['resume']['position'] > 0: action = 'Resuming' else: action = 'Playing' kodi.PlayEpisode(next_episode_id) return build_alexa_response( '%s season %d episode %d of %s' % (action, episode_details['season'], episode_details['episode'], last_show_obj['result']['episodes'][0]['showtitle']), card_title) else: return build_alexa_response( 'No new episodes for %s' % last_show_obj['result']['episodes'][0]['showtitle'], card_title) except: return build_alexa_response('Error parsing results', card_title)
def alexa_play_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) card_title = 'Playing an episode of %s' % (heard_show) print card_title sys.stdout.flush() shows = kodi.GetTvShows() if 'result' in shows and 'tvshows' in shows['result']: shows_array = shows['result']['tvshows'] heard_season = slots['Season']['value'] heard_episode = slots['Episode']['value'] located = kodi.matchHeard(heard_show, shows_array) if located: episode_id = kodi.GetSpecificEpisode(located['tvshowid'], heard_season, heard_episode) if episode_id: if kodi.GetEpisodeDetails(episode_id)['resume']['position'] > 0: action = 'Resuming' else: action = 'Playing' kodi.PlayEpisode(episode_id) return build_alexa_response('%s season %s episode %s of %s' % (action, heard_season, heard_episode, heard_show), card_title) else: return build_alexa_response('Could not find season %s episode %s of %s' % (heard_season, heard_episode, heard_show), card_title) else: return build_alexa_response('Could not find a show named %s' % (heard_show), card_title) else: return build_alexa_response('Error parsing results', card_title)
def alexa_play_newest_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) card_title = 'Playing the newest episode of %s' % (heard_show) print card_title sys.stdout.flush() shows = kodi.GetTvShows() if 'result' in shows and 'tvshows' in shows['result']: shows_array = shows['result']['tvshows'] located = kodi.matchHeard(heard_show, shows_array) if located: episode_id = kodi.GetNewestEpisodeFromShow(located['tvshowid']) if episode_id: episode_details = kodi.GetEpisodeDetails(episode_id) if episode_details['resume']['position'] > 0: action = 'Resuming' else: action = 'Playing' kodi.PlayEpisode(episode_id) return build_alexa_response('%s season %d episode %d of %s' % (action, episode_details['season'], episode_details['episode'], heard_show), card_title) else: return build_alexa_response('No new episodes for %s' % (heard_show), card_title) else: return build_alexa_response('Could not find %s' % (heard_show), card_title) else: return build_alexa_response('Error parsing results', card_title)
def alexa_play_random_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) card_title = 'Playing a random episode of %s' % (heard_show) print card_title sys.stdout.flush() shows = kodi.GetTvShows() if 'result' in shows and 'tvshows' in shows['result']: shows_array = shows['result']['tvshows'] located = kodi.matchHeard(heard_show, shows_array) if located: episodes_result = kodi.GetUnwatchedEpisodesFromShow(located['tvshowid']) if not 'episodes' in episodes_result['result']: # Fall back to all episodes if no unwatched available episodes_result = kodi.GetEpisodesFromShow(located['tvshowid']) episodes_array = [] for episode in episodes_result['result']['episodes']: episodes_array.append(episode['episodeid']) episode_id = random.choice(episodes_array) episode_details = kodi.GetEpisodeDetails(episode_id) kodi.PlayEpisode(episode_id, False) return build_alexa_response('Playing season %d episode %d of %s' % (episode_details['season'], episode_details['episode'], heard_show), card_title) else: return build_alexa_response('Could not find a show named %s' % (heard_show), card_title) else: return build_alexa_response('Error parsing results', card_title)