From 79f5178fd915d6f0782d84417a0277e03ca9621f Mon Sep 17 00:00:00 2001 From: jingai Date: Wed, 9 Aug 2017 22:24:41 -0400 Subject: [PATCH 1/6] Add support for music videos in find_and_play(). --- alexa.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/alexa.py b/alexa.py index de683ce..d21d592 100644 --- a/alexa.py +++ b/alexa.py @@ -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) From bc8c1521073d2927fd567790dd8655765df9eec2 Mon Sep 17 00:00:00 2001 From: jingai Date: Wed, 9 Aug 2017 23:48:40 -0400 Subject: [PATCH 2/6] Add ShuffleMusicVideos Intent. --- alexa.py | 50 +++++++++++++++++++++++++----- speech_assets/IntentSchema.json | 9 ++++++ speech_assets/SampleUtterances.txt | 12 +++++++ templates.en.yaml | 4 +++ utterances.txt | 2 ++ 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/alexa.py b/alexa.py index d21d592..77f48d0 100644 --- a/alexa.py +++ b/alexa.py @@ -2199,19 +2199,55 @@ 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']) - 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) - kodi.PlayMusicVideo(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 + + # 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") diff --git a/speech_assets/IntentSchema.json b/speech_assets/IntentSchema.json index 5179bcc..37b8a3a 100644 --- a/speech_assets/IntentSchema.json +++ b/speech_assets/IntentSchema.json @@ -401,6 +401,15 @@ } ] }, + { + "intent": "ShuffleMusicVideos", + "slots": [ + { + "name": "MusicVideoGenre", + "type": "MUSICVIDEOGENRES" + } + ] + }, { "intent": "ShuffleShow", "slots": [ diff --git a/speech_assets/SampleUtterances.txt b/speech_assets/SampleUtterances.txt index 41523ed..76ea41c 100644 --- a/speech_assets/SampleUtterances.txt +++ b/speech_assets/SampleUtterances.txt @@ -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} diff --git a/templates.en.yaml b/templates.en.yaml index 2eecbce..2b80fe9 100644 --- a/templates.en.yaml +++ b/templates.en.yaml @@ -329,6 +329,10 @@ playing_next_unwatched_episode: "Playing the next unwatched episode of {{ heard_ playing_newest_episode: "Playing the newest episode of {{ heard_show }}" +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" diff --git a/utterances.txt b/utterances.txt index f2eb3c2..4a5147b 100644 --- a/utterances.txt +++ b/utterances.txt @@ -163,6 +163,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} From a599059545cf246709ff8a121d5a8b393da1fa5e Mon Sep 17 00:00:00 2001 From: jingai Date: Thu, 10 Aug 2017 00:16:32 -0400 Subject: [PATCH 3/6] Add MUSICVIDEOS slot to generator. --- .gitignore | 3 ++- README.md | 1 + generate_custom_slots.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a6d5010..7acd7a8 100644 --- a/.gitignore +++ b/.gitignore @@ -74,9 +74,10 @@ MUSICPLAYLISTS VIDEOPLAYLISTS MOVIES MOVIEGENRES -MUSICVIDEOGENRES SHOWS SHOWGENRES +MUSICVIDEOS +MUSICVIDEOGENRES ADDONS kodi-alexa/ diff --git a/README.md b/README.md index ef56e95..56224e7 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ You need to create the following slots: - MOVIEGENRES - SHOWS - SHOWGENRES +- MUSICVIDEOS - MUSICVIDEOGENRES - MUSICARTISTS - MUSICALBUMS diff --git a/generate_custom_slots.py b/generate_custom_slots.py index 1032231..71d5e5f 100644 --- a/generate_custom_slots.py +++ b/generate_custom_slots.py @@ -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']: From 48bd7d68f30ab00fb11fb1e94800f910893896df Mon Sep 17 00:00:00 2001 From: jingai Date: Thu, 10 Aug 2017 00:54:24 -0400 Subject: [PATCH 4/6] Add WatchMusicVideo Intent. --- alexa.py | 18 ++++++++++++++++++ speech_assets/IntentSchema.json | 9 +++++++++ speech_assets/SampleUtterances.txt | 4 ++++ templates.en.yaml | 4 ++++ utterances.txt | 2 ++ 5 files changed, 37 insertions(+) diff --git a/alexa.py b/alexa.py index 77f48d0..5c85ed2 100644 --- a/alexa.py +++ b/alexa.py @@ -2218,6 +2218,24 @@ def alexa_watch_random_music_video(MusicVideoGenre): 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) + + # Handle the ShuffleMusicVideos intent. @ask.intent('ShuffleMusicVideos') def alexa_shuffle_music_videos(MusicVideoGenre): diff --git a/speech_assets/IntentSchema.json b/speech_assets/IntentSchema.json index 37b8a3a..ce65801 100644 --- a/speech_assets/IntentSchema.json +++ b/speech_assets/IntentSchema.json @@ -383,6 +383,15 @@ } ] }, + { + "intent": "WatchMusicVideo", + "slots": [ + { + "name": "MusicVideo", + "type": "MUSICVIDEOS" + } + ] + }, { "intent": "WatchRandomMusicVideo", "slots": [ diff --git a/speech_assets/SampleUtterances.txt b/speech_assets/SampleUtterances.txt index 76ea41c..75eec2f 100644 --- a/speech_assets/SampleUtterances.txt +++ b/speech_assets/SampleUtterances.txt @@ -928,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} diff --git a/templates.en.yaml b/templates.en.yaml index 2b80fe9..f881bd7 100644 --- a/templates.en.yaml +++ b/templates.en.yaml @@ -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 }}?" @@ -329,6 +331,8 @@ 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" diff --git a/utterances.txt b/utterances.txt index 4a5147b..b821c6a 100644 --- a/utterances.txt +++ b/utterances.txt @@ -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} From c2509944fedd5f68a45f3b6604a2e0dff1958767 Mon Sep 17 00:00:00 2001 From: jingai Date: Thu, 10 Aug 2017 14:42:14 -0400 Subject: [PATCH 5/6] Require Kodi-Voice 0.9.7. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ee086f5..593d2b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ gunicorn pytz flask-ask>=0.8.9 -kodi-voice>=0.9.6 +kodi-voice>=0.9.7 From 700ebc96fa504a4530a4260ff1358e636ff75eab Mon Sep 17 00:00:00 2001 From: jingai Date: Fri, 11 Aug 2017 15:33:38 -0400 Subject: [PATCH 6/6] Add German translations for music video intents. Thanks mcl22! --- speech_assets/SampleUtterances.german.txt | 8 ++++++++ templates.de.yaml | 8 ++++++++ utterances.german.txt | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/speech_assets/SampleUtterances.german.txt b/speech_assets/SampleUtterances.german.txt index 667bd77..de1d5e6 100644 --- a/speech_assets/SampleUtterances.german.txt +++ b/speech_assets/SampleUtterances.german.txt @@ -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 @@ -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} diff --git a/templates.de.yaml b/templates.de.yaml index e578b6e..32d855b 100644 --- a/templates.de.yaml +++ b/templates.de.yaml @@ -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 }}?" @@ -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" diff --git a/utterances.german.txt b/utterances.german.txt index db2a472..b1ff5f5 100644 --- a/utterances.german.txt +++ b/utterances.german.txt @@ -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}