예제 #1
0
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)
예제 #2
0
파일: wsgi.py 프로젝트: irvingwa/kodi-alexa
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))
예제 #3
0
파일: wsgi.py 프로젝트: irvingwa/kodi-alexa
def alexa_stop(slots):
    print('Stopping Playback')
    sys.stdout.flush()

    kodi.Stop()
    answer = "Playback Stopped"
    return build_alexa_response(answer)
예제 #4
0
def alexa_stop(slots):
    card_title = 'Stopping playback'
    print card_title
    sys.stdout.flush()

    kodi.Stop()
    answer = "Playback stopped"
    return build_alexa_response(answer, card_title)
예제 #5
0
def alexa_play_artist(slots):
    artists = kodi.GetMusicArtists()
    
    heard_artist =  str(slots['Artist']['value']).lower().translate(None, string.punctuation)
    located = None
    fuzzy_match = False
    
    for artist in artists['result']['artists']:
        ascii_name = artist['artist'].encode('ascii', 'replace')
        artist_name = str(ascii_name).lower().translate(None, string.punctuation)
        if artist_name == heard_artist:
            located = artist_name
            artist_id = artist['artistid']
            break
            
    if not located:
        # Try an exact match after removing any leading "the"
        heard_minus_the = remove_the(heard_artist)
        for artist in artists['result']['artists']:
            ascii_name = artist['artist'].encode('ascii', 'replace')
            artist_name = str(ascii_name).lower().translate(None, string.punctuation)
            if remove_the(artist_name) == heard_minus_the:
                located = artist_name
                artist_id = artist['artistid']
                break

    if located:
        songs_result = kodi.GetArtistSongs(artist_id)
        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' % (located))
    else:
        return build_alexa_response('Could not find %s' % (heard_artist))
예제 #6
0
파일: wsgi.py 프로젝트: irvingwa/kodi-alexa
def alexa_party_play(slots):
    songs = kodi.GetAllSongs()

    if 'result' in songs and 'songs' in songs['result']:
        kodi.Stop()
        kodi.ClearPlaylist()

        songs_array = []

        for song in songs['result']['songs']:
            songs_array.append(song['songid'])

        random.shuffle(songs_array)
        print songs_array

        kodi.AddSongsToPlaylist(songs_array)
        kodi.StartPlaylist()
        return build_alexa_response('Starting Party play')
    else:
        return build_alexa_response('Error parsing results.')
예제 #7
0
파일: wsgi.py 프로젝트: irvingwa/kodi-alexa
def alexa_play_recently_added_songs(slots):
    print('Trying to play recently added songs')
    sys.stdout.flush()

    songs_result = kodi.GetRecentlyAddedSongs()
    if songs_result:
        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 recently added songs')
    return build_alexa_response('No recently added songs found')
예제 #8
0
def alexa_stop(slots):
    kodi.Stop()
    answer = "Playback Stopped"
    return build_alexa_response(answer)