• 1
  • 6
  • 7
  • 8(current)
  • 9
  • 10
  • 16
Working JSON RPC API Examples
(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' }
Reply
You don't have to get all results, let Kodi do the work. The API supports some neat filters, the following should return one result with "minions" in the title. You could change the sort method to "dateadded" to get the most recently added or "year" to get the newest, lots of possibilities.

Code:
{"jsonrpc":"2.0","method":"VideoLibrary.GetMovies","id":"1484897668671","params":{"properties":["title"],"limits":{"start":0,"end":1},"sort":{"method":"title","order":"ascending","ignorearticle":true},"filter":{"operator":"contains","field":"title","value":"minions"}}}

http://kodi.wiki/view/JSON-RPC_API/v6#Li....Operators

Cool use of google home btw Wink
Author of Chorus
Reply
(2017-01-20, 09:46)jez500 Wrote: You don't have to get all results, let Kodi do the work. The API supports some neat filters, the following should return one result with "minions" in the title. You could change the sort method to "dateadded" to get the most recently added or "year" to get the newest, lots of possibilities.

Code:
{"jsonrpc":"2.0","method":"VideoLibrary.GetMovies","id":"1484897668671","params":{"properties":["title"],"limits":{"start":0,"end":1},"sort":{"method":"title","order":"ascending","ignorearticle":true},"filter":{"operator":"contains","field":"title","value":"minions"}}}

http://kodi.wiki/view/JSON-RPC_API/v6#Li....Operators

Cool use of google home btw Wink

Nice, thanks for the tip! I'll try to incorporate when I have some more time to sit and work my way through it.

The SmartThings hub is pretty awesome, there's a community-created rules engine for it called CoRE that's great for home automation, but also accepts incoming IFTTT Maker requests as a trigger and can be set to, among other things, make web requests as an associated action. I have an automation set up that is triggered by the incoming IFTTT request, then makes multiple web requests using 3 separate web services to wake up my Fire TV and launch Kodi (using adb commands), send the play command to Kodi, and launch the Fire TV activity on my Harmony hub.
Reply
What is wrong with this command, it t keeps giving me an error, all example give same code

I am trying to get the speed, i want to poll if the player is on play or pause mode, nothing more or less,
But what i try i keep getting the same 'error' that my parans are wrong, changed the id, playerid etc but nothing helps.
Using this on kodi v17

Code:
$jsonarr = array(
                "jsonrpc" => "2.0",
                "method" => "Player.GetProperties",
                "params" => array ( "playerid" =>1, "properties" => "speed" ),
                "id" => '1');
               
             var_dump(json_decode(curl_call ("http://".$ip."/jsonrpc?request=".json_encode($jsonarr)), true));

this is the respond i keep getting, no speed: (there is a movie running and the info is shown from that movie when i retrieve it using json)
Code:
array(3) {
  ["id"]=>
  int(0)
  ["jsonrpc"]=>
  string(3) "2.0"
  ["result"]=>
  array(1) {
    [0]=>
    array(2) {
      ["playerid"]=>
      int(1)
      ["type"]=>
      string(5) "video"
    }
  }
}
array(3) {
  ["error"]=>
  array(3) {
    ["code"]=>
    int(-32602)
    ["data"]=>
    array(2) {
      ["method"]=>
      string(20) "Player.GetProperties"
      ["stack"]=>
      array(3) {
        ["message"]=>
        string(28) "Invalid type string received"
        ["name"]=>
        string(10) "properties"
        ["type"]=>
        string(5) "array"
      }
    }
    ["message"]=>
    string(15) "Invalid params."
  }
  ["id"]=>
  string(1) "1"
  ["jsonrpc"]=>
  string(3) "2.0"
}
Reply
(2017-01-29, 23:06)B3rt Wrote: What is wrong with this command, it t keeps giving me an error, all example give same code

And what result do you get if you do:

"params" => array ( "playerid" =>"1", "properties" => "speed" ),
Add-on : Bluray iso utils Rewrite of BR_iso_enhancements
Add-on : BR_iso_Enhancements Give theatrical & directors cut from the same bluray iso each their own library entry, use bluray iso's of tv shows as if they are already ripped.
Reply
"params":{"playerid":1, "properties":["speed"]}
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
(2017-01-30, 03:03)Wimpie Wrote:
(2017-01-29, 23:06)B3rt Wrote: What is wrong with this command, it t keeps giving me an error, all example give same code

And what result do you get if you do:

"params" => array ( "playerid" =>"1", "properties" => "speed" ),

exactly the same, does not matter..

@rONniE
I use this in PHP, so the way ou displayed it is not correct for within PHP, it is exactly as i wrote it in the correct syntax for php
Reply
i don't speak php, hence i formatted it that way ;-)

either way, the 'properties' value needs to be a list (or whatever that type is called in php) and not a string.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
(2017-01-30, 11:34)ronie Wrote: i don't speak php, hence i formatted it that way ;-)

either way, the 'properties' value needs to be a list (or whatever that type is called in php) and not a string.

ok, but "properties":["speed"] translated to php is an array....
Maybe someone could give me the correct PHP syntax then?
Reply
as you said, it's an array. Have you tried with

Code:
$jsonarr = array(
                "jsonrpc" => "2.0",
                "method" => "Player.GetProperties",
                "params" => array ( "playerid" =>1, "properties" => array("speed") ),
                "id" => '1');

Huh
Reply
(2017-01-30, 12:08)joethefox Wrote: as you said, it's an array. Have you tried with

Code:
$jsonarr = array(
                "jsonrpc" => "2.0",
                "method" => "Player.GetProperties",
                "params" => array ( "playerid" =>1, "properties" => array("speed") ),
                "id" => '1');

Huh

Yep, this is the code:
Code:
$jsonarr = array(
                "jsonrpc" => "2.0",
                "method" => "Player.GetProperties",
                "params" => array ( "playerid" => 1, "properties" => array( "speed" )),
                "id" => 1);
And this is the answer
Code:
array(3) {
  ["error"]=>
  array(3) {
    ["code"]=>
    int(-32602)
    ["data"]=>
    array(2) {
      ["method"]=>
      string(20) "Player.GetProperties"
      ["stack"]=>
      array(3) {
        ["message"]=>
        string(28) "Invalid type string received"
        ["name"]=>
        string(8) "playerid"
        ["type"]=>
        string(7) "integer"
      }
    }
    ["message"]=>
    string(15) "Invalid params.

I really have no idea why this is not working....
Reply
It's clear from the error message. It isn't complaining anymore about the "properties" value (that now is correctly passed as array) but about the "playerid" value that is passed as string instead of numeric. If you read here -> http://stackoverflow.com/questions/13909...as-strings maybe the solution is to pass the flag JSON_NUMERIC_CHECK to the json_encode command if you have PHP >= 5.3.3
Reply
I do need a jsonrpc to start a radiochannel from my favourites in TuneIn. Someone who can help ?
Reply
Example to filter TVshows by path:
Code:
{
   "jsonrpc":"2.0",
   "params":{
      "sort":{
         "order":"ascending",
         "method":"title"
      },
      "filter":{
         "operator":"startswith",
         "field":"path",
         "value":"nfs://192.168.1.77/tvshows/"
      },
      "properties":[
         "title",
         "file"
      ],
      "limits":{
         "start":0,
         "end":400
      }
   },
   "method":"VideoLibrary.GetTVShows",
   "id":"libTvshows"
}

the output would be something like:
Code:
{
   "id":"libTvshows",
   "jsonrpc":"2.0",
   "result":{
      "limits":{
         "end":58,
         "start":0,
         "total":58
      },
      "tvshows":[
         {
            "file":"nfs://192.168.1.77/tvshows/24/",
            "label":"24",
            "title":"24",
            "tvshowid":44
         },
         {
            "file":"nfs://192.168.1.77/tvshows/30 Rock/",
            "label":"30 Rock",
            "title":"30 Rock",
            "tvshowid":62
         },
         {
            "file":"nfs://192.168.1.77/tvshows/American Horror Story/",
            "label":"American Horror Story",
            "title":"American Horror Story",
            "tvshowid":43
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Arrested Development/",
            "label":"Arrested Development",
            "title":"Arrested Development",
            "tvshowid":42
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Band of Brothers/",
            "label":"Band of Brothers",
            "title":"Band of Brothers",
            "tvshowid":41
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Battlestar Galactica (2003)/",
            "label":"Battlestar Galactica (2003)",
            "title":"Battlestar Galactica (2003)",
            "tvshowid":61
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Better Call Saul/",
            "label":"Better Call Saul",
            "title":"Better Call Saul",
            "tvshowid":40
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Bible/",
            "label":"The Bible",
            "title":"The Bible",
            "tvshowid":11
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Big Bang Theory/",
            "label":"The Big Bang Theory",
            "title":"The Big Bang Theory",
            "tvshowid":10
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Blackadder/",
            "label":"Blackadder",
            "title":"Blackadder",
            "tvshowid":39
         },
         {
            "file":"nfs://192.168.1.77/tvshows/O Bocas/",
            "label":"O Bocas",
            "title":"O Bocas",
            "tvshowid":19
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Breaking Bad/",
            "label":"Breaking Bad",
            "title":"Breaking Bad",
            "tvshowid":38
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Bridge (2011)/",
            "label":"The Bridge (2011)",
            "title":"The Bridge (2011)",
            "tvshowid":55
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Bridge (2013)/",
            "label":"The Bridge (2013)",
            "title":"The Bridge (2013)",
            "tvshowid":92
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Californication/",
            "label":"Californication",
            "title":"Californication",
            "tvshowid":37
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Dartacao e os Tres Moscaoteiros/",
            "label":"Dartacão e os Três Moscãoteiros",
            "title":"Dartacão e os Três Moscãoteiros",
            "tvshowid":36
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Dexter/",
            "label":"Dexter",
            "title":"Dexter",
            "tvshowid":35
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Duarte e Companhia/",
            "label":"Duarte E Companhia",
            "title":"Duarte E Companhia",
            "tvshowid":34
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Face Off/",
            "label":"Face Off",
            "title":"Face Off",
            "tvshowid":33
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Fargo/",
            "label":"Fargo",
            "title":"Fargo",
            "tvshowid":60
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Fawlty Towers/",
            "label":"Fawlty Towers",
            "title":"Fawlty Towers",
            "tvshowid":32
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Firefly/",
            "label":"Firefly",
            "title":"Firefly",
            "tvshowid":31
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Freaks and Geeks/",
            "label":"Freaks and Geeks",
            "title":"Freaks and Geeks",
            "tvshowid":30
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Fresh Prince of Bel-Air/",
            "label":"The Fresh Prince of Bel-Air",
            "title":"The Fresh Prince of Bel-Air",
            "tvshowid":8
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Friends/",
            "label":"Friends",
            "title":"Friends",
            "tvshowid":29
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Game of Thrones/",
            "label":"Game of Thrones",
            "title":"Game of Thrones",
            "tvshowid":28
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Herman Enciclopedia/",
            "label":"Herman Enciclopédia",
            "title":"Herman Enciclopédia",
            "tvshowid":27
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Homeland/",
            "label":"Homeland",
            "title":"Homeland",
            "tvshowid":26
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Homicide - Life On The Street/",
            "label":"Homicide: Life On The Street",
            "title":"Homicide: Life On The Street",
            "tvshowid":59
         },
         {
            "file":"nfs://192.168.1.77/tvshows/House of Cards/",
            "label":"House of Cards",
            "title":"House of Cards",
            "tvshowid":25
         },
         {
            "file":"nfs://192.168.1.77/tvshows/How I Met Your Mother/",
            "label":"How I Met Your Mother",
            "title":"How I Met Your Mother",
            "tvshowid":24
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Killing/",
            "label":"The Killing",
            "title":"The Killing",
            "tvshowid":54
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Lost/",
            "label":"Lost",
            "title":"Lost",
            "tvshowid":58
         },
         {
            "file":"nfs://192.168.1.77/tvshows/MacGyver/",
            "label":"MacGyver",
            "title":"MacGyver",
            "tvshowid":95
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Mad Men/",
            "label":"Mad Men",
            "title":"Mad Men",
            "tvshowid":23
         },
         {
            "file":"nfs://192.168.1.77/tvshows/MasterChef Australia/",
            "label":"MasterChef Australia",
            "title":"MasterChef Australia",
            "tvshowid":22
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Modern Family/",
            "label":"Modern Family",
            "title":"Modern Family",
            "tvshowid":98
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Monty Python's Flying Circus/",
            "label":"Monty Python's Flying Circus",
            "title":"Monty Python's Flying Circus",
            "tvshowid":21
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Mozart in the Jungle/",
            "label":"Mozart in the Jungle",
            "title":"Mozart in the Jungle",
            "tvshowid":96
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Mr. Robot/",
            "label":"Mr. Robot",
            "title":"Mr. Robot",
            "tvshowid":20
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Narcos/",
            "label":"Narcos",
            "title":"Narcos",
            "tvshowid":57
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Office/",
            "label":"The Office",
            "title":"The Office",
            "tvshowid":94
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Prison Break/",
            "label":"Prison Break",
            "title":"Prison Break",
            "tvshowid":18
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Rome/",
            "label":"Rome",
            "title":"Rome",
            "tvshowid":17
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Saved by the Bell/",
            "label":"Saved by the Bell",
            "title":"Saved by the Bell",
            "tvshowid":16
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Scream - The TV Series/",
            "label":"Scream: The TV Series",
            "title":"Scream: The TV Series",
            "tvshowid":56
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Seinfeld/",
            "label":"Seinfeld",
            "title":"Seinfeld",
            "tvshowid":15
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Sherlock/",
            "label":"Sherlock",
            "title":"Sherlock",
            "tvshowid":14
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Shield/",
            "label":"The Shield",
            "title":"The Shield",
            "tvshowid":53
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Six Feet Under/",
            "label":"Six Feet Under",
            "title":"Six Feet Under",
            "tvshowid":13
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Sopranos/",
            "label":"The Sopranos",
            "title":"The Sopranos",
            "tvshowid":6
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Supernatural/",
            "label":"Supernatural",
            "title":"Supernatural",
            "tvshowid":12
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Taboo (2017)/",
            "label":"Taboo (2017)",
            "title":"Taboo (2017)",
            "tvshowid":97
         },
         {
            "file":"nfs://192.168.1.77/tvshows/True Detective/",
            "label":"True Detective",
            "title":"True Detective",
            "tvshowid":2
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Tudors/",
            "label":"The Tudors",
            "title":"The Tudors",
            "tvshowid":5
         },
         {
            "file":"nfs://192.168.1.77/tvshows/Twin Peaks/",
            "label":"Twin Peaks",
            "title":"Twin Peaks",
            "tvshowid":1
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Walking Dead/",
            "label":"The Walking Dead",
            "title":"The Walking Dead",
            "tvshowid":4
         },
         {
            "file":"nfs://192.168.1.77/tvshows/The Wire/",
            "label":"The Wire",
            "title":"The Wire",
            "tvshowid":3
         }
      ]
   }
}
Image Image
Reply
Hello.

Any people could explain me why this give me error:

var url:String ='http://192.168.1.150:8080/jsonrpc?request={"jsonrpc": "2.0","id":1, "method": "Files.GetDirectory", "params": {"properties": "directory":"home", "media":"video"}}'

Inside videos --> Files --> Movies (This is the path)

ERROR:

{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

I am new and I not find all the tree of jason to understand..

Sorry my bad english.
Reply
  • 1
  • 6
  • 7
  • 8(current)
  • 9
  • 10
  • 16

Logout Mark Read Team Forum Stats Members Help
Working JSON RPC API Examples0
This forum uses Lukasz Tkacz MyBB addons.