def alexa_play_album(slots): heard_album = str(slots['Album']['value']).lower().translate(None, string.punctuation) if 'value' in slots['Artist']: heard_artist = str(slots['Artist']['value']).lower().translate(None, string.punctuation) card_title = 'Playing %s by %s' % (heard_album, heard_artist) else: card_title = 'Playing %s' % (heard_album) print card_title sys.stdout.flush() if 'value' in slots['Artist']: artists = kodi.GetMusicArtists() if 'result' in artists and 'artists' in artists['result']: artists_list = artists['result']['artists'] located = kodi.matchHeard(heard_artist, artists_list, 'artist') if located: albums = kodi.GetArtistAlbums(located['artistid']) if 'result' in albums and 'albums' in albums['result']: albums_list = albums['result']['albums'] album_located = kodi.matchHeard(heard_album, albums_list, 'label') if album_located: album_result = album_located['albumid'] kodi.Stop() kodi.ClearPlaylist() kodi.AddAlbumToPlaylist(album_result) kodi.StartPlaylist() else: return build_alexa_response('Could not find %s by %s' % (heard_album, heard_artist), card_title) return build_alexa_response('Playing %s by %s' % (heard_album, heard_artist), card_title) else: return build_alexa_response('Could not find %s by %s' % (heard_album, heard_artist), card_title) else: return build_alexa_response('Could not find %s by %s' % (heard_album, heard_artist), card_title) else: return build_alexa_response('Could not find %s by %s' % (heard_artist), card_title) else: albums = kodi.GetAlbums() if 'result' in albums and 'albums' in albums['result']: albums_list = albums['result']['albums'] album_located = kodi.matchHeard(heard_album, albums_list, 'label') if album_located: album_result = album_located['albumid'] kodi.Stop() kodi.ClearPlaylist() kodi.AddAlbumToPlaylist(album_result) kodi.StartPlaylist() else: return build_alexa_response('Could not find %s' % (heard_album), card_title) return build_alexa_response('Playing %s' % (heard_album), card_title) else: return build_alexa_response('Could not find %s' % (heard_album), card_title)
def alexa_play_movie(slots): heard_movie = str(slots['Movie']['value']).lower().translate( None, string.punctuation) print('Trying to play the movie %s' % (heard_movie)) sys.stdout.flush() movies_response = kodi.GetMovies(kodi.remove_the(heard_movie)) if 'result' in movies_response and 'movies' in movies_response['result']: movies = movies_response['result']['movies'] located = kodi.matchHeard(heard_movie, movies) if located: kodi.ClearVideoPlaylist() kodi.PrepMoviePlaylist(located['movieid']) kodi.StartVideoPlaylist() return build_alexa_response('Playing %s' % (heard_movie)) else: return build_alexa_response('Could not find a movie called %s' % (heard_movie)) else: return build_alexa_response('Could not find a movie called %s' % (heard_movie))
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_result = kodi.GetSpecificEpisode(located['tvshowid'], heard_season, heard_episode) if episode_result: kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(episode_result) kodi.StartVideoPlaylist() return build_alexa_response('Playing season %s episode %s of %s' % (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_new_show_inquiry(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) card_title = "Looking for new episodes 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']: num_of_unwatched = 0 else: num_of_unwatched = len(episodes_result['result']['episodes']) if num_of_unwatched > 0: if num_of_unwatched == 1: return build_alexa_response("There is one unseen episode of %(real_show)s." % {'real_show': heard_show}, card_title) else: return build_alexa_response("There are %(num)d episodes of %(real_show)s." % {'real_show': heard_show, 'num': num_of_unwatched}, card_title) else: return build_alexa_response("There are no unseen episodes of %(real_show)s." % {'real_show': 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_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 = kodi.GetNewestEpisodeFromShow(located['tvshowid']) if episode: episode_details = kodi.GetEpisodeDetails(episode)['result']['episodedetails'] kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(episode) kodi.StartVideoPlaylist() 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('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_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_what_albums(slots): heard_artist = str(slots['Artist']['value']).lower().translate(None, string.punctuation) card_title = 'Albums by %s' % (heard_artist) print card_title sys.stdout.flush() artists = kodi.GetMusicArtists() if 'result' in artists and 'artists' in artists['result']: artists_list = artists['result']['artists'] located = kodi.matchHeard(heard_artist, artists_list, 'artist') if located: albums_result = kodi.GetArtistAlbums(located['artistid']) albums = albums_result['result']['albums'] num_albums = len(albums) if num_albums > 0: really_albums = list(set([sanitize_name(x['label']) for x in albums])) album_list = really_albums[0] if num_albums > 1: for one_album in really_albums[1:-1]: album_list += ", " + one_album album_list += ", and " + really_albums[-1] return build_alexa_response('You have %s' % (album_list), card_title) else: return build_alexa_response('You have no albums by %s' % (heard_artist), card_title) else: return build_alexa_response('Could not find %s' % (heard_artist), card_title) else: return build_alexa_response('Could not find %s' % (heard_artist), 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_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)
def alexa_pick_random_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) print('Trying to play a random episode of %s' % (heard_show)) 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']: episodes_result = kodi.GetEpisodesFromShow(located['tvshowid']) episodes_array = [] for episode in episodes_result['result']['episodes']: episodes_array.append(episode['episodeid']) kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(random.choice(episodes_array)) kodi.StartVideoPlaylist() return build_alexa_response('Playing a random episode of %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show))
def alexa_play_next_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) print('Trying to play the next episode of %s' % (heard_show)) 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: next_episode = kodi.GetNextUnwatchedEpisode(located['tvshowid']) if next_episode: kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(next_episode) kodi.StartVideoPlaylist() return build_alexa_response('Playing next episode of %s' % (heard_show)) else: return build_alexa_response('No new episodes for %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show))
def alexa_play_next_episode(slots): heard_show = str(slots['Show']['value']).lower().translate( None, string.punctuation) print('Trying to play the next episode of %s' % (heard_show)) 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: next_episode = kodi.GetNextUnwatchedEpisode(located['tvshowid']) if next_episode: kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(next_episode) kodi.StartVideoPlaylist() return build_alexa_response('Playing next episode of %s' % (heard_show)) else: return build_alexa_response('No new episodes for %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show))
def alexa_play_playlist(slots): heard_playlist = str(slots['Playlist']['value']).lower().translate( None, string.punctuation) card_title = 'Playing playlist "%s"' % (heard_playlist) print card_title sys.stdout.flush() playlists = kodi.GetMusicPlaylists() if 'result' in playlists and 'files' in playlists['result']: playlists_list = playlists['result']['files'] located = kodi.matchHeard(heard_playlist, playlists_list, 'label') if located: print 'Located playlist "%s"' % (located['file']) sys.stdout.flush() kodi.StartPlaylist(located['file']) return build_alexa_response( 'Playing playlist %s' % (heard_playlist), card_title) else: return build_alexa_response( 'I Could not find a playlist named %s' % (heard_playlist), card_title) else: return build_alexa_response('Error parsing results', card_title)
def alexa_play_movie(slots): heard_movie = str(slots['Movie']['value']).lower().translate( None, string.punctuation) card_title = 'Playing the movie %s' % (heard_movie) print card_title sys.stdout.flush() movies = kodi.GetMovies() if 'result' in movies and 'movies' in movies['result']: movies_array = movies['result']['movies'] located = kodi.matchHeard(heard_movie, movies_array) if located: kodi.ClearVideoPlaylist() kodi.PrepMoviePlaylist(located['movieid']) kodi.StartVideoPlaylist() return build_alexa_response('Playing %s' % (heard_movie), card_title) else: return build_alexa_response( 'Could not find a movie called %s' % (heard_movie), card_title) else: return build_alexa_response('Error parsing results', card_title)
def alexa_new_show_inquiry(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) print('Checking if there are new episodes to watch of %s' % (heard_show)) 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']: num_of_unwatched = 0 else: num_of_unwatched = len(episodes_result['result']['episodes']) if num_of_unwatched > 0: if num_of_unwatched == 1: return build_alexa_response("There is one unseen episode of %(real_show)s." % {'real_show': heard_show}) else: return build_alexa_response("There are %(num)d episodes of %(real_show)s." % {'real_show': heard_show, 'num': num_of_unwatched}) else: return build_alexa_response("There are no unseen episodes of %(real_show)s." % {'real_show': heard_show}) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Error parsing results.')
def alexa_play_movie(slots): heard_movie = str(slots['Movie']['value']).lower().translate( None, string.punctuation) card_title = 'Playing the movie %s' % (heard_movie) print card_title sys.stdout.flush() movies = kodi.GetMovies() if 'result' in movies and 'movies' in movies['result']: movies_array = movies['result']['movies'] located = kodi.matchHeard(heard_movie, movies_array) if located: if kodi.GetMovieDetails( located['movieid'])['resume']['position'] > 0: action = 'Resuming' else: action = 'Playing' kodi.PlayMovie(located['movieid']) return build_alexa_response('%s %s' % (action, heard_movie), card_title) else: return build_alexa_response( 'Could not find a movie called %s' % (heard_movie), card_title) else: 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) print('Trying to play a specific episode of %s' % (heard_show)) 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_result = kodi.GetSpecificEpisode(located['tvshowid'], heard_season, heard_episode) if episode_result: kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(episode_result) kodi.StartVideoPlaylist() return build_alexa_response('Playing season %s episode %s of %s' % (heard_season, heard_episode, heard_show)) else: return build_alexa_response('Could not find season %s episode %s of %s' % (heard_season, heard_episode, heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Error parsing results.')
def alexa_play_newest_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) print('Trying to play the newest episode of %s' % (heard_show)) 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_result = kodi.GetNewestEpisodeFromShow(located['tvshowid']) if episode_result: kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(episode_result) kodi.StartVideoPlaylist() return build_alexa_response('Playing latest episode of %s' % (heard_show)) else: return build_alexa_response('Could not find newest episode of %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Error parsing results.')
def alexa_play_artist(slots): heard_artist = str(slots['Artist']['value']).lower().translate(None, string.punctuation) print('Trying to play music by %s' % (heard_artist)) sys.stdout.flush() artists = kodi.GetMusicArtists() if 'result' in artists and 'artists' in artists['result']: artists_list = artists['result']['artists'] located = kodi.matchHeard(heard_artist, artists_list, 'artist') if located: songs_result = kodi.GetArtistSongs(located['artistid']) songs = songs_result['result']['songs'] kodi.Stop() kodi.ClearPlaylist() songs_array = [] for song in songs: songs_array.append(song['songid']) kodi.AddSongsToPlaylist(songs_array) kodi.StartPlaylist() return build_alexa_response('Playing %s' % (heard_artist)) else: return build_alexa_response('Could not find %s' % (heard_artist)) else: return build_alexa_response('Could not find %s' % (heard_artist))
def alexa_pick_random_episode(slots): heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) print('Trying to play a random episode of %s' % (heard_show)) 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']: episodes_result = kodi.GetEpisodesFromShow(located['tvshowid']) episodes_array = [] for episode in episodes_result['result']['episodes']: episodes_array.append(episode['episodeid']) kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(random.choice(episodes_array)) kodi.StartVideoPlaylist() return build_alexa_response('Playing a random episode of %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Error parsing results.')
def alexa_play_newest_episode(slots): heard_show = str(slots['Show']['value']).lower().translate( None, string.punctuation) print('Trying to play the newest episode of %s' % (heard_show)) 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_result = kodi.GetNewestEpisodeFromShow(located['tvshowid']) if episode_result: kodi.ClearVideoPlaylist() kodi.PrepEpisodePlayList(episode_result) kodi.StartVideoPlaylist() return build_alexa_response('Playing latest episode of %s' % (heard_show)) else: return build_alexa_response( 'Could not find newest episode of %s' % (heard_show)) else: return build_alexa_response('Could not find %s' % (heard_show)) else: return build_alexa_response('Error parsing results.')
def alexa_play_artist(slots): heard_artist = str(slots['Artist']['value']).lower().translate( None, string.punctuation) print('Trying to play music by %s' % (heard_artist)) sys.stdout.flush() artists = kodi.GetMusicArtists() if 'result' in artists and 'artists' in artists['result']: artists_list = artists['result']['artists'] located = kodi.matchHeard(heard_artist, artists_list, 'artist') if located: songs_result = kodi.GetArtistSongs(located['artistid']) songs = songs_result['result']['songs'] kodi.Stop() kodi.ClearPlaylist() songs_array = [] for song in songs: songs_array.append(song['songid']) kodi.AddSongsToPlaylist(songs_array) kodi.StartPlaylist() return build_alexa_response('Playing %s' % (heard_artist)) else: return build_alexa_response('Could not find %s' % (heard_artist)) else: return build_alexa_response('Could not find %s' % (heard_artist))
def alexa_play_tv_channel(slots): print slots print('Trying to play tv channel') sys.stdout.flush() heard_channel = str(slots['Channel']['value']).lower().translate( None, string.punctuation) # Get the list of tv channels from the PVR channels = kodi.GetTvChannels() if 'result' in channels and 'channels' in channels['result']: channel_array = channels['result']['channels'] located = kodi.matchHeard(heard_channel, channel_array) if located: kodi.PlayTvChannel(located['channelid']) answer = 'Playing channel %s' % (heard_channel) return build_alexa_response(answer)
def alexa_play_playlist(slots): heard_playlist = str(slots['Playlist']['value']).lower().translate(None, string.punctuation) print('Trying to play playlist "%s"' % (heard_playlist)) sys.stdout.flush() playlists = kodi.GetMusicPlaylists() if 'result' in playlists and 'files' in playlists['result']: playlists_list = playlists['result']['files'] located = kodi.matchHeard(heard_playlist, playlists_list, 'label') if located: print 'Playing playlist "%s"' % (located['file']) sys.stdout.flush() kodi.StartPlaylist(located['file']) return build_alexa_response('Playing playlist %s' % (heard_playlist)) else: return build_alexa_response('Could not find %s' % (heard_playlist)) else: return build_alexa_response('Error parsing results.')
def alexa_play_movie(slots): heard_movie = str(slots['Movie']['value']).lower().translate(None, string.punctuation) print('Trying to play the movie %s' % (heard_movie)) sys.stdout.flush() movies_response = kodi.GetMovies() if 'result' in movies_response and 'movies' in movies_response['result']: movies = movies_response['result']['movies'] located = kodi.matchHeard(heard_movie, movies) if located: kodi.ClearVideoPlaylist() kodi.PrepMoviePlaylist(located['movieid']) kodi.StartVideoPlaylist() return build_alexa_response('Playing %s' % (heard_movie)) else: return build_alexa_response('Could not find a movie called %s' % (heard_movie)) else: return build_alexa_response('Error parsing results.')