2017-01-20, 04:26
(2017-01-03, 00:54)Happyoldguy Wrote:(2017-01-02, 07:12)life02 Wrote:(2017-01-02, 04:04)Happyoldguy Wrote: Thanks Jonib
I do see that in the JSON-RPC Wiki. what about tagging? I'm working on IFTTT with Google assistant and would like to say "Ok Google" I want to watch <movie name>. I'm working on a python script to handle the GET from IFTTT and process the the suggestion you had.
Thanks for the input.
Happyoldguy, yeah that's exactly what I was trying to do without making an intermediary script for mapping name to id.
jonib, Thanks, I'll look into VideoLibrary.GetMovies.
Ok so last night I dabbled with VideoLibrary.GetMovies and this seems to work to get me the file of the movie by title. Now I need to see how to make this work. If you come up with something please let me know. If I get the solution Ill let you know here.
Code:http://192.168.15.117/jsonrpc?request={"jsonrpc": "2.0", "params": {"sort": {"order": "ascending", "method": "title"}, "filter": {"operator": "is", "field": "title", "value": "<movie title here>"}, "properties": ["title", "art", "file"]}, "method": "VideoLibrary.GetMovies", "id": "libMovies"}
I got something like this working in node.js, it takes an incoming GET request, extracts the movie title, looks it up in the Kodi library, gets the associated MovieId, then sends the play command. I've just recently started teaching myself javascript but this has been working for me. See here if you're interested: https://github.com/destructure00/kodi-lookup
Code:
var express = require('express');
var app = express();
var request = require('request');
const serverPort = 8078;
app.get('/kodi-lookup', function (req, res) {
if (!req.query) return res.sendStatus(400)
console.log(req.query);
var movie_title = req.query.movie_title.toLowerCase().replace('the ','');
var kodi_ip = req.query.kodi_ip;
if (movie_title && kodi_ip){
res.send('Searching for ' + movie_title + ' on ' + kodi_ip);
console.log('Searching for ' + movie_title + ' on ' + kodi_ip);
var options = {
uri: 'http://'+kodi_ip+':8080/jsonrpc?request={"jsonrpc":"2.0", "method":"VideoLibrary.GetMovies", "id":1}',
method: 'GET',
json: true
};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
var jsonBody = JSON.stringify(body);
console.log(jsonBody);
var nameList = jsonBody.split('"label":"');
console.info("Found " + nameList.length + " movies in library");
var movieCount = nameList.length;
var i;
for(i = 0; i < movieCount; i++) {
var endPos = nameList[i].indexOf('"');
nameList[i] = nameList[i].substring(0,endPos).toLowerCase().replace('the ','');
console.info(nameList[i]);
}
var movieId = nameList.indexOf(movie_title);
console.info("Found match, movieId: " + movieId);
play(kodi_ip, movieId);
}
});
}else{
res.send('Error');
}
})
app.listen(serverPort);
console.log("Listening on port "+serverPort);
function play (kodi_ip, movieID) {
var options = {
uri: 'http://'+kodi_ip+':8080/jsonrpc?request={"jsonrpc":"2.0", "method":"Player.Open", "id":1,"params":{"item":{"movieid":' + movieID + '}}}',
method: 'GET',
json: true
};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Sending play command to " + kodi_ip);
console.log(body);
}
});
}
As for the trigger, I'm using Google Home -> IFTTT -> SmartThings hub -> node.js app, where the SmartThings hub is acting as the intermediary between the internet and my local network. If you can get something to trigger the request on your local network, the request would look like this:
Code:
http://192.168.0.110:8078/kodi-lookup?movie_title=minions&kodi_ip=192.168.0.113
HTTP response looks like this:
Code:
Searching for minions on 192.168.0.113
Console response looks like this:
Code:
Listening on port 8078
{ movie_title: 'minions', kodi_ip: '192.168.0.113' }
Searching for minions on 192.168.0.113
{"id":1,"jsonrpc":"2.0","result":{"limits":{"end":23,"start":0,"total":23},"movies":[{"label":"Cars","movieid":1},{"label":"Cars 2","movieid":2},{"label":"Despicable Me","movieid":3},{"label":"Despicable Me 2","movieid":4},{"label":"Finding Dory","movieid":5},{"label":"Finding Nemo","movieid":6},{"label":"Inside Out","movieid":7},{"label":"Lady and the Tramp","movieid":8},{"label":"Minions","movieid":9},{"label":"Frozen","movieid":10},{"label":"Planes","movieid":11},{"label":"Storks","movieid":12},{"label":"The Accountant","movieid":13},{"label":"The Girl on the Train","movieid":14},{"label":"The Hunt for Red October","movieid":15},{"label":"The Intervention","movieid":16},{"label":"The Secret Life of Pets","movieid":17},{"label":"Toy Story","movieid":18},{"label":"Toy Story 2","movieid":19},{"label":"Toy Story 3","movieid":20},{"label":"Joy","movieid":21},{"label":"Tangled","movieid":22},{"label":"Big Hero 6","movieid":23}]}}
Found 24 movies in library
{
cars
cars 2
despicable me
despicable me 2
finding dory
finding nemo
inside out
lady and tramp
frozen
minions
planes
storks
accountant
girl on the train
hunt for red october
intervention
secret life of pets
toy story
toy story 2
toy story 3
joy
tangled
big hero 6
Found match, movieId: 9
Sending play command to 192.168.0.113
{ id: 1, jsonrpc: '2.0', result: 'OK' }