| Code:
|
$servers = array(
'servers' => array(
's8.viastreaming.net',
''
),
'ports' => array(
7240,
),
'passwords' => array(
'**********',
''
),
'hbw' => 'http://s8.viastreaming.net/7240/listen.asx', <---- Windows Media Player; note the /
'lbw' => 'http://s8.viastreaming.net:7240/listen.pls', <----- WinAMP Media Player; note the :
'lasttracks' => 5
);
$stationname = 'YOUR STATION NAME (Make sure its correct)'; // What is your station called?
$refreshtime = 60 * 3; // How often to refresh (seconds)
$content = "$stationname is not broadcasting"; // Default content.
require_once('includes/scxml.php');
require_once('config.php');
global $prefix, $dbi;
/* Function to fetch the info */
function getInfo($servers)
{
$server = new SCXML;
$listeners = 0;
$nowplaying = 'Nothing';
$peak = 0;
$max = 0;
while( $host = each($servers['servers']) )
{
$port = each($servers['ports']);
$password = each($servers['passwords']);
$server->set_host($host[1]);
$server->set_port($port[1]);
$server->set_password($password[1]);
if ($server->retrieveXML())
{
$nowplaying = urldecode($server->fetchMatchingTag("SONGTITLE"));
$listeners += $server->fetchMatchingTag("CURRENTLISTENERS");
$peak += $server->fetchMatchingTag("PEAKLISTENERS");
$max += $server->fetchMatchingTag("MAXLISTENERS");
$lasttracks = $server->fetchMatchingArray("TITLE");
}
}
$content .= "<b>Now Playing:</b><br><i>$nowplaying</i><br><b>Listeners:</b> ";
$content .= "<i>$listeners/$max</i><br><b>Peak:</b> <i>$peak</i><br><br>";
$content .= '<center>';
if( ($servers['hbw']=='') && ($servers['lbw']=='') )
{
$content.="<a href=http://$host[1]:$port[1]/listen.pls>Tune In</a>";
}
if( $servers['hbw'] <> '' )
{
$content.="<a href=".$servers['hbw'].">Play With: Windows Media Player</a><br>";
}
if( $servers['lbw'] <> '' )
{
$content.="<a href=".$servers['lbw'].">Play With: WinAMP Media Player</a><br>";
}
$content.='</center>';
if( $servers['lasttracks'] > 0 ) {
$max = $servers['lasttracks'];
if( count($lasttracks) < $max ) $max = count($lasttracks);
$content .= "<br><b>Last $max tracks:</b><br>";
for( $i=0; $i < $max; $i++ ) {
$content .= ($i + 1).". $lasttracks[$i]<br>";
}
}
return $content;
}
/* Function to cache the string $content */
function cacheInfo($content,$title)
{
global $dbi, $prefix;
$now = time();
$sql = "UPDATE ".$prefix."_blocks SET content='".$content."', time=".$now
." WHERE title='".$title."'";
sql_query($sql,$dbi);
}
/* Get Cached Content: */
$sql = "SELECT content,time FROM ".$prefix."_blocks WHERE title='".$title."'";
$result = sql_query($sql,$dbi);
$roottime = time() - $refreshtime;
if($result)
{
$row = sql_fetch_array($result, $dbi);
/* Check time! */
if( $row[1] < $roottime )
{
$content = getInfo($servers);
cacheInfo($content,$title);
}
else
{
$content = $row[0];
}
}
/* Otherwise, we have to fetch, and cache the details */
else
{
$content = getInfo($servers);
cacheInfo($content,$title);
}
?>
|