PHP Wrapper for XBMC JSON-RPC and HTTP-API

  Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
alshain Offline
Senior Member
Posts: 145
Joined: Jul 2010
Reputation: 3
Post: #16
Hey, I've cleaned your script up a little.

I've removed the redundant config checking code mostly. Both classes now wrap an Xbmc object, which serves as a universal class to build the configuration and check whether the XBMC instance can be reached.
I've refactored the config processing as well, and should be easier now.
I now also throws custom exceptions.

https://gist.github.com/761851

GitHub's GISTs don't show diffs by defaults, but there are userscripts to do this for you. Alternatively you can just use a decent diff program or get the GIST's git repository.

Oh... and I should note that this is completely untested, it may even have syntax errors Smile
find quote
kaigoh Offline
Junior Member
Posts: 23
Joined: Jan 2009
Reputation: 0
Post: #17
alshain Wrote:Hey, I've cleaned your script up a little.

Thanks.

alshain Wrote:Oh... and I should note that this is completely untested, it may even have syntax errors Smile

It does have some errors, I haven't had time to correct them yet, I'm hoping to do that tomorrow.

I think I've figured out Subversion, too!

Cheers,

Kai.
find quote
kaigoh Offline
Junior Member
Posts: 23
Joined: Jan 2009
Reputation: 0
Thumbs Up  Update
Post: #18
After a tip from alshain, I've decided to move the project to GitHub.

https://github.com/kaigoh/XBMC-PHP

I have also repaired a bug that will cause a JSON-RPC error, so please grab the new code from GitHub.

Cheers,

Kai.
find quote
kaigoh Offline
Junior Member
Posts: 23
Joined: Jan 2009
Reputation: 0
Wink  Updated
Post: #19
Code updated.

Cheers,

Kai.
find quote
alshain Offline
Senior Member
Posts: 145
Joined: Jul 2010
Reputation: 3
Post: #20
cool Smile

Now compiling PHP... so I can test my own code too hehe
find quote
kaigoh Offline
Junior Member
Posts: 23
Joined: Jan 2009
Reputation: 0
Big Grin   
Post: #21
alshain Wrote:cool Smile

Now compiling PHP... so I can test my own code too hehe

Let me know how you get on!

I had a quick tidy up today with the code, I have moved some stuff around...see what you think?

Cheers,

Kai.
find quote
alshain Offline
Senior Member
Posts: 145
Joined: Jul 2010
Reputation: 3
Post: #22
Hey, I've update my code. You have a pull request.
find quote
kaigoh Offline
Junior Member
Posts: 23
Joined: Jan 2009
Reputation: 0
Post: #23
alshain Wrote:Hey, I've update my code. You have a pull request.

Done!

Cheers mate,

Kai.
find quote
alshain Offline
Senior Member
Posts: 145
Joined: Jul 2010
Reputation: 3
Post: #24
cool Wink
find quote
neus Offline
Junior Member
Posts: 1
Joined: May 2011
Reputation: 0
Post: #25
im trying to learn how this api works but cant get it to work right
the moviewall is showing now i want it to show just 1 movie

$xbmcJson->VideoLibrary->GetMovieDetails ? ?

someone can push me in the right direction ?

thx in advantage Smile
find quote
kaigoh Offline
Junior Member
Posts: 23
Joined: Jan 2009
Reputation: 0
Smile   
Post: #26
neus Wrote:im trying to learn how this api works but cant get it to work right
the moviewall is showing now i want it to show just 1 movie

$xbmcJson->VideoLibrary->GetMovieDetails ? ?

someone can push me in the right direction ?

thx in advantage Smile

Hi neus,

If you look at the code here:

PHP Code:
foreach($moviesRaw->movies as $movie) {
    
//Removes "The" from the movies title, for sorting reasons.
    
$title str_replace("The """$movie->label);
    
$movies[$title]['id'] = $movie->movieid;
    
$movies[$title]['title'] = $movie->label;
    
$movies[$title]['filename'] = $movie->file;
    
/*
    We need to check certain properties exist before referencing them,
    otherwise a notice will be generated by PHP due to a JSON-RPC error.
    */
    
if(property_exists($movie'thumbnail'))
        
$movies[$title]['thumbnail'] = $movie->thumbnail;
    if(
property_exists($movie'fanart'))
        
$movies[$title]['fanart'] = $movie->fanart;


You can see we have a variable $moviesRaw->movies that contains all of the movies in your library. To reference a particular movie, you would call $movieRaw->movies[x] (where x is the array key), i.e. $movieRaw->movies[0] would show the first movie in your collection.

HTH,

Kai.
find quote
rickrude Offline
Senior Member
Posts: 161
Joined: Jun 2011
Reputation: 0
Location: New Zealand
Post: #27
Hey there

Any plans to update this class to support EDEN?
find quote
ivarmedi Offline
Junior Member
Posts: 2
Joined: Dec 2011
Reputation: 0
Location: Sweden
Post: #28
rickrude Wrote:Hey there

Any plans to update this class to support EDEN?

It's just small changes that are needed. Here's a diff output:

[HTML]# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- W:\xbmc_remote\application\libraries\xbmc_2.php
+++ W:\xbmc_remote\application\libraries\xbmc_json.php
@@ -230,6 +230,7 @@
'id' => $uid
);

+ $json = array_filter($json);
$request = json_encode($json);

$ch = curl_init();
@@ -265,12 +266,12 @@

public function __construct(xbmcHost $xbmcHost) {
parent::setUrl($xbmcHost->url());
- $this->populateCommands($this->rpc("JSONRPC.Introspect")->commands);
+ $this->populateCommands($this->rpc("JSONRPC.Introspect")->methods);
}

private function populateCommands($remoteCommands) {
- foreach($remoteCommands as $remoteCommand) {
- $rpcCommand = explode(".", $remoteCommand->command);
+ foreach($remoteCommands as $cmd => $remoteCommand) {
+ $rpcCommand = explode(".", $cmd);
if(!class_exists($rpcCommand[0])) {
$this->$rpcCommand[0] = new xbmcJsonCommand($rpcCommand[0], parent::getUrl(), $this);
}
[/HTML]

I wrote a simple wrapper for CodeIgniter aswell, if someone is interested. Just let me know here (it's on another computer).
find quote
rickrude Offline
Senior Member
Posts: 161
Joined: Jun 2011
Reputation: 0
Location: New Zealand
Post: #29
Thanks so much. You make it look so easy!
find quote
smilykoch Offline
Junior Member
Posts: 5
Joined: Jan 2012
Reputation: 0
Post: #30
I know this post i old.. BUT!

could some1 please help me get this working with the current stable version of xbmcBuntu.. (EDEN?)?

I cant seem to get it working Sad..

the closest i can get is with the error:

Code:
Fatal error:  Uncaught exception 'XbmcException' with message 'Missing config key: host' in C:\xampp\htdocs\Remote\xbmc.php:126
Stack trace:
#0 C:\xampp\htdocs\Remote\xbmc.php(83): Xbmc->validateAndCleanConfig(Array)
#1 C:\xampp\htdocs\Remote\xbmc.php(196): Xbmc->__construct(Array)
#2 C:\xampp\htdocs\Remote\exampleMovieWall.php(11): XbmcJson->__construct(Array)
#3 {main}
  thrown in C:\xampp\htdocs\Remote\xbmc.php on line 126
find quote
Post Reply