Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better support for music videos #210

Merged
merged 6 commits into from
Aug 11, 2017
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ MUSICPLAYLISTS
VIDEOPLAYLISTS
MOVIES
MOVIEGENRES
MUSICVIDEOGENRES
SHOWS
SHOWGENRES
MUSICVIDEOS
MUSICVIDEOGENRES
ADDONS

kodi-alexa/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ You need to create the following slots:
- MOVIEGENRES
- SHOWS
- SHOWGENRES
- MUSICVIDEOS
- MUSICVIDEOGENRES
- MUSICARTISTS
- MUSICALBUMS
Expand Down
76 changes: 69 additions & 7 deletions alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ def find_and_play(kodi, needle, content=['video','audio'], shuffle=False, slot_h
kodi.PlayEpisode(episode_id)
return render_template('playing_episode_number', season=episode_details['season'], episode=episode_details['episode'], show_name=show[0][1]).encode("utf-8")

# Music Video?
if 'video' in content and 'MusicVideo' not in slot_ignore and (slot_hint == 'unknown' or slot_hint == 'MusicVideo'):
musicvideo = kodi.FindMusicVideo(needle)
if len(musicvideo) > 0:
musicvideo_details = kodi.GetMusicVideoDetails(musicvideo[0][0])
kodi.PlayMusicVideo(musicvideo[0][0])
return render_template('playing_musicvideo', musicvideo_name=musicvideo[0][1], artist_name=musicvideo_details['artist'][0]).encode("utf-8")

# Artist?
if 'audio' in content and 'Artist' not in slot_ignore and (slot_hint == 'unknown' or slot_hint == 'Artist'):
artist = kodi.FindArtist(needle)
Expand Down Expand Up @@ -2191,19 +2199,73 @@ def alexa_watch_random_music_video(MusicVideoGenre):
musicvideos = kodi.GetMusicVideosByGenre(genre[0][1])
else:
musicvideos = kodi.GetMusicVideos()
musicvideos_array = []
if 'result' in musicvideos and 'musicvideos' in musicvideos['result']:
musicvideos_array = musicvideos['result']['musicvideos']
if len(musicvideos_array) > 0:
random_musicvideo = random.choice(musicvideos_array)
musicvideo_details = kodi.GetMusicVideoDetails(random_musicvideo['musicvideoid'])

kodi.PlayMusicVideo(random_musicvideo['musicvideoid'])
if len(genre) > 0:
response_text = render_template('playing_genre_musicvideo', genre_name=genre[0][1], musicvideo_name=random_musicvideo['label'], artist_name=musicvideo_details['artist'][0]).encode("utf-8")
else:
response_text = render_template('playing_musicvideo', musicvideo_name=random_musicvideo['label'], artist_name=musicvideo_details['artist'][0]).encode("utf-8")
else:
response_text = render_template('error_parsing_results').encode("utf-8")
else:
response_text = render_template('error_parsing_results').encode("utf-8")

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


# Handle the WatchMusicVideo intent.
@ask.intent('WatchMusicVideo')
def alexa_watch_music_video(MusicVideo):
card_title = render_template('playing_musicvideo_card').encode("utf-8")
print card_title

kodi = Kodi(config, context)
musicvideo = kodi.FindMusicVideo(MusicVideo)
if len(musicvideo) > 0:
musicvideo_details = kodi.GetMusicVideoDetails(musicvideo[0][0])
kodi.PlayMusicVideo(musicvideo[0][0])
response_text = render_template('playing_musicvideo', musicvideo_name=musicvideo[0][1], artist_name=musicvideo_details['artist'][0]).encode("utf-8")
else:
response_text = render_template('could_not_find_musicvideo', heard_musicvideo=MusicVideo).encode("utf-8")

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


if len(musicvideos_array) > 0:
random_musicvideo = random.choice(musicvideos_array)
musicvideo_details = kodi.GetMusicVideoDetails(random_musicvideo['musicvideoid'])
# Handle the ShuffleMusicVideos intent.
@ask.intent('ShuffleMusicVideos')
def alexa_shuffle_music_videos(MusicVideoGenre):
kodi = Kodi(config, context)
genre = []
if MusicVideoGenre:
card_title = render_template('shuffling_musicvideos_genre', genre=MusicVideoGenre).encode("utf-8")
genre = kodi.FindVideoGenre(MusicVideoGenre, 'musicvideo')
else:
card_title = render_template('shuffling_musicvideos').encode("utf-8")
print card_title

kodi.PlayMusicVideo(random_musicvideo['musicvideoid'])
# Select from specified genre if one was matched
if len(genre) > 0:
musicvideos_result = kodi.GetMusicVideosByGenre(genre[0][1])
else:
musicvideos_result = kodi.GetMusicVideos()
if 'result' in musicvideos_result and 'musicvideos' in musicvideos_result['result']:
musicvideos_array = []
for musicvideo in musicvideos_result['result']['musicvideos']:
musicvideos_array.append(musicvideo['musicvideoid'])

kodi.PlayerStop()
kodi.ClearVideoPlaylist()
kodi.AddMusicVideosToPlaylist(musicvideos_array, True)
kodi.StartVideoPlaylist()
if len(genre) > 0:
response_text = render_template('playing_genre_musicvideo', genre_name=genre[0][1], musicvideo_name=random_musicvideo['label'], artist_name=musicvideo_details['artist'][0]).encode("utf-8")
response_text = render_template('shuffling_musicvideos_genre', genre=genre[0][1]).encode("utf-8")
else:
response_text = render_template('playing_musicvideo', musicvideo_name=random_musicvideo['label'], artist_name=musicvideo_details['artist'][0]).encode("utf-8")
response_text = render_template('shuffling_musicvideos').encode("utf-8")
else:
response_text = render_template('error_parsing_results').encode("utf-8")

Expand Down
6 changes: 6 additions & 0 deletions generate_custom_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def write_file(filename, items=[]):
write_file('SHOWS', cl)


# Generate MUSICVIDEOS Slot
retrieved = kodi.GetMusicVideos()
cl = clean_results(retrieved, 'musicvideos', 'label')
write_file('MUSICVIDEOS', cl)


# Generate ADDONS Slot
retrieved = {'result': {'addons': []}}
for content in ['video', 'audio', 'image', 'executable']:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gunicorn
pytz
flask-ask>=0.8.9
kodi-voice>=0.9.6
kodi-voice>=0.9.7
18 changes: 18 additions & 0 deletions speech_assets/IntentSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@
}
]
},
{
"intent": "WatchMusicVideo",
"slots": [
{
"name": "MusicVideo",
"type": "MUSICVIDEOS"
}
]
},
{
"intent": "WatchRandomMusicVideo",
"slots": [
Expand All @@ -401,6 +410,15 @@
}
]
},
{
"intent": "ShuffleMusicVideos",
"slots": [
{
"name": "MusicVideoGenre",
"type": "MUSICVIDEOGENRES"
}
]
},
{
"intent": "ShuffleShow",
"slots": [
Expand Down
8 changes: 8 additions & 0 deletions speech_assets/SampleUtterances.german.txt
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,12 @@ ShuffleLatestAlbum starte Zufallswiedergabe des neuen Albums von {Artist}
ShuffleLatestAlbum starte Zufallswiedergabe des neuesten Albums von {Artist}
ShuffleLatestAlbum starte Zufallswiedergabe des zuletzt hinzugefügten Albums von {Artist}
ShuffleMedia zufallswiedergabe {Show}
ShuffleMusicVideos zeige Musikvideos
ShuffleMusicVideos zeige alle Musikvideos
ShuffleMusicVideos zeige alle {MusicVideoGenre} Musikvideos
ShuffleMusicVideos zeige zufällige Musikvideos
ShuffleMusicVideos zeige zufällige {MusicVideoGenre} Musikvideos
ShuffleMusicVideos zeige {MusicVideoGenre} Musikvideos
ShufflePlaylist zufallswiedergabe playlist {AudioPlaylist}
ShufflePlaylist zufallswiedergabe playlist {VideoPlaylist}
ShufflePlaylist zufallswiedergabe {AudioPlaylist} playlist
Expand Down Expand Up @@ -1105,6 +1111,8 @@ WatchMovieTrailer zeige Trailer von {Movie}
WatchMovieTrailer zeige Vorschau
WatchMovieTrailer zeige Vorschau für {Movie}
WatchMovieTrailer zeige Vorschau von {Movie}
WatchMusicVideo zeige Musikvideo {MusicVideo}
WatchMusicVideo zeige das Musikvideo {MusicVideo}
WatchNextEpisode zeige nächste Episode von {Show}
WatchNextEpisode zeige nächste Folge von {Show}
WatchRandomEpisode zeige eine Episode von {Show}
Expand Down
16 changes: 16 additions & 0 deletions speech_assets/SampleUtterances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ ShuffleLatestAlbum shuffle newest album by {Artist}
ShuffleLatestAlbum shuffle the latest album by {Artist}
ShuffleLatestAlbum shuffle the newest album by {Artist}
ShuffleMedia shuffle {Show}
ShuffleMusicVideos play all music videos
ShuffleMusicVideos play all {MusicVideoGenre} music videos
ShuffleMusicVideos play music videos
ShuffleMusicVideos play {MusicVideoGenre} music videos
ShuffleMusicVideos shuffle all music videos
ShuffleMusicVideos shuffle all {MusicVideoGenre} music videos
ShuffleMusicVideos shuffle music videos
ShuffleMusicVideos shuffle {MusicVideoGenre} music videos
ShuffleMusicVideos watch all music videos
ShuffleMusicVideos watch all {MusicVideoGenre} music videos
ShuffleMusicVideos watch music videos
ShuffleMusicVideos watch {MusicVideoGenre} music videos
ShufflePlaylist shuffle playlist {AudioPlaylist}
ShufflePlaylist shuffle playlist {VideoPlaylist}
ShufflePlaylist shuffle the playlist {AudioPlaylist}
Expand Down Expand Up @@ -916,6 +928,10 @@ WatchMovieTrailer watch the trailer
WatchMovieTrailer watch the trailer for {Movie}
WatchMovieTrailer watch trailer
WatchMovieTrailer watch trailer for {Movie}
WatchMusicVideo play music video {MusicVideo}
WatchMusicVideo play the music video {MusicVideo}
WatchMusicVideo watch music video {MusicVideo}
WatchMusicVideo watch the music video {MusicVideo}
WatchNextEpisode play next episode of {Show}
WatchNextEpisode play the next episode of {Show}
WatchNextEpisode watch next episode of {Show}
Expand Down
8 changes: 8 additions & 0 deletions templates.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ could_not_find_show: "Konnte die Serie {{ heard_show }} nicht finden"

could_not_find_episode_show: "Konnte Staffel {{ season }} Folge {{ episode }} von {{ show_name }} nicht finden"

could_not_find_musicvideo: "Konnte kein Musikvideo mit dem Namen {{ heard_musicvideo }} finden"

no_recommendations: "Es tut mir leid, aber es gibt nichts zu empfehlen."

recommend_movie: "Wie wäre es mit dem Film {{ movie_name }}?"
Expand Down Expand Up @@ -329,6 +331,12 @@ playing_next_unwatched_episode: "Spiele die nächste ungesehene Folge von {{ hea

playing_newest_episode: "Spiele die neueste Folge von {{ heard_show }}"

playing_musicvideo_card: "Spiele Musikvideo"

shuffling_musicvideos: "Spiele zufällige Musikvideos"

shuffling_musicvideos_genre: "Spiele zufällige {{ genre }} Musikvideos"

playing_random_musicvideo: "Spiele ein zufälliges Musikvideo"

playing_random_musicvideo_genre: "Spiele ein zufälliges {{ genre }} Musikvideo"
Expand Down
8 changes: 8 additions & 0 deletions templates.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ could_not_find_show: "Could not find a show named {{ heard_show }}"

could_not_find_episode_show: "Could not find season {{ season }} episode {{ episode }} of {{ show_name }}"

could_not_find_musicvideo: "Could not find a music video called {{ heard_musicvideo }}"

no_recommendations: "I'm sorry, I have nothing to recommend"

recommend_movie: "How about the movie {{ movie_name }}?"
Expand Down Expand Up @@ -329,6 +331,12 @@ playing_next_unwatched_episode: "Playing the next unwatched episode of {{ heard_

playing_newest_episode: "Playing the newest episode of {{ heard_show }}"

playing_musicvideo_card: "Playing music video"

shuffling_musicvideos: "Shuffling music videos"

shuffling_musicvideos_genre: "Shuffling {{ genre }} music videos"

playing_random_musicvideo: "Playing a random music video"

playing_random_musicvideo_genre: "Playing a random {{ genre }} music video"
Expand Down
4 changes: 4 additions & 0 deletions utterances.german.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ WatchLastShow weiter mit (/letzter) Serie

WatchLatestEpisode zeige (neueste/letzte) (Episode/Folge) von {Show}

WatchMusicVideo zeige (/das) Musikvideo {MusicVideo}

WatchRandomMusicVideo zeige ein (/zufälliges) (/{MusicVideoGenre}) Musikvideo

ShuffleShow zufallswiedergabe (/aller) episoden von {Show}

ShuffleMusicVideos zeige (/zufällige/alle) (/{MusicVideoGenre}) Musikvideos

ShuffleLatestAlbum (shuffle/(/starte) Zufallswiedergabe) des (aktuellen/neuen/aktuellsten/neuesten/zuletzt hinzugefügten) Albums von {Artist}

ShuffleAlbum zufallswiedergabe (album/des albums/vom album) {Album}
Expand Down
4 changes: 4 additions & 0 deletions utterances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ WatchLastShow continue (/watching/playing) (/last/the last) show

WatchLatestEpisode (play/watch) (/the) (newest/latest) episode of {Show}

WatchMusicVideo (play/watch) (/the) music video {MusicVideo}

WatchRandomMusicVideo (play/watch) (/a) random (/{MusicVideoGenre}) music video

WatchVideoPlaylist (play/watch) (/the) (movie/show/video) playlist {VideoPlaylist}
Expand All @@ -163,6 +165,8 @@ WatchVideoPlaylist watch {VideoPlaylist} playlist

ShuffleShow shuffle (/all) episodes of {Show}

ShuffleMusicVideos (play/watch/shuffle) (/all) (/{MusicVideoGenre}) music videos

ShuffleLatestAlbum shuffle (/the) (latest/newest) album by {Artist}

ShuffleAlbum shuffle (album/the album) {Album}
Expand Down