Example #1
0
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))
Example #2
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))