![]() |
|
XBMC-PHP-RPC - a PHP JSON-RPC library supporting HTTP and TCP - Printable Version +- XBMC Community Forum (http://forum.xbmc.org) +-- Forum: Help and Support (/forumdisplay.php?fid=33) +--- Forum: Supplementary Tools for XBMC (/forumdisplay.php?fid=116) +--- Thread: XBMC-PHP-RPC - a PHP JSON-RPC library supporting HTTP and TCP (/showthread.php?tid=90465) |
XBMC-PHP-RPC - a PHP JSON-RPC library supporting HTTP and TCP - Mindzai - 2011-01-13 18:04 I've been playing around with some ideas for XBMC projects in the last couple of days, and most of them required the use of a solid RPC wrapper in PHP, so I wrote the rather catchily titled xbmc-php-rpc. You can grab it via my GitHub: https://github.com/karlrixon/xbmc-php-rpc The wrapper supports HTTP, as well as TCP for those who wish to avoid the HTTP overhead. Usage is as simple as this: PHP Code: $params = array('host' => '192.168.0.123', 'port' => 9090);The README gives a bit more information: Code: xbmc-php-rpcI hope someone finds this useful. Any questions, just ask! P.S. I'll be very happy to hear of any bugs or suggestions - alshain - 2011-01-13 18:36 Hi This looks very nice. However, I think it is somewhat overengineered. The code is very well documented. Why create so many files that only contain an empty exception class when you're not using autoloading? I like that you use the different Exception classes though. Have a look here, for a much more straight-forward implementation for PHP: https://github.com/kaigoh/XBMC-PHP You will notice that there is a lot less code. I don't know why exactly uses so much more, perhaps it supports more things that the aforementioned implementation doesn't cover - I haven't looked at your code that closely. Maybe it is also, because of the overengineering - but that may be an "unfortunate" first impression. - Mindzai - 2011-01-13 23:25 Hi alshain, It's not really down the the library to autoload imo. I would assume that any project implementing it would have autoloading functionality, which would conflict with any included here. The reason for creating empty exception classes is to allow calling code to properly act on out-of-the-ordinary errors (ie, exceptions ). Of course I could just have everything throw a base Exception, but I don't think that would be helpful.I'm sorry you think its over engineered. I actually think it's pretty compact myself . I have taken a look at the code to which you linked. I agree it is more simple, but on the other hand it has fewer features (such as no TCP support, limited to single-level namespaces). Also bear in mind that xbmc-php-rpc lazy loads commands and namespaces, whereas the linked code creates objects for every possible command up front, which means that in practice there are actually considerably fewer class instances in scope at any given time with my code. I haven't benchmarked the two, but I would suspect that xbmc-php-rpc is actually more efficient, despite being more complex in terms of the code itself ![]() That's not to take anything away from kaigoh's code, there's a lot to be said for keeping things simple! - alshain - 2011-01-14 01:53 I know why you have empty Exception classes, that's why I said I like that you have them But I don't understand why every empty exception gets it's own file.I suspected it had less features, I just don't have a clue about what the XBMC API offers really - For example, I didn't know that you would need more "depth" to the namespaces, ( can easily be achieved through __get and a class recursively instantiating itself for example - and __get for the lazy-loading as well)I don't think this code will be a bottleneck though
- dann0 - 2011-01-25 12:27 Hi Mindzai, Thanks for taking the time to write this code, also for sharing it with us and a big thanks for your efforts with the documentation, you've done well!I tried to use your connection object via TCP and it seems to work well, i have only just started to muck around with it, but so far so good. I had only 1 hiccup and that was that i didnt see any call to include Client.php in the examples, TCPClient.php doesn't make a call but does require that it is loaded, so at first it didnt work, i added one line PHP Code: require_once 'plugins/XBMC/rpc/Client.php'; - Mindzai - 2011-01-25 12:39 Hi dann0 Glad it's working OK for you ![]() Thanks for the bug report, I've fixed the issue now. - dann0 - 2011-01-26 13:11 i'm a little confused by an error message i get when using AudioPlayer->PlayPause() the code i try is PHP Code: try {the error i get is Quote:Notice: Undefined index: id in /mnt/hostwebinc/plugins/XBMC/rpc/Response.php on line 25 Invalid JSON RPC response The reason i am confused is because from what i can see the index 'id' does exist at line 25 of response.php, i can print it at that point, so... i really don't get it! I'm hoping you can make sense of it Mindzai - Mindzai - 2011-01-26 14:01 Hi dann0 At first I couldn't replicate your issue using the HTTPClient, but then I tested with the TCPClient and indeed got the error you describe. The issue is that an announcement is sent over the socket indicating the occurrence of the play/pause event. I stupidly didn't account for this, and assumed that the next chunk of data sent over the socket would be the response. I have now fixed this bug; any data received via TCP which is not a response to the initial request is now ignored. In case you aren't using git to pull revisions, the files which have changed are: Client.php, HTTPClient.php and TCPClient.php. The change itself is here: https://github.com/karlrixon/xbmc-php-rpc/commit/fd1232559822dc9b27c678d3fa6ee5774a00a4c8 Thanks for reporting these bugs. I haven't been through and tested every method of the API yet so it's very useful feedback
- DKreeK - 2011-02-01 01:13 Hi, I'm testing the wrapper. I would like to recover all information about movies. This code work's fine : PHP Code: $params = 'xbmc:xbmc@192.168.0.55:8080';But, I don't kown how pass args. What is the equivalent of the following syntax? Code: {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "start": 0, "fields": ["genre", "director", "trailer", "tagline", "plot", "plotoutline", "title", "originaltitle", "lastplayed", "showtitle", "firstaired", "duration", "season", "episode", "runtime", "year", "playcount", "rating"] }, "id": 1}Thank's in advance - Mindzai - 2011-02-01 11:58 Hi DKreeK If you want to pass a single argument you can do that directly. For example: PHP Code: $response = $rpc->XBMC->SetVolume(75); If you want to pass multiple arguments you just need to wrap them in an array. For example, the call you posted could be made like this: PHP Code: $response = $rpc->VideoLibrary->GetMovies(array(I hope that helps
|