Page 1 of 1

[CODE] PHP Rest parsing for forum signatures!

PostPosted: Fri Sep 24, 2010 9:13 pm
by lucron
The idea is to create a dynamic forum signature showing currently playing information provided by Subsonic through the awesome REST API :)

Since this was requested in a thread a while back and nobody has gotten around to making a tutorial, I thought I'd post my code with some comments included. If you have any questions, post here :)

Example (not live):
Image

Code: Select all
<?

//Subsonic Account Information
$username = "admin";
$password = "";

//Path to your Subsonic
$subsonicpath = "http://www.domain.com/subsonic";

//Path to your signature image
$signaturepath = "images/signature.jpg";

//Font settings
$size = 4;
$x = 5; //X Position
$y = 97; //Y Position
$color = imagecolorallocate($img,255,255,255);

//Retrieve the XML output from REST
$xmlstr = simplexml_load_file("$subsonicpath/rest/getNowPlaying.view?u=$username&p=$password&v=1.3.0&c=forumsig");

//Retrieve Now Playing Information
$artist = $xmlstr->nowPlaying->entry[artist];
$title = $xmlstr->nowPlaying->entry[title];
$year = $xmlstr->nowPlaying->entry[year];
$bitrate = $xmlstr->nowPlaying->entry[bitRate];
$minutesago = $xmlstr->nowPlaying->entry[minutesAgo];

//Change header to jpeg, so browsers know that this is an image
header('Content-Type: image/jpeg');


$img = @imagecreatefromjpeg($signaturepath);


if ($artist && $title) //Check if a song is playing or not, if not, don't write anything!
   imagestring($img, $size,$x,$y, "Subsonic: $artist - $title ($minutesago min. ago)",$color);

imagejpeg($img);
imagedestroy($img);

?>

PostPosted: Wed Feb 02, 2011 5:20 pm
by peher
thanks !
very useful !

PostPosted: Wed Feb 23, 2011 3:51 pm
by donpearson
One thing to think of with this code is that it will just show the top player in the xml file, it will show what your playing if your the only one playing music or you was the first to start playing music.

here is the one im working on atm: http://forum.subsonic.org/forum/viewtop ... 2056#22056