<?php
// Live 365 PHP song info script
// By Sam Storie <sstorie@d.umn.edu>
// Check out The Vibe at http://www.thevibe.ws to see this script in action!
//
// Requirements:
// PHP running on the web server
// The ability to use virtual includes(SSI) on your pages
//
// Description: This will poll the Live365 song_info cgi function and retrieve the
// information for the current song playing and print it out in plain english.
// One requirement is that the ID3 tag should be filled out correctly or else
// the wording will be goofy. You can edit the print-out as you wish though.
//
// To correctly run the script you need to call it with your handle name.
// This is done by using a virtual include on the html page you want the
// script to show the song info. But you need to change the $station variable
// below to your user name. It's done like this:
//
// <!--#inlcude virtual="SCRIPT_LOCATION"-->
//
// You may also use ?station=YOUR_HANDLE after the location of the script when you call the script.
//
// An example would be:
//
// <!--#inlcude virtual="/script/is/located/here/song_info.php3?station=username"-->
//
// This allows you to poll multiple stations with just one script like I do at The Vibe.
//
// I am by no means an good PHP programmer so if you find a better method to
// do what this does then please e-mail me and tell me. Also send me any problems
// you may have.
//
//
/
//Grab source code from the Live365 song directory and use the $station variable
if(!($myFile=fopen("http://www.live365.com/cgi-bin/song_info.cgi?handle=$station","r"))) {
echo "The song info is not available right now.";
exit;
}
/
//Grab source code from the Live365 song directory and use the $station variable
if(!($myFile=fopen("http://www.live365.com:89/pls/front?handler=playlist&cmd=view&handle=$station&site=..","r"))) {
echo "The song info is not available right now.";
exit;
}
// Read each line and add to $myLine
while(!feof($myFile)) {
$myLine .= fgets($myFile,255);
}
fclose($myFile);
// Extract everything needed for the first song info
$start="one:{";
$end="}";
// Get the info for the first song
$start_position=strpos($myLine, $start) + 5; / The '+5' offsets the start position to eliminate the "one:{" /
$end_position=strpos($myLine, $end);
$length=$end_position-$start_position;
$song_one=substr($myLine, $start_position, $length);
// Now chop it into an array
$song = explode("," , $song_one);
// Now strip out everything but the relevant info
for($i=0; $i < count($song); $i++) {
$start_position = strpos($song[$i], "\"") + 1;
$end_position = strrpos($song[$i], "\"");
$length = $end_position-$start_position;
$song[$i] = substr($song[$i], $start_position, $length);
}
// Display HTML if all info is present
// if the ID3 tag is all there then print out this
if($song[0] != "" && $song[1] != "" && $song[2] != "" && $song[3] != "") {
echo "Tune in now to hear <font color=\"#3333FF\"><b>$song[0]</b></font> from <font color=\"#3333FF\"><b>$song[1]</b></font>'s <font color=\"#3333FF\"><b>$song[2]</b></font>. The track is <font color=\"#3333FF\"><b>$song[3]</b></font> minutes long.";
}
// Now if there is no album then print out a message for a single
else if( $song[2] == "" && $song[0] != "" && $song[1] != "" && $song[3] != "") {
echo "Tune in to hear <font color=\"#3333FF\"><b>$song[0]</b></font> from <font color=\"#3333FF\"><b>$song[1]</b></font>. It's <font color=\"#3333FF\"><b>$song[3]</b></font> minutes long.";
}
// What if there is no song info? Then print that out
else if( $song[0] == "" && $song[1] == "" && $song[2] == "" && $song[3] == "" && $song[4] == "" && $song[5] == "") {
echo "The song info is not available right now.";
}
else {
// just print out the filename
echo "Tune in now to hear <font color=\"#3333FF\"><b>$song[5]</b></font>.";
}
?>