PDA

View Full Version : ShoutCast Script Help


MarvinHalliwell
12-19-2005, 10:36 AM
i currently use shoutcast and i am wondering if its possible to have a script for my website that shows whats currently playing? and maybe how many listners?

Or is there a free online radio that you can do it with?

Osiris
12-19-2005, 11:58 AM
Hey there, I've got a script written to do that:

$host = "localhost"; // The address of your shoutcast server.
$pass = "blahblahblah"; // The admin password to your server.

$sock = fsockopen("localhost", 8000, &$errno, &$errstr, 30);
if(!$sock) {
$output = '<b>The server is currently down.</b>';
} else {
fputs($sock,"GET /admin.cgi?pass=$pass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
while(!feof($sock)) {
$page .= fgets($sock, 1000);
}

$loop = array("STREAMSTATUS", "BITRATE", "SERVERTITLE", "CURRENTLISTENERS");
$y=0;
while($loop[$y] != ''){
$pageed = ereg_replace(".*<$loop[$y]>", "", $page);
$scphp = strtolower($loop[$y]);
$$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);
if($loop[$y] == SERVERGENRE || $loop[$y] == SERVERTITLE || $loop[$y] == SONGTITLE || $loop[$y] == SERVERTITLE)
$$scphp = urldecode($$scphp);
$y++;
}

$pageed = ereg_replace(".*<SONGHISTORY>", "", $page);
$pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed);
$songatime = explode("<SONG>", $pageed);
$r = 1;
while($songatime[$r] != ""){
$t = $r - 1;
$playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);
$playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);
$song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);
$song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);
$song[$t] = urldecode($song[$t]);
$dj[$t] = ereg_replace(".*<SERVERTITLE>", "", $page);
$dj[$t] = ereg_replace("</SERVERTITLE>.*", "", $pageed);
$r++;
}
fclose($sock);
}

if($streamstatus == "1"){
foreach($song as $k => $v) {
if($v != '' && $k !== 0) {
$l++;
$songs .= ' <b>'.$l.'.</b>'.$song[$k]."<br>\n";
}
}

$output = <<<EOF
<center>
<font face="arial" size="2"><b>&nbsp;Server Name:</b>&nbsp;$servertitle</font><br><br>
<font face="arial" size="2"><b>&nbsp;Listeners:</b>&nbsp;$currentlisteners / 32</font><br><br>
<font face="arial" size="2" color=""><b>Current Song:</b> $song[0]</font><br>
</center>
<center>
<font face="arial" size="2"><b>Past Songs:</b></font>
<font color=""><font face="arial" size="2"><br>
$songs
</font>
<br>
</center>
EOF;
} else {
$output = '<b>The server is currently offline.</b>';
}

quocbao
12-20-2005, 04:02 PM
You can find many of these classes on http://phpclasses.org :)

MarvinHalliwell
12-21-2005, 11:41 AM
$host = "localhost"; // The address of your shoutcast server.

So with that would it be http://ip : port Soz no spaces cant do : and p togethor or u get :p

or just the ip alone?

By the way thanks for the script.

MarvinHalliwell
12-23-2005, 01:49 AM
I Put that code into dreamweaver under the code section to find that when i click preview i just see the code. Can anyone help?