• 1
  • 19
  • 20
  • 21(current)
  • 22
  • 23
  • 226
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC
Nick8888 Wrote:I'm currently trying to make the xbmc web interface available from my domain through an apache server. I've been successful in doing this for other programs such as sabnzbd, sick-beard, tvheadend, transmission and couchpotato.

Using the following code to set up a virtual host in apache

Code:
ProxyRequests Off

ProxyPass /xbmc/ http://localhost:8080/

<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPassReverse /xbmc/ /

I am able to access it at http://mydomain.com/xbmc/ (css and all) however I am unable to browse any of my content (movies, music etc) as the json calls must not be going to the right location or something. The same behaviour occurs when using the Xbmc Web Media Manager (XWMM) package as well.

Just wondering if you've had any success in achieving the json-rpc to work behind apache, if not I'll wait until development has finished before I request support.

EDIT: Okay I did a bit of mucking around and found I need to change all references to "/jsonrpc" to "/xbmc/jsonrpc/" any chance of a urlbase setting or something along those lines?

In the new web interface all paths are absolute, however I will look to make this configurable long term.
Reply
The JSON server doesn't seem to parse sets into seperate movies when sending them to a client:
Quote:29/08/10 18:29:03 - Response: {
"end": 1,
"movies": [
{
"file": "videodb://1/7/1/",
"label": "The Fast and the Furious",
"thumbnail": "special://masterprofile/Thumbnails/Video/c/c755305d.tbn"
}
],
"start": 0,
"total": 1
}

Now i'm not sure wether i should do something with this myself, or if it classifies as a bug/future request. Can someone please enlighten me on this one?
Reply
That looks as though it's returned a set. The set stuff happens at the same layer as the JSON API is fetching at, so the API doesn't know that it's received sets (and doesn't know what to do with them after that).

Not sure what makes the most sense - options are having it so you can then request the set, or "flattening" the sets so that all that happens is the client gets a list of movies and can then choose to flatten the sets client side should they want to.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
But is it possible to flatten the sets right now (client-side)? I wouldn't know how to request all the movies that are inside a set.
Reply
Hi, I'm working on my XBMCRepeat plugin for EventGhost.

I started to add some more functionality using the HTTP API, but as that is going away I'm trying this newfangled JSON-RPC.

I have gotten same stuff working, but now I'm stuck (hopefully its nothing embarrassing).

So I'm trying to use VideoPlaylist.Add to add a video file to the playlist in XBMC (Dharma Beta1)
The below command adds the "e:\test.avi" to the playlist and works, but there is no text, only an empty(blank) line when looking in the "Now playing" window.
Code:
{"params": {"file": "E:\\test.avi"}, "jsonrpc": "2.0", "method": "VideoPlaylist.Add", "id": 1}
The below is the result from VideoPlaylist.GetItems:
Code:
{
  "file" : "E:\\test.avi",
  "label" : "",
  "thumbnail" : "special://home/userdata/Thumbnails/Video/4/auto-455227d7.tbn"
}
So I figured I need to add a Label so I tried the below:
Code:
{"params": {"file": "E:\\test.avi", "label": "Test"}, "jsonrpc": "2.0", "method": "VideoPlaylist.Add", "id": 1}
Still works but still no label Sad

So can someone tell me what I'm doing wrong? and/or point me to some more reading material about the parameter syntax.

jonib
XBMC2, EventGhost plugin. Image
Reply
Hello,
I have a question regarding playlist support:
How Can I get the list of all play lists i.e. for Audio ?

Kind regards
Reply
jonib Wrote:Hi, I'm working on my XBMCRepeat plugin for EventGhost.

I started to add some more functionality using the HTTP API, but as that is going away I'm trying this newfangled JSON-RPC.

I have gotten same stuff working, but now I'm stuck (hopefully its nothing embarrassing).

So I'm trying to use VideoPlaylist.Add to add a video file to the playlist in XBMC (Dharma Beta1)
The below command adds the "e:\test.avi" to the playlist and works, but there is no text, only an empty(blank) line when looking in the "Now playing" window.
Code:
{"params": {"file": "E:\\test.avi"}, "jsonrpc": "2.0", "method": "VideoPlaylist.Add", "id": 1}
The below is the result from VideoPlaylist.GetItems:
Code:
{
  "file" : "E:\\test.avi",
  "label" : "",
  "thumbnail" : "special://home/userdata/Thumbnails/Video/4/auto-455227d7.tbn"
}
So I figured I need to add a Label so I tried the below:
Code:
{"params": {"file": "E:\\test.avi", "label": "Test"}, "jsonrpc": "2.0", "method": "VideoPlaylist.Add", "id": 1}
Still works but still no label Sad

So can someone tell me what I'm doing wrong? and/or point me to some more reading material about the parameter syntax.

jonib

Try using the webinterface branch, instead of adding things by path, add them by database id. Ideally all items should exist within the library.
Reply
Thanks for the reply.
Malard Wrote:Try using the webinterface branch,
Instead of Dharma Beta1? If so where to get binary? and I assume JSON-RPC support is better or why the webinterface branch?
Quote:instead of adding things by path, add them by database id. Ideally all items should exist within the library.
So I need to add the file to the library first? I don't see a command for that. And I can't assume the file is already in the library.

jonib
XBMC2, EventGhost plugin. Image
Reply
Hello all, I'm kinda new to this forum but I have been using XBMC for a few weeks now. I have started on a dedicated XBMC Jsonrpc class for php, but I can't figure out why it does not work 100%. My problem is that 9 out of 10 times my connection times out and in the log it says just:
"14:50:50 T:140333434550032 M:3258880000 NOTICE: WebServer: POST | /jsonrpc"
When it works I get a reponse after < 1 second and when it fails it loads for ~10 seconds.

Here is my code:
PHP Code:
class xbmcRPC {
    public function 
getMovie$ids = array( ), $params = array( ) )
    {
        if ( !
is_array$ids ) ) $ids = array( $ids );
        
        
$movies $this->request("VideoLibrary.GetMovies"$params);
                
        if(!empty(
$ids)) // Get movies in $ids
        
{
            
$return = array();
            foreach(
$movies["result"]["movies"] AS $movie)
                if(
in_array($movie["id"], $ids))
                    
$return movie;
            if(
count($return)>0)
                return 
$return;
            else
                return array(
"error" => "Movie not found");
        } 
// Get all movies
        
else    
            return 
$movies["result"]["movies"];
    }
    protected function 
request$method$params = array( ) )
    {
        
$this->id++;
        
$data = array("jsonrpc" => "2.0","method" => $method"id" => $this->id);
        
        if(
count($params) > 0)
            
$data["params"] = $params;
            
        
$data json_encode$data );
        
$opts = array( 'http' => array('user_agent'  => $_SERVER['HTTP_USER_AGENT'] ,'timeout' => '5','ignore_errors' => true,'method' => 'POST','content' => $data,'header' => 'Content-type: application/json'."\r\n"));
        
        if ( 
$this->username && $this->password )
            
$opts['http']['header'] .= sprintf"Authorization: Basic %s\r\n"base64_encode$this->username.':'.$this->password ) );
            
        
$stream stream_context_create$opts );
        
        if ( 
$fp fopen$this->url'r'false$stream ) ) {
            
$response '';
            while( 
$row fgets$fp ) ) {
                
$response.= trim$row )."\n";
            }
        }
        
        
$stream_meta stream_get_meta_data$fp );
        
fclose$fp );
        
        if(!
$fp)
            throw new 
xbmcRPCException'Unable to establish a connection to '$this->url);
        else if( 
$stream_meta['timed_out'] )
            throw new 
xbmcRPCException"Timed out connecting to " $this->url);
        else if( 
substr$stream_meta['wrapper_data'][0], 9) == "401" )
            throw new 
xbmcRPCException"Invalid username/password.");
        
                
        return 
json_decode$responsetrue );
    }
    public function 
__construct($url 'http://localhost:8080'$username "xbmc"$password null)
    {
        
$this->url $url;
        
$this->username $username;
        
$this->password $password;
        
        
ini_set ('user_agent'$_SERVER['HTTP_USER_AGENT']); 
    }
}
class 
xbmcRPCException extends Exception {
    public function 
__construct$message null$code 0Exception $previous null )
    {
        
parent::__construct$message$code );
    }

Reply
SGulseth Wrote:Hello all, I'm kinda new to this forum but I have been using XBMC for a few weeks now. I have started on a dedicated XBMC Jsonrpc class for php, but I can't figure out why it does not work 100%. My problem is that 9 out of 10 times my connection times out and in the log it says just:
"14:50:50 T:140333434550032 M:3258880000 NOTICE: WebServer: POST | /jsonrpc"
When it works I get a reponse after < 1 second and when it fails it loads for ~10 seconds.

Here is my code:
PHP Code:
class xbmcRPC {
    public function 
getMovie$ids = array( ), $params = array( ) )
    {
        if ( !
is_array$ids ) ) $ids = array( $ids );
        
        
$movies $this->request("VideoLibrary.GetMovies"$params);
                
        if(!empty(
$ids)) // Get movies in $ids
        
{
            
$return = array();
            foreach(
$movies["result"]["movies"] AS $movie)
                if(
in_array($movie["id"], $ids))
                    
$return movie;
            if(
count($return)>0)
                return 
$return;
            else
                return array(
"error" => "Movie not found");
        } 
// Get all movies
        
else    
            return 
$movies["result"]["movies"];
    }
    protected function 
request$method$params = array( ) )
    {
        
$this->id++;
        
$data = array("jsonrpc" => "2.0","method" => $method"id" => $this->id);
        
        if(
count($params) > 0)
            
$data["params"] = $params;
            
        
$data json_encode$data );
        
$opts = array( 'http' => array('user_agent'  => $_SERVER['HTTP_USER_AGENT'] ,'timeout' => '5','ignore_errors' => true,'method' => 'POST','content' => $data,'header' => 'Content-type: application/json'."\r\n"));
        
        if ( 
$this->username && $this->password )
            
$opts['http']['header'] .= sprintf"Authorization: Basic %s\r\n"base64_encode$this->username.':'.$this->password ) );
            
        
$stream stream_context_create$opts );
        
        if ( 
$fp fopen$this->url'r'false$stream ) ) {
            
$response '';
            while( 
$row fgets$fp ) ) {
                
$response.= trim$row )."\n";
            }
        }
        
        
$stream_meta stream_get_meta_data$fp );
        
fclose$fp );
        
        if(!
$fp)
            throw new 
xbmcRPCException'Unable to establish a connection to '$this->url);
        else if( 
$stream_meta['timed_out'] )
            throw new 
xbmcRPCException"Timed out connecting to " $this->url);
        else if( 
substr$stream_meta['wrapper_data'][0], 9) == "401" )
            throw new 
xbmcRPCException"Invalid username/password.");
        
                
        return 
json_decode$responsetrue );
    }
    public function 
__construct($url 'http://localhost:8080'$username "xbmc"$password null)
    {
        
$this->url $url;
        
$this->username $username;
        
$this->password $password;
        
        
ini_set ('user_agent'$_SERVER['HTTP_USER_AGENT']); 
    }
}
class 
xbmcRPCException extends Exception {
    public function 
__construct$message null$code 0Exception $previous null )
    {
        
parent::__construct$message$code );
    }


In Dharma and trunk the WebServer is not multithreaded, as such each call is blocking, any long requests cause other requests to timeout.

The webinterface branch has resolved this issue and will appear in trunk in due course.
Reply
jonib Wrote:Thanks for the reply.
Instead of Dharma Beta1? If so where to get binary? and I assume JSON-RPC support is better or why the webinterface branch?So I need to add the file to the library first? I don't see a command for that. And I can't assume the file is already in the library.

jonib

There is no pre-compiled binary for the webinterface branch, you will need to compile this manually for the time being.

Raise a trac ticket for exactly what you are trying to do, I will either provide a sample fragment of code on how to do what your wanting correctly, implement the feature you require, or explain why what you are trying to do wont be supported.

Thanks
Reply
Malard Wrote:There is no pre-compiled binary for the webinterface branch, you will need to compile this manually for the time being.
I assumed as much, so it wont help me until there is.
Quote:Raise a trac ticket for exactly what you are trying to do,
Hmm, I'm not sure a trac ticket is appropriate place to declare my desire to learn how to use the JSON-RPC API in XBMC Big Grin
Quote:I will either provide a sample fragment of code on how to do what your wanting correctly, implement the feature you require, or explain why what you are trying to do wont be supported.
I thought my post was clear of what I wanted, I guess not. Huh

I'm just trying to add a video file to the current playlist in XBMC via the VideoPlaylist.Add command, but the added entry doesn't get any label/title/text just an empty line.

I don't want any new functionality, I just want to know why my code doesn't work, if it's a bug in the command or the feature is not implemented or that I'm using the wrong syntax.

Image
There are two videos in this list, the second added with VideoPlaylist.Add command from my other post, both work to play the video. There just is no label.

jonib
XBMC2, EventGhost plugin. Image
Reply
jonib Wrote:I assumed as much, so it wont help me until there is.
Hmm, I'm not sure a trac ticket is appropriate place to declare my desire to learn how to use the JSON-RPC API in XBMC Big Grin
I thought my post was clear of what I wanted, I guess not. Huh

I'm just trying to add a video file to the current playlist in XBMC via the VideoPlaylist.Add command, but the added entry doesn't get any label/title/text just an empty line.

I don't want any new functionality, I just want to know why my code doesn't work, if it's a bug in the command or the feature is not implemented or that I'm using the wrong syntax.

Image
There are two videos in this list, the second added with VideoPlaylist.Add command from my other post, both work to play the video. There just is no label.

jonib


Thanks, probably me being a bit dumb in not translating your post; I will look into this probably sooner rather than later as I am writing the video management section of the web interface (basics of audio is now sorted)

This is most likely a bug, infact an empty label in a playlist item is something we dont want in the GUI anyway, it should read '<no label>' at the very least so the user is aware something is there.

Raise a trac ticket for that.
Reply
Malard Wrote:Raise a trac ticket for that.
I have made a ticket here. Hopefully I added all relevant info.

jonib
XBMC2, EventGhost plugin. Image
Reply
Does anyone know how you play all the songs on an album in order of tracknumber?

I can add the album to an AudioPlaylist and then play it with the commands below but it only sorts the songs in order of title A-Z.

Code:
{"id":1,"jsonrpc":"2.0","method":"AudioPlaylist.Add","params":{"albumid":96}}

{"id":2,"jsonrpc":"2.0","method":"Audioplaylist.Play"}

Adding Sort parameters to the Playlist.Add seems to have no effect.

Do I just have to retrieve all the songs and then manually add them to the playlist in my desired order?
I can retrieve an album's songs in tracknumber order with:

Code:
{"id":3,"jsonrpc":"2.0","method":"AudioLibrary.GetSongs",
            "params":{"albumid":96, "sort":{"method":"track"}}}
Reply
  • 1
  • 19
  • 20
  • 21(current)
  • 22
  • 23
  • 226

Logout Mark Read Team Forum Stats Members Help
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC8