JSON-RPC version 7 and PHP
#1
Hi,
Im tring to control xbmc from php(to create some basicl functionality) and noticed the API docs are not complete
I basicly try to connect from a JSON-RPC wrapper but i get params array issues when there is no explanation regarding the vectors passed to the API
my code is:

require_once 'TCPClient.php';
$params = array
(
'host' => '192.168.1.102',
'port' => 9090,
'user' => 'xbmc',
'pass' => 'password'
);

try
{
$rpc = new XBMC_RPC_TCPClient($params);
} catch (XBMC_RPC_ConnectionException $e) {
die($e->getMessage());
}

when i run command that dont need args its ok aka

$response = $rpc->Application->Quit();

works

but this doesnt

$response = $rpc->Player->Open(array("name" => "/media/test/ANYTHING_ELSE/VIDEO_TS/VIDEO_TS.VOB"));
tried also
$response = $rpc->Player->PlayPause(array(array("playerid" => 0), array("id" => 1)));
and all sort of passing arrays but no luck

Any help would be apruciated.

Tnx,
Reply
#2
First of all there's no version 7 of the API yet. The latest version is version 6.0.0.
I don't know anything about your JSON-RPC wrapper so it's hard to say what the error is but if you pass parameters by name you can't pass them as an array, it needs to be an object. Furthermore in your example Player.Open has no parameter named "name" what you want is "file". So I suggest you start looking into how JSON-RPC works (at the base level not at your wrapper level) and take a closer look at the JSON-RPC API v6 documentation on the wiki.

PS: Please use the [ code ] BBcodes next time you post code snippets. That makes it much easier to read them.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#3
Tnx Monteles,
Yes my mistake(its v6 prodo)

After running

Code:
foreach ($response['methods'] as $command => $commandData)
    {
        printf(
            '<p><strong>%s</strong><br />%s</p>',
            $command,
            isset($commandData['description']) ? $commandData['description'] : ''
        );
        var_dump($commandData);
    }

I get this description regarding the array

Player.Open
Start playback of either the playlist with the given ID, a slideshow with the pictures from the given directory or a single file or an item from the database.

Code:
array(4) { ["description"]=> string(158) "Start playback of either the playlist with the given ID, a slideshow with the pictures from the given directory or a single file or an item from the database." ["params"]=> array(1) { [0]=> array(2) { ["name"]=> string(4) "item" ["type"]=> array(3) { [0]=> array(3) { ["additionalProperties"]=> bool(false) ["properties"]=> array(2) { ["playlistid"]=> array(2) { ["$ref"]=> string(11) "Playlist.Id" ["required"]=> bool(true) } ["position"]=> array(2) { ["$ref"]=> string(17) "Playlist.Position" ["default"]=> int(0) } } ["type"]=> string(6) "object" } [1]=> array(1) { ["$ref"]=> string(13) "Playlist.Item" } [2]=> array(3) { ["additionalProperties"]=> bool(false) ["properties"]=> array(3) { ["path"]=> array(2) { ["required"]=> bool(true) ["type"]=> string(6) "string" } ["random"]=> array(2) { ["default"]=> bool(true) ["type"]=> string(7) "boolean" } ["recursive"]=> array(2) { ["default"]=> bool(true) ["type"]=> string(7) "boolean" } } ["type"]=> string(6) "object" } } } } ["returns"]=> array(1) { ["type"]=> string(6) "string" } ["type"]=> string(6) "method" }
Player.
Reply
#4
Looking at it as a PHP object makes it very difficult to read the JSON schema definition. Take a look at the documentation on the wiki at http://wiki.xbmc.org/index.php?title=JSO...layer.Open
The best way to read the documentation there is to click on the "show" link of the "JSON Schema Description" below a method definition. There you'll get the JSON schema definition and not some vardump PHP output with a lot of noise. "name", "type" etc are part of the JSON schema description language and not an actual parameter value. For more information on how JSON schema works, please read http://tools.ietf.org/html/draft-zyp-json-schema-03
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#5
Tnx, Iv read http://wiki.xbmc.org/index.php?title=JSO...layer.Open but its still missing some info
And very unclaer regarding the methods.

So to simple play what would a json call will look like, i was thinking of
http://192.168.1.102:8080/jsonrpc?request={ jsonrpc 6.0, method Player.Open,params:{ path : /home/ran/anything_else.avi}}
But all it gets is
JSONRPC active and working
Reply
#6
I think you are confusing a few things. First you use some PHP JSON-RPC wrapper which uses a TCP connection to XBMC. Then you try to use the HTTP GET implementation. All of these implementations have certain things that you need to consider and they are all (more or less) listed on the wiki.

In general a request to play a certain file through JSON-RPC would be
Code:
{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "file": { "/path/to/some/file.mkv" } } }, "id": 1 }
If you want to pass that via the HTTP GET parameter "request" you need to URL encode that JSON-RPC request first and set it as the value of the "request" GET parameter.

Your last example shows that you don't really know how JSON-RPC works in general. Your example isn't even a valid JSON object. So please first take some time to read up on JSON, JSON-RPC and ideally on JSON schema which makes it easier to read our JSON-RPC API definition. The necessary links to the specifications of JSON-RPC and JSON schema are also on the wiki on JSON-RPC API (wiki).
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#7
Thanks, you right. I dont have much expirience with JSON-RPC
I know its different calls, im aware HTTP GET works diifrent as the TCP wrapper
I was looking for a way to bypass the wrapper and work with the API directly
so i wont have the extra code to worry about(bugs, version mismuch etc..)
Reply
#8
Montesele, btw where do you see on the wiki the "file" key
If im not mistaken JSON follow the key/value structure but i cant seem to find any "file" value on the wiki
you wrote:
{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "file": { "/path/to/some/file.mkv" } } }, "id": 1 }

and what is the id:1?

I arpuciate your help.
Reply
#9
Identification of sender. It is informative. You can use string like name of your script if I am not wrong.
Reply
#10
Sorry it should be
Code:
{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "file": "/path/to/some/file.mkv" } }, "id": 1 }
The "file" property is in the definition of the "Playlist.Item" which is referenced by the "item" parameter of Player.Open.

"id" is to uniquely identify a request because over TCP there's no guarantee for the order of the responses so if you send requests A, B and C in that order, the responses may come in order B, C, A so you need to know which request matches which response. But again, this is all explained in the JSON-RPC 2.0 specification. This is not really the place to ask such basic questions. Learning how JSON-RPC works in general is something everyone has to do by himself. I'm happy to answer questions when it comes to XBMC's JSON-RPC API but I'm no JSON/JSON-RPC/JSON schema teacher.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#11
Thanks, the wiki should update a little bit(not much) the item key for example.

Apruciate your help.
Reply
#12
Tnx Montesele, i know that. This is part of the learning curve.
Reply
#13
Just wanted to pitch in with my way of using Json with Frodo.

I use RestClient.class.php from http://www.phpclasses.org/browse/file/27523.html to communite.

E.g. Getting videoplayer ID I use.

Code:
$playerID = getVideoPlayerID();

public function getVideoPlayerID()    {
       $result = 0;
    $JSON = array(
        "jsonrpc"=>"2.0",
        "method"=>"Player.GetActivePlayers",
        "id"=>"1");

    $response = json_decode(RestClient::post("http://IP:PORT/jsonrpc",json_encode($JSON,true),"","","application/json")->getResponse(), true);
    if ($response["result"]!=null){
        $resultArray = ($response["result"][0]);
        $type = $resultArray["type"];
        if ($type=="video"){
                $result =  $resultArray["playerid"];
            }
        }
        return $result;
    }
Reply

Logout Mark Read Team Forum Stats Members Help
JSON-RPC version 7 and PHP0