PHP Wrapper for XBMC JSON-RPC and HTTP-API
#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
Reply
#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.
Reply
#18
Thumbs Up 
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.
Reply
#19
Wink 
Code updated.

Cheers,

Kai.
Reply
#20
cool Smile

Now compiling PHP... so I can test my own code too hehe
Reply
#21
Big Grin 
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.
Reply
#22
Hey, I've update my code. You have a pull request.
Reply
#23
alshain Wrote:Hey, I've update my code. You have a pull request.

Done!

Cheers mate,

Kai.
Reply
#24
cool Wink
Reply
#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
Reply
#26
Smile 
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.
Reply
#27
Hey there

Any plans to update this class to support EDEN?
Reply
#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:ConfusedetUrl($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).
Reply
#29
Thanks so much. You make it look so easy!
Reply
#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
Reply

Logout Mark Read Team Forum Stats Members Help
PHP Wrapper for XBMC JSON-RPC and HTTP-API2