XBMC-PHP-RPC - a PHP JSON-RPC library supporting HTTP and TCP

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
dann0 Offline
Junior Member
Posts: 29
Joined: Jan 2011
Reputation: 0
Post: #31
Hi Mindzai,

I was wondering if there be a new version of your wrapper for the new JSON-RPC API?

Also i spent some time this morning looking at my issue with the wrong albums being returned by AudioLibrary->GetAlbums(), and i have to say i'm pretty confused as to what is going on, i honestly don't know how to proceed, as far as i can tell the problem must be coming from the JSON-RPC API but if that is the case why does it only happen to me??

If you have a moment or two could you look at the output and maybe make a comment?

My test library has 12 albums, first the result of a AudioLibrary->GetAlbums() call with no param:
Code:
Array
(
    [albums] => Array
        (
            [0] => Array
                (
                    [albumid] => 1
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/80ff4ab6.tbn
                    [label] => Beats, Rhymes and Life
                    [thumbnail] => special://masterprofile/Thumbnails/Music/f/f7229512.tbn
                )

            [1] => Array
                (
                    [albumid] => 2
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/023f21fa.tbn
                    [label] => Chocolates and Cigarettes
                    [thumbnail] => special://masterprofile/Thumbnails/Music/6/68ce1b2b.tbn
                )

            [2] => Array
                (
                    [albumid] => 3
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/efb5feb7.tbn
                    [label] => The Rainwater LP
                    [thumbnail] => special://masterprofile/Thumbnails/Music/d/d8f88e44.tbn
                )

            [3] => Array
                (
                    [albumid] => 4
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/16e1d41c.tbn
                    [label] => Chasing The Dragon
                    [thumbnail] => special://masterprofile/Thumbnails/Music/a/a729bf8e.tbn
                )

            [4] => Array
                (
                    [albumid] => 5
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/5390dc46.tbn
                    [label] => Random Acts Of Kindness
                    [thumbnail] => special://masterprofile/Thumbnails/Music/e/e1d617b8.tbn
                )

            [5] => Array
                (
                    [albumid] => 6
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/369390a1.tbn
                    [label] => Like The Deserts Miss The Rain
                    [thumbnail] => special://masterprofile/Thumbnails/Music/4/4e1edf77.tbn
                )

            [6] => Array
                (
                    [albumid] => 7
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/9dddda93.tbn
                    [label] => All Day
                    [thumbnail] => special://masterprofile/Thumbnails/Music/d/de92f260.tbn
                )

            [7] => Array
                (
                    [albumid] => 8
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/3c90196e.tbn
                    [label] => Waiting For You...
                    [thumbnail] => special://masterprofile/Thumbnails/Music/b/b2b4c704.tbn
                )

            [8] => Array
                (
                    [albumid] => 9
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/a68c7fbe.tbn
                    [label] => Only By The Night
                    [thumbnail] => special://masterprofile/Thumbnails/Music/5/5d79c476.tbn
                )

            [9] => Array
                (
                    [albumid] => 10
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/d5e84e8a.tbn
                    [label] => Remain In Light
                    [thumbnail] => special://masterprofile/Thumbnails/Music/9/9eeac53b.tbn
                )

            [10] => Array
                (
                    [albumid] => 11
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/121caa73.tbn
                    [label] => DJ-Kicks - Daddy G
                    [thumbnail] => special://masterprofile/Thumbnails/Music/4/41d498af.tbn
                )

            [11] => Array
                (
                    [albumid] => 12
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/121caa73.tbn
                    [label] => Fabriclive 29 - Cut Copy
                    [thumbnail] => special://masterprofile/Thumbnails/Music/c/cdadf88d.tbn
                )

        )

    [end] => 12
    [start] => 0
    [total] => 12
)
now the array i send as arguments to the same call
Code:
Array
(
    [start] => 2
    [end] => 4
)
and finally the result of the call with the arguments included
Code:
Array
(
    [albums] => Array
        (
            [0] => Array
                (
                    [albumid] => 5
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/5390dc46.tbn
                    [label] => Random Acts Of Kindness
                    [thumbnail] => special://masterprofile/Thumbnails/Music/e/e1d617b8.tbn
                )

            [1] => Array
                (
                    [albumid] => 6
                    [fanart] => special://masterprofile/Thumbnails/Music/Fanart/369390a1.tbn
                    [label] => Like The Deserts Miss The Rain
                    [thumbnail] => special://masterprofile/Thumbnails/Music/4/4e1edf77.tbn
                )

        )

    [end] => 4
    [start] => 2
    [total] => 4
)

You can see from the second call the start value '2' is correct but the albumid of the items returned match items [4] and [5] which is not expected, the albumid's should match items [2] and [3].

At this point any feedback would be appreciated.
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #32
Hey Midzai,
Thanks a lot for this. Has been working relatively well with one exception. I'm trying to get the Movie library in alphabetical order but for some reason no matter what params I use it only gives me the same order (not-alphabetical). Am I doing something wrong?

PHP Code:
try{
    
$response $rpc->VideoLibrary->GetMovies(array("sortmethod"=> "title""sortorder"=> "descending"));
} catch (
XBMC_RPC_Exception $e) {
    die(
$e->getMessage());
}
echo 
'<pre>';print_r($response);echo '</pre>'
find quote
Romep Offline
Junior Member
Posts: 20
Joined: Feb 2011
Reputation: 0
Post: #33
There's a bug in TCPClient::sendRequest.

Code:
if (strpos($result, '"id" : "' . $rpcId . '"') !== false) {


Should be (there are no spaces around ':'):

Code:
if (strpos($result, '"id":"' . $rpcId . '"') !== false) {
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #34
gugahoi Wrote:Hey Midzai,
Thanks a lot for this. Has been working relatively well with one exception. I'm trying to get the Movie library in alphabetical order but for some reason no matter what params I use it only gives me the same order (not-alphabetical). Am I doing something wrong?

PHP Code:
try{
    
$response $rpc->VideoLibrary->GetMovies(array("sortmethod"=> "title""sortorder"=> "descending"));
} catch (
XBMC_RPC_Exception $e) {
    die(
$e->getMessage());
}
echo 
'<pre>';print_r($response);echo '</pre>'

Never mind, I figured out that "sortmethod" doesn't work with Dharma.
find quote
erhnam Offline
Team-XBMC Live Developer
Posts: 673
Joined: May 2009
Reputation: 2
Location: The Netherlands
Post: #35
I've done a similar thing. If you're interested you might want to take look at this:

http://forum.xbmc.org/showthread.php?tid=82520
find quote
Mindzai Offline
Fan
Posts: 333
Joined: Aug 2010
Reputation: 0
Post: #36
Romep Wrote:There's a bug in TCPClient::sendRequest.

Code:
if (strpos($result, '"id" : "' . $rpcId . '"') !== false) {


Should be (there are no spaces around ':'):

Code:
if (strpos($result, '"id":"' . $rpcId . '"') !== false) {

On my test system the response has spaces before and after the colon. Which version of XBMC are you using? I assume this is due to different XBMC versions.

I have updated the code for now to handle both situations anyway.
find quote
Mindzai Offline
Fan
Posts: 333
Joined: Aug 2010
Reputation: 0
Post: #37
gugahoi Wrote:Never mind, I figured out that "sortmethod" doesn't work with Dharma.

Sorry for the delay. Yes I found the same thing as you in my testing. Unfortunately I think the best solution would be to sort in the client code via usort.
find quote
Mindzai Offline
Fan
Posts: 333
Joined: Aug 2010
Reputation: 0
Post: #38
erhnam Wrote:I've done a similar thing. If you're interested you might want to take look at this:

http://forum.xbmc.org/showthread.php?tid=82520

Cool I'll have a look, thanks.
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #39
Mindzai Wrote:Sorry for the delay. Yes I found the same thing as you in my testing. Unfortunately I think the best solution would be to sort in the client code via usort.

No no there's no need for that. The correct syntax would be in this style
Code:
"sort": { "method": "videotitle" }

Another question I had: is this compatible with Nightly builds? If not, do you plan on updating it at all?

Thanks!
find quote
Mindzai Offline
Fan
Posts: 333
Joined: Aug 2010
Reputation: 0
Post: #40
gugahoi Wrote:No no there's no need for that. The correct syntax would be in this style
Code:
"sort": { "method": "videotitle" }

Ah excellent thanks for that. I really wish the JSON-RPC wiki was more informative!

Quote:Another question I had: is this compatible with Nightly builds? If not, do you plan on updating it at all?

Thanks!

My test system at work is currently XBMC PRE-10.5 r32807. I haven't tested against a more recent version yet, but I'll compile a nightly build and check things out. If it doesn't work I will be updating it so that it does, yes.
find quote
Mindzai Offline
Fan
Posts: 333
Joined: Aug 2010
Reputation: 0
Post: #41
OK I compiled the latest nightly and found that the new RPC implementation did break the library but it was fairly trivial to fix. The new version in git supports both implementations, though you obviously would need to adjust the client code (eg the parameter format) if you want to support both implementations in your own apps. To that end, the *Client classes now have an isLegacy() method which you can call to find out which RPC implementation is being used and adjust accordingly. The example script has been updated to use this method.
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #42
Mindzai Wrote:OK I compiled the latest nightly and found that the new RPC implementation did break the library but it was fairly trivial to fix. The new version in git supports both implementations, though you obviously would need to adjust the client code (eg the parameter format) if you want to support both implementations in your own apps. To that end, the *Client classes now have an isLegacy() method which you can call to find out which RPC implementation is being used and adjust accordingly. The example script has been updated to use this method.

AWESOME! Thanks for such a quick response! Will test it out with some nightlies and see if they work as expected.
find quote
Mindzai Offline
Fan
Posts: 333
Joined: Aug 2010
Reputation: 0
Post: #43
gugahoi Wrote:AWESOME! Thanks for such a quick response! Will test it out with some nightlies and see if they work as expected.

No problem Smile Let me know if you run in to any problems.
find quote
Romep Offline
Junior Member
Posts: 20
Joined: Feb 2011
Reputation: 0
Post: #44
gugahoi Wrote:
Code:
"sort": { "method": "videotitle" }

Are there any other sort methods? They are not documented on the JSON Wiki page.
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #45
Romep Wrote:Are there any other sort methods? They are not documented on the JSON Wiki page.

I'm not sure, I believe you're best option would be to go on IRC and ask there.

Regarding the Nightly compatibility, it seems like it's working as it should! Thanks for the great job!
find quote