コード例 #1
0
ファイル: wsgi.py プロジェクト: onknight/kodi-alexa
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))
コード例 #2
0
ファイル: wsgi.py プロジェクト: irvingwa/kodi-alexa
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.')
コード例 #3
0
ファイル: wsgi.py プロジェクト: onknight/kodi-alexa
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))
コード例 #4
0
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))
コード例 #5
0
ファイル: wsgi.py プロジェクト: Xaelias/kodi-alexa
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)
コード例 #6
0
ファイル: wsgi.py プロジェクト: Xaelias/kodi-alexa
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)
コード例 #7
0
ファイル: wsgi.py プロジェクト: crowland88/kodi-alexa
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 = kodi.GetNextUnwatchedEpisode(last_show_id)

        if next_episode:
            episode_details = kodi.GetEpisodeDetails(
                next_episode)['result']['episodedetails']

            kodi.ClearVideoPlaylist()
            kodi.PrepEpisodePlayList(next_episode)
            kodi.StartVideoPlaylist()

            return build_alexa_response(
                'Playing season %d episode %d of %s' %
                (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)
コード例 #8
0
ファイル: wsgi.py プロジェクト: crowland88/kodi-alexa
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)
コード例 #9
0
ファイル: wsgi.py プロジェクト: ninthwalker/kodi-alexa
def alexa_pick_random_movie(slots):
    movies_response = kodi.GetUnwatchedMovies()
    movies = movies_response['result']['movies']
    random_movie = random.choice(movies)

    kodi.ClearVideoPlaylist()
    kodi.PrepMoviePlaylist(random_movie['movieid'])
    kodi.StartVideoPlaylist()
    
    return build_alexa_response('Playing %s' % (random_movie['label']))
コード例 #10
0
ファイル: wsgi.py プロジェクト: irvingwa/kodi-alexa
def alexa_pick_random_movie(slots):
    print('Trying to play a random movie')
    sys.stdout.flush()

    movies_response = kodi.GetUnwatchedMovies()
    if 'result' in movies_response and 'movies' in movies_response['result']:
        movies = movies_response['result']['movies']
        random_movie = random.choice(movies)

        kodi.ClearVideoPlaylist()
        kodi.PrepMoviePlaylist(random_movie['movieid'])
        kodi.StartVideoPlaylist()

        return build_alexa_response('Playing %s' % (random_movie['label']))
    else:
        return build_alexa_response('Error parsing results.')
コード例 #11
0
ファイル: wsgi.py プロジェクト: ninthwalker/kodi-alexa
def alexa_play_movie(slots):
    movies_response = kodi.GetMovies()
    movies = movies_response['result']['movies']
    
    heard_movie =  str(slots['Movie']['value']).lower().translate(None, string.punctuation)
    located = None
    
    for movie in movies:
        ascii_name = movie['label'].encode('ascii', 'replace')
        movie_name = str(ascii_name).lower().translate(None, string.punctuation)
        if movie_name == heard_movie:
            located = movie_name
            movie_id = movie['movieid']
            break
            
    if not located:
        # Try an exact match after removing any leading "the"
        heard_minus_the = remove_the(heard_movie)
        for movie in movies:
            ascii_name = movie['label'].encode('ascii', 'replace')
            movie_name = str(ascii_name).lower().translate(None, string.punctuation)
            if remove_the(movie_name) == heard_minus_the:
                located = movie_name
                movie_id = movie['movieid']
                break
                
    if not located:
        # Last resort -- take out some useless words and see if we have a show with
        # any of the remaining words in common
        heard_list = set([x for x in heard_movie.split() if x not in STOPWORDS])
        for movie in movies:
            movie_list = set(movie['label'].split())
            if heard_list & movie_list:
                located = movie['label']
                movie_id = movie['movieid']
                break
                
    if located:
        kodi.ClearVideoPlaylist()
        kodi.PrepMoviePlaylist(movie_id)
        kodi.StartVideoPlaylist()
      
        return build_alexa_response('Playing %s' % (located))
    else:
        return build_alexa_response('Could not find a movie called %s' % (heard_movie))
    
    return build_alexa_response('This feature is not added yet')
コード例 #12
0
ファイル: wsgi.py プロジェクト: ninthwalker/kodi-alexa
def alexa_continue_show(slots):
    last_show_obj = kodi.GetLastWatchedShow()
    
    try:
        last_show_id = last_show_obj['result']['episodes'][0]['tvshowid']
        next_episode = kodi.GetNextUnwatchedEpisode(last_show_id)
        
        if next_episode:
            kodi.ClearVideoPlaylist()
            kodi.PrepEpisodePlayList(next_episode)

            kodi.StartVideoPlaylist()
            return build_alexa_response('Playing next episode')
        else:
            return build_alexa_response('No new episodes') 

    except:
        return build_alexa_response('Could not continue show')
コード例 #13
0
ファイル: wsgi.py プロジェクト: crowland88/kodi-alexa
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)['result']['episodedetails']

            kodi.ClearVideoPlaylist()
            kodi.PrepEpisodePlayList(episode_id)
            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(
                'Could not find a show named %s' % (heard_show), card_title)
    else:
        return build_alexa_response('Error parsing results', card_title)
コード例 #14
0
ファイル: wsgi.py プロジェクト: Xaelias/kodi-alexa
def alexa_play_random_movie(slots):
  card_title = 'Playing a random movie'
  print card_title
  sys.stdout.flush()

  movies = kodi.GetUnwatchedMovies()
  if not 'movies' in movies['result']:
    # Fall back to all movies if no unwatched available
    movies = kodi.GetMovies()

  if 'result' in movies and 'movies' in movies['result']:
    movies_array = movies['result']['movies']
    random_movie = random.choice(movies_array)

    kodi.ClearVideoPlaylist()
    kodi.PrepMoviePlaylist(random_movie['movieid'])
    kodi.StartVideoPlaylist()

    return build_alexa_response('Playing %s' % (random_movie['label']), card_title)
  else:
    return build_alexa_response('Error parsing results', card_title)
コード例 #15
0
ファイル: wsgi.py プロジェクト: ninthwalker/kodi-alexa
def alexa_play_next_episode(slots):
    shows = kodi.GetTvShows()
    shows_array = shows['result']['tvshows']
    
    heard_show =  str(slots['Show']['value']).lower().translate(None, string.punctuation)
    located = None
    
    for show in shows_array:
        ascii_name = show['label'].encode('ascii', 'replace')
        show_name = str(ascii_name).lower().translate(None, string.punctuation)
        if show_name == heard_show:
            located = show_name
            show_id = show['tvshowid']
            break
            
    if not located:
        # Try an exact match after removing any leading "the"
        heard_minus_the = remove_the(heard_show)
        for show in shows_array:
            ascii_name = show['label'].encode('ascii', 'replace')
            show_name = str(ascii_name).lower().translate(None, string.punctuation)
            if remove_the(show_name) == heard_minus_the:
                located = show_name
                show_id = show['tvshowid']
                break
                
    if not located:
        #Try removing everthing in parenthesis for shows that might have (2009) or (US)
        for show in shows_array:
            ascii_name = show['label'].encode('ascii', 'replace')
            removed_paren = re.sub(r'\([^)]*\)', '', ascii_name).rstrip()
            show_name = str(removed_paren).lower().translate(None, string.punctuation)
            if show_name == heard_show:
                located = show_name
                show_id = show['tvshowid']
                break
                
    if not located:
        # Last resort -- take out some useless words and see if we have a show with
        # any of the remaining words in common
        heard_list = set([x for x in heard_show.split() if x not in STOPWORDS])
        for show in shows_array:
            show_list = set(show['label'].split())
            if heard_list & show_list:
                located = show
                show_id = show['tvshowid']
                break
                
    if located:
        next_episode = kodi.GetNextUnwatchedEpisode(show_id)
        
        if next_episode:
          kodi.ClearVideoPlaylist()
          kodi.PrepEpisodePlayList(next_episode)

          kodi.StartVideoPlaylist()
          return build_alexa_response('Playing next episode of %s' % (located))
        else:
          return build_alexa_response('No new episodes for %s' % (heard_show))          
    else:
        return build_alexa_response('Could not find %s' % (heard_show))