// SHOUTcast XML to RSS
// Version 1.0
// Brad Parker 12-22-2004
// http://www.charminggeek.net
// portions of code borrowed from grabxml by tpepper
// Feed customization
// SET THESE VARIABLES
//
$homelink="http://www.charminggeek.net"; //this is the url for the entire feed
$streamtitle="TITLE FOR YOUR STREAM";
$streamdescription="DESCRIPTION FOR YOUR STREAM";
$password="SHOUTCAST PASSWORD";
$host="SHOUTCAST HOST";
$email="STREAM EMAIL";
$streamurl="URL OF STREAM"; //This is the url which will appear for each song
$port=8000;
//
//Globals (do not edit)
//
$in_date=0;
$rssOutput="";
$lastModifiedTimeStamp=0;
// these handlers essentially rename the xml elements and format the date
function startElement($parser, $name, $attrs) {
global $lastelem, $in_date, $rssOutput;
if($name=="SONG"){
$rssOutput.=" \n";
}else if($name=="PLAYEDAT"){
$in_date=1;
$rssOutput.=" ";
}else if($name=="TITLE"){
$rssOutput.=" ";
}
$lastelem='start';
}
function endElement($parser, $name) {
global $lastelem,$in_date,$rssOutput,$streamurl;
if($name=="SONG"){
$rssOutput.= " \n";
}else if($name=="PLAYEDAT"){
$in_date=0;
$rssOutput.= "\n";
}else if($name=="TITLE"){
$rssOutput.= "\n";
$rssOutput.= " $streamurl\n";
//add any other item specific elements here
}
}
function characterData($parser, $data) {
global $lastelem,$in_date,$rssOutput,$lastModifiedTimeStamp;
$data=trim($data);
if ($data) {
if($in_date){
if($lastModifiedTimeStamp==0){
$lastModifiedTimeStamp=$data;
}
$data = date('r',$data);
}
$rssOutput.= htmlspecialchars($data);
$lastelem='data';
}
}
// here we go
$lastelem="";
// connect to sc_serv
error_reporting(0);
$sp=fsockopen($host,$port,&$errno,&$errstr,20);
if(!$sp){
//hide error output from non-hax0rs
$rssOutput="";
}else{
set_socket_blocking($sp,false);
// send request
fputs($sp,"GET /admin.cgi?pass=$password&mode=viewxml&page=4 HTTP/1.1\nUser-Agent:Mozilla\n\n");
while (!feof($sp)) {
$sp_data.=fgets($sp, 1024);
}
// strip HTTP headers so all we have is XML data
$sp_data=ereg_replace("^.*<\?xml ","",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
/* Feel free to edit things below here. This is the output. However, try not to break
the RSS compliance. http://blogs.law.harvard.edu/tech/rss
*/
}
// close up rss
//provide header so this is interpreted as xml
header( "Content-Type: text/xml" );
header( "Last-Modified: ".gmdate('r',$lastModifiedTimeStamp));
header( "ETag: \"".gmdate('r',$lastModifiedTimeStamp)."\"");
// set up rss
echo "\n";
echo "\n";
echo " \n";
// add aditional tags here if you'd like
// see http://blogs.law.harvard.edu/tech/rss for specifications
echo " ".htmlspecialchars($streamtitle)."\n";
echo " ".htmlspecialchars($streamdescription)."\n";
echo " $homelink\n";
echo " $email\n";
echo " SHOUTcast\n";
echo " ",date('r',$lastModifiedTimeStamp),"\n";
echo " en-us\n";
echo $rssOutput;
echo " \n";
?>