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_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_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_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))
import kodi import re import string import random from yaep import populate_env # to use put the Kodi details into environment variables # KODI_ADDRESS=localhost KODI_PORT=8088 KODI_USERNAME=kodi KODI_PASSWORD=kodi python generate_custom_types.py kodi.PopulateEnv() # Generate MUSICARTISTS Slot retrieved = kodi.GetMusicArtists() all = [] if 'result' in retrieved and 'artists' in retrieved['result']: for v in retrieved['result']['artists']: name = kodi.sanitize_name(v['artist']) name_stripped = kodi.sanitize_name(v['artist'], True) all.append(name) all.append(name_stripped) cleaned = list(set(all)) cleaned = filter(None, cleaned) random.shuffle(cleaned) cleaned = cleaned[:300] gfile = open('MUSICARTISTS', 'w') for a in cleaned: gfile.write("%s\n" % a) gfile.close()