Play Movies or TV Shows in Kodi with Natural Language commands using custom Types

Set your Kodi TVShow and Movie collection as Natural Language types so that you can easily play them

  1. joaomgcd
    In this example you're going to be creating new entities for Natural Language Commands:
    • movie: will contain all of your Kodi movies
    • tvshow: will contain all of your Kodi TV Shows
    Then you'll create a Natural Language command for each:
    • play movie
    • play tv show
    This will make sure that when you say the name of a movie, the play movie command will trigger (because the movie entity will contain that name) and when you say the name of a TV Show, the play tv show command will trigger (because the tvshow entity will contain that name).

    So, for example, if you say
    • play Lady and the Tramp you can trigger a profile in Tasker to play a movie by that name
    • play South Park you can trigger a different profile that will look up the first unplayed episode for that show and play it
    You'll need AutoXBMC for this which is an Alpha AutoApp. Download the AutoApps app and look in the Alphas section to get it.

    STEP 0 - SETUP YOUR API.AI ACCOUNT


    Make sure that you have setup your account and have configured AutoVoice to work with API.AI


    STEP 1 - CREATE MOVIE ENTITIES


    • Create a new Task and call it Set Media Contexts
    • Add an AutoXBMC Query action
    • Set it query Movies
    • Set the Max Nr of Results to a number that's sure to be bigger than the number of movies in your collection
    • Add a Flash action with the text %axlabels()
    • Add an AutoVoice Natural Language Context action
    • Under Entities set Entity Name to movie
    • Set Values set to %axlabels()


    STEP 2 - SET TV SHOW ENTITIES


    • Add another AutoXBMC Query action
    • Set it query TV Shows
    • Set the Max Nr of Results to a number that's sure to be bigger than the number of episodes in your collection (not tv shows, but individual episodes)
    • Enable Show Title in Fields to Get
    • Add a Flash action with %axshowtitle()
    • Add an AutoVoice Natural Language Context action
    • Under Entities set Entity Name to tvshow
    • Set Values set to %axshowtitle()
    • Run the task.
    (i) If you now check the Entities section in your agent in https://api.ai/ you'll see that the two new entities were created and that they contain the names of movies and tv shows in your collection. However, you'll see that the TV show list has a lot of duplicates. One for each episode to be exact. This happens because when you query XBMC it'll list all the episodes you have instead of just the names of the TV Shows. Let's get rid of the duplicates now.


    STEP 3 - DELETE DUPLICATE TV SHOW NAMES


    • Add an AutoTools Arrays Tasker action
    • Set the Input Arrays field to %axshowtitle()
    • Set the Output Names field to shows
    • Under Filtering enable Unique
    (i) This action will remove all the duplicates and save them in the new %shows() array
    /!\ You can't use the same array name as the output because the output has less items then the input. Because Tasker doesn't allow plugins to delete local variables you would still have all the old duplicates in the output if you did this. So always use a new array to store results if there are less outputs than inputs.
    • Move the AutoTools Arrays action so that it's used right after the AutoXBMC Query action
    • Change the Value in the AutoVoice Natural Language Context action to %shows()
    (i) If you now check your entities in https://api.ai/ you'll see that TV Shows are no longer duplicate


    STEP 4 - CREATE COMMAND TO WATCH MOVIE


    • Open the main AutoVoice app and then Natural Language -> Commands
    • Create a new command
    • Set commands like Watch Lady and the Tramp and Play Lady and the Tramp
    • Set responses like Watching Lady and the Tramp now
    • Select Lady and the Tramp and choose Create Variable
    • Set the variable name to movie and make it replace all instances of Lady and the Tramp with the variable
    • Tap the movie variable below and set it to the type User: Movie
    • Save the command


    STEP 5 - CREATE COMMAND TO WATCH TV SHOW


    Do the exact same thing you did for movies, but for TV Shows instead.


    STEP 6 - CREATE PROFILE TO PLAY MOVIE


    • In Tasker create a new profile with the AutoVoice Natural Language condition
    • Choose the play movie command
    • Notice how there's a movie variable available that you can use in the Task
    • In the Task flash the %movie variable to check that it's correctly set


    STEP 7 - PLAY MOVIE BY NAME


    • Start by setting %movie to the name of any movie in your library so you can easily test the task
    • Get the movie id by using an AutoXBMC Query action and querying your movies setting Filter 1 to Title Is %movie
    • Flash %axids1 to make sure that the first result has an ID
    • Add an AutoXBMC Control action
    • Set Media ID to %axids1
    • Set Media Type to Movie
    • Enable Resume
    (i) If you now run the task you should see the movie with the name you set as a test start to play on Kodi
    (i) If you back out of Tasker and say the Natural Language command it should start playing the movie you say in the command. Check here how to start natural language command voice recognition.


    STEP 8 - PLAY FIRST UNWATCHED TV SHOW BY NAME


    Follow the same procedure as above for TV shows.
    To get unwatched tv shows, filter the results by Play Count Is 0 as seen here (don't forget to only play if %axids1 is set. It will not be set if you don't have any unwatched episodes for the show):
    To get the first of these sort the results by Date Added as seen here:



    You'll now be able to just say watch lady and the tramp or watch south park and it'll know whether to play a movie or a tv show with that name based on the name you said :cool:
    Pete and Gman04 like this.