m0ngr31 / kanzi

Alexa skill for controlling Kodi
https://lexigr.am
MIT License
428 stars 149 forks source link

add kodi.PlayerStop() to PlayMedia intent #247

Closed islipfd19 closed 6 years ago

islipfd19 commented 6 years ago

When testing playback of movies and music, I found there was not way to "stop" playback. Adding this to PlayMedia now allows movie and music that is currently playing to be stopped.

digiltd commented 6 years ago

"Alexa, ask kodi to stop" should work, it certainly used to. I am unable to test mine right now though.

islipfd19 commented 6 years ago

I tried different variations of asking alexa to stop playback but the closest I got was the movie would stop and then restart where it was originally playing from

digiltd commented 6 years ago

it would restart automatically?

islipfd19 commented 6 years ago

yes

jingai commented 6 years ago

I just tested this here with a movie, tv show, and song, and stop worked for all.

This patch wouldn't be right, regardless. We can help you debug your issue, though.

What version of Kodi are you using? What platform?

islipfd19 commented 6 years ago

It was tested on the latest version of Kodi that can be found on Google Play

I'm also testing it on LibreELEC 8.2.2 which includes Kodi 17.6

I removed the code I added and performed a test. I started a movie and then issued a 'stop', that's the first debug post below and then a 'stop playing' command, the second debug post below:

[2018-01-04 06:36:34 +0000] [10981] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled

[2018-01-04 06:36:48 +0000] [10981] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled INFO:kodi_alexa.alexa:Playing INFO:kodi_alexa.alexa:Find and Play: "" INFO:kodi_alexa.alexa:Searching content types: INFO:kodi_alexa.alexa:['video', 'audio'] INFO:kodi_voice.kodi:Searching for video playlist "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"directory": "special://videoplaylists"}, "jsonrpc": "2.0", "method": "Files.GetDirectory", "id": 1} INFO:kodi_voice.kodi:Trying to match: INFO:kodi_voice.kodi:Simple match failed, trying fuzzy match INFO:kodi_voice.kodi:Processing 10 items with fuzzywuzzy... INFO:kodi_voice.kodi: heard -> "" INFO:kodi_voice.kodi: digits2roman -> "" INFO:kodi_voice.kodi: words2roman -> "" INFO:kodi_voice.kodi: words2digits -> "" INFO:kodi_voice.kodi: digits2words -> "" INFO:kodi_voice.kodi: Trying with "" WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ''] INFO:kodi_voice.kodi:Searching for audio playlist "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"directory": "special://musicplaylists"}, "jsonrpc": "2.0", "method": "Files.GetDirectory", "id": 1} INFO:kodi_voice.kodi:Searching for movie "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} INFO:kodi_voice.kodi:Trying to match: INFO:kodi_voice.kodi:Simple match failed, trying fuzzy match INFO:kodi_voice.kodi:Processing 868 items with fuzzywuzzy... INFO:kodi_voice.kodi: heard -> "" INFO:kodi_voice.kodi: digits2roman -> "" INFO:kodi_voice.kodi: words2roman -> "" INFO:kodi_voice.kodi: words2digits -> "" INFO:kodi_voice.kodi: digits2words -> "" INFO:kodi_voice.kodi: Trying with "" WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ''] INFO:kodi_voice.kodi:Searching for show "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "id": 1} INFO:kodi_voice.kodi:Trying to match: INFO:kodi_voice.kodi:Simple match failed, trying fuzzy match INFO:kodi_voice.kodi:Processing 8 items with fuzzywuzzy... INFO:kodi_voice.kodi: heard -> "" INFO:kodi_voice.kodi: digits2roman -> "" INFO:kodi_voice.kodi: words2roman -> "" INFO:kodi_voice.kodi: words2digits -> "" INFO:kodi_voice.kodi: digits2words -> "" INFO:kodi_voice.kodi: Trying with "" WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ''] INFO:kodi_voice.kodi:Searching for music video "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"properties": ["artist"]}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "id": 1} INFO:kodi_voice.kodi:Searching for artist "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"albumartistsonly": false}, "jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "id": 1} INFO:kodi_voice.kodi:Trying to match: INFO:kodi_voice.kodi:Simple match failed, trying fuzzy match INFO:kodi_voice.kodi:Processing 448 items with fuzzywuzzy... INFO:kodi_voice.kodi: heard -> "" INFO:kodi_voice.kodi: digits2roman -> "" INFO:kodi_voice.kodi: words2roman -> "" INFO:kodi_voice.kodi: words2digits -> "" INFO:kodi_voice.kodi: digits2words -> "" INFO:kodi_voice.kodi: Trying with "" WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ''] INFO:kodi_voice.kodi:Searching for song "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "id": 1} INFO:kodi_voice.kodi:Trying to match: INFO:kodi_voice.kodi:Simple match failed, trying fuzzy match INFO:kodi_voice.kodi:Processing 5323 items with fuzzywuzzy... INFO:kodi_voice.kodi: heard -> "" INFO:kodi_voice.kodi: digits2roman -> "" INFO:kodi_voice.kodi: words2roman -> "" INFO:kodi_voice.kodi: words2digits -> "" INFO:kodi_voice.kodi: digits2words -> "" INFO:kodi_voice.kodi: Trying with "" WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ''] INFO:kodi_voice.kodi:Searching for album "" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "id": 1} INFO:kodi_voice.kodi:Trying to match: INFO:kodi_voice.kodi:Simple match failed, trying fuzzy match INFO:kodi_voice.kodi:Processing 690 items with fuzzywuzzy... INFO:kodi_voice.kodi: heard -> "" INFO:kodi_voice.kodi: digits2roman -> "" INFO:kodi_voice.kodi: words2roman -> "" INFO:kodi_voice.kodi: words2digits -> "" INFO:kodi_voice.kodi: digits2words -> "" INFO:kodi_voice.kodi: Trying with "" WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: '']

jingai commented 6 years ago

The search terms are not being passed to the skill code. Further, the skill code thinks you've issued a generic "play" command, which is why you're seeing the odd behavior.

Both of these things are not the skill's fault though. You've got something misconfigured. It looks like you're self-hosting judging from the IP address you're using for Kodi, so I'd guess it's something wrong there.

digiltd commented 6 years ago

I removed the code I added and performed a test. I started a movie and then issued a 'stop', that's the first debug post below and then a 'stop playing' command

"stop playing" wouldn't work, though "stop" should if used as part of "alexa, ask kodi to stop", saying "alexa, kodi stop" would (I think) treat "stop" in the standard Alexa way which is an escape.

jingai commented 6 years ago

Ah I see, there's two logs there.. sorry, not yet really awake.

Yes, what @digiltd said is correct.

stop is definitely working here, so you probably should check the model configuration again.

islipfd19 commented 6 years ago

Does the order of the utterances matter? It would be the only thing I could think of that could be out of place.

jingai commented 6 years ago

No, but if you've modified them, it could matter.

The intent that should match is AMAZON.StopIntent, which is handled in the skill by alexa_stop(). This is what fires on my copies of the skill here.

In the skill on Amazon's dev site, under Skill Information->Global Fields, do you have any of those enabled? None should be. I doubt this is the problem, but I otherwise don't really know why the built-in wouldn't be firing for you, unless Amazon goofed up the model builder recently (it happens).

jingai commented 6 years ago

Just to make sure.. what region are you in? And does the language on your skill model match that of your Echo device(s)?

islipfd19 commented 6 years ago

Global fields are all set to 'no' on the 'skill information'

My intent schema includes the stop intent.

{
  "intent": "AMAZON.StopIntent"
},

The region I'm in is the U.S.

I'm also using Amazon's 'test' within the skill to perform these commands, though I don't think that would matter either.

jingai commented 6 years ago

It can matter, actually. The simulator very often doesn't match reality. But, it works for me in the simulator as well.

Tell us exactly what you are saying verbally and typing in the simulator (full phrase, including the invocation you use).

islipfd19 commented 6 years ago

I'm unable to test it verbally at the moment but the phrases I've tried are 'stop', 'stop movie', 'stop playing', 'stop {Movie}' (obviously I said the movie name here). I've used the same phrases in the simulator.

jingai commented 6 years ago

Please include the invocation phrase.

For example, the full utterance I use is:

Alexa, ask Kodi to stop

In the simulator, all you would enter is the word stop. There are other synonyms that work as well (Amazon maintains the list of acceptable synonyms). I'm kind of surprised it doesn't recognize "stop playing" as one, but it appears it doesn't.

islipfd19 commented 6 years ago

running the command 'Alexa, ask Kodi to stop' on the simulator produced this error. The artist is not defined error is probably due to the fact that I removed all music intents, utterances and slots from my skill.

[2018-01-04 07:39:49,067] ERROR in app: Exception on / [POST] Traceback (most recent call last): File "/usr/local/bin/kodi-alexa.test/test/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/usr/local/bin/kodi-alexa.test/test/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/bin/kodi-alexa.test/test/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/bin/kodi-alexa.test/test/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/bin/kodi-alexa.test/test/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functionsrule.endpoint File "/usr/local/bin/kodi-alexa.test/test/local/lib/python2.7/site-packages/flask_ask/core.py", line 670, in _flask_view_func result = self._map_intent_to_view_func(self.request.intent)() File "/usr/local/bin/kodi-alexa.test/alexa.py", line 85, in decorated_function return f(*args, **kwargs) File "/usr/local/bin/kodi-alexa.test/alexa.py", line 642, in alexa_play_media return _alexa_play_media(kodi, Movie, Artist) NameError: global name 'Artist' is not defined

jingai commented 6 years ago

You do not enter "Alexa, ask Kodi to stop" on the simulator. As I said, you only enter the single word "stop".

When you're verbally asking an Echo, you'd say something like "Alexa, ask Kodi to stop".

jingai commented 6 years ago

Also, please revert your skill model back to stock before asking for support. We have no way of telling if your modifications are contributing to your issues or not. Even if you don't use the music intents, it doesn't hurt anything to leave them in there.

islipfd19 commented 6 years ago

I'll revert the skill to continue the testing. The music intents were removed as I wouldn't want my three year old daughter make an attempt to play one of her movies and have Kodi begin to play Metallica.

I'll provide additional feedback once I've reverted the skill (will probably create new one to test with)

islipfd19 commented 6 years ago

I created a new skill, used all the intents, utterances and slots as defined.

issuing the 'stop' command using the simulator provides mixed results. when attempting to play movies a song will play, this I'd presume is because of the "matching" that occurs. In any case, I was able to reproduce the movie restarting when the command 'stop movie frozen' is issued at the simulator. The first command I issued was to play the movie 'play movie frozen' followed by the 'stop movie frozen'.

[2018-01-04 08:00:08 +0000] [13332] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled INFO:kodi_alexa.alexa:Playing movie INFO:kodi_voice.kodi:Searching for movie "frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} INFO:kodi_voice.kodi:Trying to match: frozen INFO:kodi_voice.kodi:Simple match on direct comparison INFO:kodi_voice.kodi:BEST MATCH: "Frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"item": {"movieid": 2222}, "options": {"resume": true}}, "jsonrpc": "2.0", "method": "Player.Open", "id": 1} INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"movieid": 2222, "properties": ["resume", "trailer"]}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "id": 1} [2018-01-04 08:01:14 +0000] [13328] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled INFO:kodi_alexa.alexa:Playing movie INFO:kodi_voice.kodi:Searching for movie "frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} INFO:kodi_voice.kodi:Trying to match: frozen INFO:kodi_voice.kodi:Simple match on direct comparison INFO:kodi_voice.kodi:BEST MATCH: "Frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"item": {"movieid": 2222}, "options": {"resume": true}}, "jsonrpc": "2.0", "method": "Player.Open", "id": 1} INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"movieid": 2222, "properties": ["resume", "trailer"]}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "id": 1}

jingai commented 6 years ago

It's not "stop movie frozen" -- it's just "stop".

jingai commented 6 years ago

If you want it to only search movies, you need to specify the media type in your command. Otherwise, yes, the skill will try its best to match against what it heard, which may not always be what you wanted.

We provide ways of 'drilling down' to the media type you want. You're free to start at any stage you like.

Alexa, ask Kodi to play Frozen

will search your entire library for the item that best matches Frozen. You can disable this functionality by setting the deep_search option to no.

Alexa, ask Kodi to watch Frozen

will search your video library for the item that best matches Frozen.

Alexa, ask Kodi to play the movie Frozen
Alexa, ask Kodi to watch the movie Frozen

will search only movies for the item that best matches Frozen.

islipfd19 commented 6 years ago

Thank you for this additional insight. I should be using 'watch' and not 'play'

A 'watch movie frozen' was issued followed by 'stop'. The movie kept playing.

[2018-01-04 08:26:40 +0000] [13332] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled INFO:kodi_alexa.alexa:Watch a video... INFO:kodi_alexa.alexa:Playing frozen INFO:kodi_alexa.alexa:Find and Play: "frozen" INFO:kodi_alexa.alexa:Pre-match with slot: Movie INFO:kodi_alexa.alexa:Searching content types: INFO:kodi_alexa.alexa:['video'] INFO:kodi_voice.kodi:Searching for movie "frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} INFO:kodi_voice.kodi:Trying to match: frozen INFO:kodi_voice.kodi:Simple match on direct comparison INFO:kodi_voice.kodi:BEST MATCH: "Frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"movieid": 2222, "properties": ["resume", "trailer"]}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "id": 1} INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"item": {"movieid": 2222}, "options": {"resume": true}}, "jsonrpc": "2.0", "method": "Player.Open", "id": 1} [2018-01-04 08:26:55 +0000] [13328] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled

Here I issued a 'stop movie frozen' The movie briefly stopped and then started to play from where it last played from. I also included my intents, utterances and slots files to help troubleshoot this matter.

[2018-01-04 08:29:55 +0000] [13332] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled INFO:kodi_alexa.alexa:Playing movie INFO:kodi_voice.kodi:Searching for movie "frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} INFO:kodi_voice.kodi:Trying to match: frozen INFO:kodi_voice.kodi:Simple match on direct comparison INFO:kodi_voice.kodi:BEST MATCH: "Frozen" INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"item": {"movieid": 2222}, "options": {"resume": true}}, "jsonrpc": "2.0", "method": "Player.Open", "id": 1} INFO:kodi_voice.kodi:Received request from device None INFO:kodi_voice.kodi:Sending request to http://192.168.1.160:8080/jsonrpc DEBUG:kodi_voice.kodi:{"params": {"movieid": 2222, "properties": ["resume", "trailer"]}, "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "id": 1}

orig_intents.txt orig_slots.txt orig_utterances.txt

digiltd commented 6 years ago

you still have your custom utterances

PlayMedia play {Movie}
PlayMedia stop {Movie}
PlayMedia pause {Movie}
PlayMedia restart {Movie}
jingai commented 6 years ago

play works as well, it just isn't as specific as watch. watch instructs the skill to only search your video library for an item. But if you say, Alexa, ask Kodi to play the movie Frozen, that will only search movies for it.

The distinction is that a 'generic' play command like Alexa, ask Kodi to play Frozen doesn't tell the skill what kind of media to look for, so it has to try to figure it out. If you use watch instead of play, it at least then knows to only look for something you can watch (i.e., a video). If you further add the movie to either play or watch, it then knows it's looking for only a movie.

But as for your troubles with stop.. again, you cannot say stop movie frozen. We use the standard Amazon built-in intent for stop, so you can use just stop or any synonym for that word that Amazon can handle.

islipfd19 commented 6 years ago

Thank you for pointing out my additional utterances and additional info with the differences between play and watch. I've removed extra utterances and tested the simulator again.

I started the movie by issuing 'watch the movie frozen'. I attempted to stop the movie using 'stop' and it continued to play. Only log info was this:

[2018-01-04 08:40:22 +0000] [13332] [DEBUG] POST / INFO:kodi_voice.cache:Initalizing INFO:kodi_voice.cache:Disabled

jingai commented 6 years ago

I and my family use the stop command on a daily basis -- I'm positive it's not broken.

I don't really know what to tell you other than to make absolutely sure you're using the stock code, utterances, intents, etc.

islipfd19 commented 6 years ago

the utterances and intents i provided is what I was using to test with (minus my additions of PlayMedia)..I'm using the master branch from GitHub not sure if that makes a difference.

jingai commented 6 years ago

What you posted doesn't match what's in the repo. Please revert all of your changes and use what we have provided.

islipfd19 commented 6 years ago

I have a question about the sample utterances in the repo. The skill wouldn't accept the text in it's current state; i.e. Home (/navigate/go) home, I had to type out each variation.

Home go home Home navigate home

jingai commented 6 years ago

You're using the wrong file.

The intents and utterances are in https://github.com/m0ngr31/kodi-alexa/tree/master/speech_assets

islipfd19 commented 6 years ago

I'll try those

jingai commented 6 years ago

The hyperlinks provided in the README always point to the latest files. Just use those.

jingai commented 6 years ago

Better?

islipfd19 commented 6 years ago

Mixed results.

jingai commented 6 years ago

If you're still having troubles, post on the forum and we can help you there.