Kodi Community Forum
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (https://forum.kodi.tv/forumdisplay.php?fid=174)
+---- Thread: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC (/showthread.php?tid=68263)



- erhnam - 2010-09-28

I want to program a php front end to control my XBMC machine. Can anyone here provide me with an example on how to start on this? I tried to capture the result of the GetShares but the array doesn't look very nice. Anyone here knows how to do this so I can use functions like explode and trim.

Code:
<?php
$array = file_get_contents('http://localhost:9019/xbmcCmds/xbmcHttp?command=GetShares(video)');
echo $array;
?>



- MKay - 2010-09-28

I think you are using the old HTTP-API.
The JSON-RPC-API requires that you send a POST-Request with JSON-formatted data.
Have a look at the JavaScript-code of AWX :-)


- erhnam - 2010-09-28

Got my first call with php working Smile

Code:
<?php
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_URL, 'http://localhost:9019/jsonrpc');

  //prepare the field values being posted to the service

  $data = '{"jsonrpc": "2.0", "method": "JSONRPC.Version", "id": 1}';
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

  //make the request
  $result = curl_exec($ch);
  echo print_r($data,1); // debugging
  echo print_r($result,1); // debugging
?>



Append fixed value - pfeifer - 2010-09-29

There is anyway to append at the response a fixed value?

Code:
Code:
HTTP request: {
    id = 0;
    jsonrpc = "2.0";
    method = "VideoLibrary.GetSeasons";
    params =    {
        fields =        (
            season
        );
         [color=red]XXXXXX[/color]
        sortmethod = season;
        sortorder = ascending;
        tvshowid = 12;
    };

For have the followinf response
Code:
JSON result: {
    id = 0;
    jsonrpc = "2.0";
    result =    {
        end = 10;
        seasons =        (
                        {
                label = "Season 1";
                season = 1;
                thumbnail =  [color=red]XXXXXX[/color]special://masterprofile/Thumbnails/Video/9/9bb2a0cd.tbn";
            },
                        {
                label = "Season 10";
                season = 10;
                thumbnail = " [color=red]XXXXXX[/color]special://masterprofile/Thumbnails/Video/6/68c4506f.tbn";
            },
                        {
                label = "Season 2";
                season = 2;
                thumbnail = " [color=red]XXXXXX[/color]special://masterprofile/Thumbnails/Video/9/96f18614.tbn";
            },
        );
        start = 0;
        total = 3;
    };
}

Thanks in advance
Pfeifer


- dstruktiv - 2010-09-29

pfeifer Wrote:There is anyway to append at the response a fixed value?

Thanks in advance
Pfeifer

That's what ID is for, differentiating request/response pairs. Otherwise if it's not for identification then you would append the value AFTER the response comes back.


- jitterjames - 2010-09-29

is JSON supported in this version:
xbmc-r33778-Dharma_beta2.exe ?

If so, is there anything that I need to do to turn it on, or configure it, or does it use the same settings at the http api on xbmc's system / network window?

it seems that nightly builds are currently disabled. I am not interested in building xbmc myself, but I would like to start playing with json since I am currently using the http-api and would like to move forward when the time comes...

thanks.


Info on params - pfeifer - 2010-09-29

I am working very happy with JsonRpc.

I need to know the workaround for have only the album_artist and not all the artists included for e.g. in compilation where the album_artist is in my case "Various Artists".

How may I modify the following code?

Code:
{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": { "start": 0, "sort": { "order": "ascending", "method": "artist" } }, "id": 1}

Thanks
Sandro


- MKay - 2010-09-29

jitterjames Wrote:is JSON supported in this version:
xbmc-r33778-Dharma_beta2.exe ?

If so, is there anything that I need to do to turn it on, or configure it, or does it use the same settings at the http api on xbmc's system / network window?
yes, the Dharma beta2 has JSON-support.
You need to enable the webserver like you do with the old http-api.


- jitterjames - 2010-09-29

thanks Mkay. Big Grin Got it working now with xbmc remote 0.3 on same machine as xbmc. Hopefully it'll work as well through the lan. I just needed confirmation, because I thought I already had that version of xbmc installed, but apparently I did not!


- erhnam - 2010-09-30

Do you know if this is working or not:

Code:
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlaylist.Add", "file": "/home/xbmc/Music/Alternative Singles/Air - All I Need.mp3", "id": 1}' http://localhost:9019/jsonrpc

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlaylist.GetItems", "id": 1}' http://localhost:9019/jsonrpc

I tried this but the output is always zero, while the response of the first command is:

Code:
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : "OK"
}

return playlist:

Code:
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "end" : 0,
      "start" : 0,
      "total" : 0
   }
}

Fixed it. Should be:

Code:
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlaylist.Add", "params": { "file": "/home/xbmc/Music/Adele - 19/101-adele-daydreams.mp3"}, "id": 1}' http://localhost:9019/jsonrpc



- Anastrophe - 2010-09-30

<oops wrong post>


- erhnam - 2010-09-30

A question;

When I select the song of an album I also want to queue the rest of the songs. How do you deal with that? The song has a songid, so I can I do a for each to queue every other song with a higher songid? Or do I have problems then with names and the order of the songs? What's the best approach for this?


- dstruktiv - 2010-09-30

erhnam Wrote:A question;

When I select the song of an album I also want to queue the rest of the songs. How do you deal with that? The song has a songid, so I can I do a for each to queue every other song with a higher songid? Or do I have problems then with names and the order of the songs? What's the best approach for this?

Song has an album attribute I think. Use that.


- jitterjames - 2010-09-30

Will the JSON interface allow calling a script with an argument?

I could never get that to work with the http interface, and it would be really sweet!


- topfs2 - 2010-10-01

jitterjames Wrote:Will the JSON interface allow calling a script with an argument?

I could never get that to work with the http interface, and it would be really sweet!

At some point yeah, I can't see why not.

The reason for it not being there now is mostly that security, while more or less implemented, isn't really turned on. So all insecure stuff (like calling script, alter library) haven't been added yet.