<?php
/*
* Needed arguments:
* - XBMC ip, port, username:password
*/
$global_xbmc_ip = getArg('xbmc_ip');
$global_xbmc_port = getArg('xbmc_port');
$global_xbmc_userpass = getArg('xbmc_userpass');
/*
* Function
* Returns:
* The filename
* Argument:
* The file absolute path
*/
function sdk_getFilenameFromPath($path)
{
$ret = $path;
/* Linux style path */
$separatorPosition = strpos($ret, "/");
while($separatorPosition !== FALSE){
$ret = substr($ret, $separatorPosition+1);
$separatorPosition = strpos($ret, "/");
}
/* Windows style path */
$separatorPosition = strpos($ret, "\\");
while($separatorPosition !== FALSE){
$ret = substr($ret, $separatorPosition+1);
$separatorPosition = strpos($ret, "\\");
}
return $ret;
}
/*
* Global variable for what is playing
* Nothing by default
*/
$playing_now = "--";
/*
* Preparing XML response
*/
sdk_header('text/xml');
echo "<xbmc><error>";
/*
* Path to XBMC api
*/
$xbmc_http_path = "http://$global_xbmc_userpass@$global_xbmc_ip:$global_xbmc_port/jsonrpc";
/*
* Get the active players and current track
*/
$xbmc_active_player = NULL;
$xbmc_get_active = '?request={"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1}';
$response_string = httpQuery($xbmc_http_path.$xbmc_get_active, 'GET', NULL);
if($response_string != NULL) {
$response_decoded = sdk_json_decode($response_string);
if($response_decoded != NULL) {
foreach($response_decoded["result"] as $active) {
if($active["type"] == "audio") {
$xbmc_get_audio = '?request={"jsonrpc":"2.0","method":"Player.GetItem","params":{"properties":["title","album","artist","file"],"playerid":'.$active["playerid"].'},"id":"AudioGetItem"}';
$response_string = httpQuery($xbmc_http_path.$xbmc_get_audio, 'GET', NULL);
if($response_string != NULL) {
$response_decoded = sdk_json_decode($response_string);
if($response_decoded != NULL && $response_decoded["result"] != NULL) {
$item = $response_decoded["result"]["item"];
if($item != NULL) {
if($item["artist"] != NULL && $item["artist"][0] != NULL && $item["title"] != NULL){
$playing_now = $item["artist"][0]." - ".$item["title"];
}
else if($item["title"] != NULL){
$playing_now = $item["title"];
}
else if($item["file"] != NULL){
$playing_now = sdk_getFilenameFromPath($item["file"]);
}
}
}
}
break;
}
else if ($active["type"] == "video") {
$xbmc_get_video = '?request={"jsonrpc":"2.0","method":"Player.GetItem","params":{"properties":["title","season","episode","showtitle","file"],"playerid":'.$active["playerid"].'},"id":"VideoGetItem"}';
$response_string = httpQuery($xbmc_http_path.$xbmc_get_video, 'GET', NULL);
if($response_string != NULL) {
$response_decoded = sdk_json_decode($response_string);
if($response_decoded != NULL && $response_decoded["result"] != NULL) {
$item = $response_decoded["result"]["item"];
if($item != NULL) {
if($item["type"] == "episode"){
if($item["showtitle"] != NULL){
$playing_now = $item["showtitle"]." S".$item["season"]."E".$item["episode"];
}
else if($item["title"] != NULL){
$playing_now = $item["title"];
}
else if($item["file"] != NULL){
$playing_now = sdk_getFilenameFromPath($item["file"]);
}
}
else{
if($item["title"] != NULL){
$playing_now = $item["title"];
}
else if($item["file"] != NULL){
$playing_now = sdk_getFilenameFromPath($item["file"]);
}
}
}
}
}
break;
}
}
}
}
/*
* Finishing XML response
*/
echo "</error><playing>$playing_now</playing></xbmc>";
?>
<?php
/*
* Needed arguments:
* - XBMC ip, port, username:password
*/
$global_xbmc_ip = getArg('xbmc_ip');
$global_xbmc_port = getArg('xbmc_port');
$global_xbmc_userpass = getArg('xbmc_userpass');
/*
* Preparing XML response
*/
sdk_header('text/xml');
echo "<xbmc><error>";
/*
* Get the current volume on XBMC (step of 5)
*/
$xbmc_http_path = "http://$global_xbmc_userpass@$global_xbmc_ip:$global_xbmc_port/jsonrpc";
$xbmc_get_volume = '?request={"jsonrpc":"2.0","method":"Application.GetProperties","params":{"properties":["volume"]},"id":1}';
$response_string = httpQuery(trim($xbmc_http_path.$xbmc_get_volume), 'GET', NULL);
$volume_xbmc = 0;
if($response_string != NULL) {
$response_decoded = sdk_json_decode($response_string);
if($response_decoded != NULL) {
$volume_xbmc = $response_decoded["result"]["volume"] * 1;
$volume_modulo_5 = $volume_xbmc % 5;
switch ($volume_modulo_5) {
case 1:
$volume_xbmc -= 1;
break;
case 2:
$volume_xbmc -= 2;
break;
case 3:
$volume_xbmc += 2;
break;
case 4:
$volume_xbmc += 1;
break;
}
}
}
/*
* Finishing XML response
*/
echo "</error><volume>$volume_xbmc</volume></xbmc>";
?>
galaksy2001 a écrit:Je ne trouve pas la bonne syntaxe pour passer au titre suivant
http://<user>:<password>@<ip_xbmc>:<port>/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Player.GoTo%22,%22params%22:{%22playerid%22:1,%22to%22:%22next%22},%22id%22:1}
galaksy2001 a écrit:En fait cette API n'est plus valable ... retour case départ
Edit : j'ai enfin trouvé ! Pffffff,
Pour info ...
Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 1 invité