Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ The initial setup page looks like this:

On the next page, you'll have to paste the contents of the [IntentSchema.json](https://raw.githubusercontent.com/m0ngr31/kodi-alexa/master/speech_assets/IntentSchema.json) file into the "Intent Schema" field, and paste the contents of the [SampleUtterances.txt](https://raw.githubusercontent.com/m0ngr31/kodi-alexa/master/speech_assets/SampleUtterances.txt) or [SampleUtterances.german.txt](https://raw.githubusercontent.com/m0ngr31/kodi-alexa/master/speech_assets/SampleUtterances.german.txt) file in the "Sample Utterances" field. **Generate and save your Custom Slots first before pasting the Intents and Utterances to avoid errors when attempting to save**.

You need to create 9 different slots:
You need to create the following slots:
- MOVIES
- MOVIEGENRES
- SHOWS
- MUSICARTISTS
- MUSICALBUMS
- MUSICSONGS
- MUSICGENRES
- MUSICPLAYLISTS
- VIDEOPLAYLISTS
- ADDONS
Expand Down
90 changes: 67 additions & 23 deletions alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,27 +604,71 @@ def alexa_listen_audio(Artist):
return alexa_play_media(Artist=Artist, content=['audio'])


# Handle the ListenToArtist intent (Shuffles all music by an artist).
@ask.intent('ListenToArtist')
def alexa_listen_artist(Artist):
card_title = render_template('listen_artist', heard_artist=Artist).encode("utf-8")
# Handle the ListenToGenre intent (Shuffles all music of a specific genre).
@ask.intent('ListenToGenre')
def alexa_listen_genre(MusicGenre):
card_title = render_template('playing_genre', genre_name=MusicGenre).encode("utf-8")
print card_title

kodi = Kodi(config, context)
genre = kodi.FindMusicGenre(MusicGenre)
if len(genre) > 0:
songs_result = kodi.GetSongsByGenre(genre[0][1])
if 'songs' in songs_result['result']:
songs = songs_result['result']['songs']

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

kodi.PlayerStop()
kodi.ClearAudioPlaylist()
kodi.AddSongsToPlaylist(songs_array, True)
kodi.StartAudioPlaylist()
response_text = render_template('playing_genre', genre_name=genre[0][1]).encode("utf-8")
else:
response_text = render_template('could_not_find_genre', genre_name=genre[0][1]).encode("utf-8")
else:
response_text = render_template('could_not_find', heard_name=MusicGenre).encode("utf-8")

return statement(response_text).simple_card(card_title, response_text)


# Handle the ListenToArtist intent (Shuffles all music by an artist, optionally of a specific genre).
@ask.intent('ListenToArtist')
def alexa_listen_artist(Artist, MusicGenre):
kodi = Kodi(config, context)
genre = []
if MusicGenre:
card_title = render_template('listen_artist_genre', heard_genre=MusicGenre, heard_artist=Artist).encode("utf-8")
genre = kodi.FindMusicGenre(MusicGenre)
else:
card_title = render_template('listen_artist', heard_artist=Artist).encode("utf-8")
print card_title

artist = kodi.FindArtist(Artist)
if len(artist) > 0:
songs_result = kodi.GetArtistSongs(artist[0][0])
songs = songs_result['result']['songs']
if len(genre) > 0:
songs_result = kodi.GetArtistSongsByGenre(artist[0][1], genre[0][1])
response_text = render_template('playing_genre_artist', genre_name=genre[0][1], artist_name=artist[0][1]).encode("utf-8")
else:
songs_result = kodi.GetArtistSongs(artist[0][0])
response_text = render_template('playing', heard_name=artist[0][1]).encode("utf-8")
if 'songs' in songs_result['result']:
songs = songs_result['result']['songs']

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

kodi.PlayerStop()
kodi.ClearAudioPlaylist()
kodi.AddSongsToPlaylist(songs_array, True)
kodi.StartAudioPlaylist()
response_text = render_template('playing', heard_name=artist[0][1]).encode("utf-8")
kodi.PlayerStop()
kodi.ClearAudioPlaylist()
kodi.AddSongsToPlaylist(songs_array, True)
kodi.StartAudioPlaylist()
elif len(genre) > 0:
response_text = render_template('could_not_find_genre_artist', genre_name=genre[0][1], artist_name=artist[0][1]).encode("utf-8")
else:
response_text = render_template('could_not_find_artist', artist_name=artist[0][1]).encode("utf-8")
else:
response_text = render_template('could_not_find', heard_name=Artist).encode("utf-8")

Expand Down Expand Up @@ -1700,13 +1744,13 @@ def alexa_watch_video(Movie):

# Handle the WatchRandomMovie intent.
@ask.intent('WatchRandomMovie')
def alexa_watch_random_movie(Genre):
def alexa_watch_random_movie(MovieGenre):
kodi = Kodi(config, context)
genre = []
# If a genre has been specified, match the genre for use in selecting a random film
if Genre:
card_title = render_template('playing_random_movie_genre', genre=Genre).encode("utf-8")
genre = kodi.FindVideoGenre(Genre)
if MovieGenre:
card_title = render_template('playing_random_movie_genre', genre=MovieGenre).encode("utf-8")
genre = kodi.FindVideoGenre(MovieGenre)
else:
card_title = render_template('playing_random_movie').encode("utf-8")
print card_title
Expand All @@ -1730,7 +1774,7 @@ def alexa_watch_random_movie(Genre):

kodi.PlayMovie(random_movie['movieid'], False)
if len(genre) > 0:
response_text = render_template('playing_genre', genre=genre[0][1], movie_name=random_movie['label']).encode("utf-8")
response_text = render_template('playing_genre_movie', genre=genre[0][1], movie_name=random_movie['label']).encode("utf-8")
else:
response_text = render_template('playing', heard_name=random_movie['label']).encode("utf-8")
else:
Expand Down Expand Up @@ -2218,15 +2262,15 @@ def alexa_what_new_albums():

# Handle the WhatNewMovies intent.
@ask.intent('WhatNewMovies')
def alexa_what_new_movies(Genre):
def alexa_what_new_movies(MovieGenre):
kodi = Kodi(config, context)

new_movies = None

# If a genre has been specified, match the genre for use in selecting random films
if Genre:
card_title = render_template('newly_added_movies_genre', genre=Genre).encode("utf-8")
genre = kodi.FindVideoGenre(Genre)
if MovieGenre:
card_title = render_template('newly_added_movies_genre', genre=MovieGenre).encode("utf-8")
genre = kodi.FindVideoGenre(MovieGenre)
if len(genre) > 0:
new_movies = kodi.GetUnwatchedMoviesByGenre(genre[0][1])
else:
Expand Down
6 changes: 6 additions & 0 deletions generate_custom_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def write_file(filename, items=[]):
write_file('MUSICPLAYLISTS', cl)


# Generate MUSICGENRES Slot
retrieved = kodi.GetMusicGenres()
cl = clean_results(retrieved, 'genres', 'label')
write_file('MUSICGENRES', cl)


# Generate MUSICARTISTS Slot
retrieved = kodi.GetMusicArtists()
cl = clean_results(retrieved, 'artists', 'artist')
Expand Down
17 changes: 15 additions & 2 deletions speech_assets/IntentSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"intent": "WhatNewMovies",
"slots": [
{
"name": "Genre",
"name": "MovieGenre",
"type": "MOVIEGENRES"
}
]
Expand Down Expand Up @@ -174,12 +174,25 @@
}
]
},
{
"intent": "ListenToGenre",
"slots": [
{
"name": "MusicGenre",
"type": "MUSICGENRES"
}
]
},
{
"intent": "ListenToArtist",
"slots": [
{
"name": "Artist",
"type": "MUSICARTISTS"
},
{
"name": "MusicGenre",
"type": "MUSICGENRES"
}
]
},
Expand Down Expand Up @@ -347,7 +360,7 @@
"intent": "WatchRandomMovie",
"slots": [
{
"name": "Genre",
"name": "MovieGenre",
"type": "MOVIEGENRES"
}
]
Expand Down
Loading