PDA

View Full Version : Radio Stats Script +Rep



Jack!
21-07-2010, 12:53 PM
I need a working radio script, asap, with my new site the one i have no longer fits my requirements, i have searched the forum and Google, nothing i can find seems to work

+Rep for all helpful answers

Apolva
21-07-2010, 05:18 PM
See if this works:


<?php

///////////////////////////////////
// PHP Shoutcast stats script :) //
///////////////////////////////////

/////////////////////
// Configure below //
/////////////////////

$server_host=""; // Domain or IP of the shoutcast DNAS page.
$server_port=""; // Port of the shoutcast stream.
$server_pass=""; // Admin password for DNAS page.

$refresh=300; // Refresh every x seconds - 0 = disabled.

$message_offline = "There is currently nobody on air.";
$message_serverdown = "The radio server is unavailable.";

$listeners_total = true; // Show total listener count.
$listeners_unique = true; // Show unique listener count.

/////////////////////
// End of config //
/////////////////////

echo ($refresh==0?"":"<script>setTimeout('window.location.reload()',".($refresh*1000).");</script>");

$scfp = @fsockopen($server_host, $server_port, &$errno, &$errstr, 30);

if(!$scfp) die($message_serverdown);

$urlpass=urlencode($scpass);

// Get page using a socket connection.
$page="";
fputs($scfp,"GET /admin.cgi?mode=viewxml&pass=".urlencode($server_pass)." HTTP/1.0\r\nUser-Agent: Radio Stats (Mozilla Compatible)\r\n\r\n");
while(!feof($scfp))
{
$page .= fgets($scfp, 1000);
}

// Get info from page.
$loop = array("STREAMSTATUS", "BITRATE", "SERVERTITLE", "CURRENTLISTENERS", "REPORTEDLISTENERS", "MAXLISTENERS","PEAKLISTENERS", "BITRATE","SERVERGENRE","SERVERURL");
$y=0;
while($loop[$y]!='')
{
$pageed = preg_replace("`.*<$loop[$y]>`", "", $page);
$scphp = strtolower($loop[$y]);
$scinfo[$scphp] = preg_replace("`</$loop[$y]>.*`", "", $pageed);
if($loop[$y]=="SERVERGENRE"||$loop[$y]=="SERVERTITLE"||$loop[$y]=="SONGTITLE"||$loop[$y]=="SERVERTITLE") $scinfo[$scphp] = urldecode($scinfo[$scphp]);
$y++;
}

$pageed = preg_replace("`.*<SONGHISTORY>`", "", $page);
$pageed = preg_replace("`<SONGHISTORY>.*`", "", $pageed);
$songatime = explode("<SONG>", $pageed);
$r=1;

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

fclose($scfp);

if($streamstatus == "1")
{
echo "<table>
<tr>
<td><b>DJ:</b></td>
<td>$servertitle</td>
</tr>
<tr>
<td><b>Listeners:</b></td>
<td>".($listeners_total && $listeners_unique ? "$currentlisteners ($reportedlisteners unique)" : ($listeners_total ? $currentlisteners : $reportedlisteners))."</td>
</tr>
<tr>
<td><b>Song:</b></td>
<td>{$song[0]}</td>
</tr>
<tr>
<td><b>Quality:</b></td>
<td>{$bitrate}kbps</td>
</tr>
</table>";
}
else die($message_offline);
?>

Jack!
21-07-2010, 05:30 PM
See if this works:


<?php

///////////////////////////////////
// PHP Shoutcast stats script :) //
///////////////////////////////////

/////////////////////
// Configure below //
/////////////////////

$server_host=""; // Domain or IP of the shoutcast DNAS page.
$server_port=""; // Port of the shoutcast stream.
$server_pass=""; // Admin password for DNAS page.

$refresh=300; // Refresh every x seconds - 0 = disabled.

$message_offline = "There is currently nobody on air.";
$message_serverdown = "The radio server is unavailable.";

$listeners_total = true; // Show total listener count.
$listeners_unique = true; // Show unique listener count.

/////////////////////
// End of config //
/////////////////////

echo ($refresh==0?"":"<script>setTimeout('window.location.reload()',".($refresh*1000).");</script>");

$scfp = @fsockopen($server_host, $server_port, &$errno, &$errstr, 30);

if(!$scfp) die($message_serverdown);

$urlpass=urlencode($scpass);

// Get page using a socket connection.
$page="";
fputs($scfp,"GET /admin.cgi?mode=viewxml&pass=".urlencode($server_pass)." HTTP/1.0\r\nUser-Agent: Radio Stats (Mozilla Compatible)\r\n\r\n");
while(!feof($scfp))
{
$page .= fgets($scfp, 1000);
}

// Get info from page.
$loop = array("STREAMSTATUS", "BITRATE", "SERVERTITLE", "CURRENTLISTENERS", "REPORTEDLISTENERS", "MAXLISTENERS","PEAKLISTENERS", "BITRATE","SERVERGENRE","SERVERURL");
$y=0;
while($loop[$y]!='')
{
$pageed = preg_replace("`.*<$loop[$y]>`", "", $page);
$scphp = strtolower($loop[$y]);
$scinfo[$scphp] = preg_replace("`</$loop[$y]>.*`", "", $pageed);
if($loop[$y]=="SERVERGENRE"||$loop[$y]=="SERVERTITLE"||$loop[$y]=="SONGTITLE"||$loop[$y]=="SERVERTITLE") $scinfo[$scphp] = urldecode($scinfo[$scphp]);
$y++;
}

$pageed = preg_replace("`.*<SONGHISTORY>`", "", $page);
$pageed = preg_replace("`<SONGHISTORY>.*`", "", $pageed);
$songatime = explode("<SONG>", $pageed);
$r=1;

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

fclose($scfp);

if($streamstatus == "1")
{
echo "<table>
<tr>
<td><b>DJ:</b></td>
<td>$servertitle</td>
</tr>
<tr>
<td><b>Listeners:</b></td>
<td>".($listeners_total && $listeners_unique ? "$currentlisteners ($reportedlisteners unique)" : ($listeners_total ? $currentlisteners : $reportedlisteners))."</td>
</tr>
<tr>
<td><b>Song:</b></td>
<td>{$song[0]}</td>
</tr>
<tr>
<td><b>Quality:</b></td>
<td>{$bitrate}kbps</td>
</tr>
</table>";
}
else die($message_offline);
?>

Thanks +Rep but it didnt work, im on it now broadcasting, but that says server unavailable

EDIT:Gotta Spread Sorry

Calvin
21-07-2010, 08:43 PM
Thanks +Rep but it didnt work, im on it now broadcasting, but that says server unavailable

EDIT:Gotta Spread SorryThe stats above should work, your port may not have been opened, ask your host to open whatever port your radio is. :)

Jack!
21-07-2010, 09:23 PM
So the port need opening again? or? because i can DJ? +Rep :)

Apolva
21-07-2010, 11:09 PM
Sometimes web hosts filter outgoing connection from PHP scripts, contact your web host support and ask if there are any restrictions in effect.

Jack!
21-07-2010, 11:14 PM
is there another way to do it without doing that? Ive heard about exploding 7.HTML but i don't know how to go about it and would it actually work?

Apolva
21-07-2010, 11:25 PM
is there another way to do it without doing that? Ive heard about exploding 7.HTML but i don't know how to go about it and would it actually work?

The trouble is the PHP script cannot connect to the shoutcast server status page at all because it's being restricted, so 7.html would face the same problem. I think also 7.html contains less info but can't remember what.

You could always find someone you trust and ask them to host the script for you.

Jack!
22-07-2010, 12:00 AM
Were would it be restricted from, my host of my shoutcast host?

Apolva
22-07-2010, 12:06 AM
Were would it be restricted from, my host of my shoutcast host?
No, your webhost is restricting PHP usage on your account, most likely blocking access to ports other than port 80.

Jack!
22-07-2010, 12:23 AM
No, your webhost is restricting PHP usage on your account, most likely blocking access to ports other than port 80.

Ohh so what port would i need?

Apolva
22-07-2010, 12:53 AM
Ohh so what port would i need?

Whatever port you're using on your shoutcast server.

Jack!
22-07-2010, 01:24 PM
Whatever port you're using on your shoutcast server.

well, my host thinks its a problem with the script :|

Apolva
22-07-2010, 04:43 PM
well, my host thinks its a problem with the script :|

Try this very simple socket connection test.

If it doesn't work, it's your host's fault (it's harder for them to deny when they see such a basic script =])


<?php
$host = ""; // Shoutcast server address
$port = ""; // Shoutcast server port

$fp = fsockopen($host,$port,$errno,$errstr,30);

if (!$fp) die("Error: $errstr ($errno)");

echo "Connection successful! :)";

fclose($fp);

?>

Jack!
22-07-2010, 05:29 PM
Warning: fsockopen() [function.fsopen]: unable to connect to *REMOVED*:8003 (Connection timed out) in /home/REMOVED/public_html/tunesfm/stats.php on line 5
Error: Connection timed out (110)

Apolva
22-07-2010, 05:36 PM
Either you've got the address / port wrong for your shoutcast host, or your php access is restricted ;)

Jack!
22-07-2010, 05:49 PM
Either you've got the address / port wrong for your shoutcast host, or your php access is restricted ;)

Thing is my host are adamant its the script, they say there are no PHP limitations :| Anyone know a good free cpanel host? not paying for them no more

Trigs
22-07-2010, 06:21 PM
Don't ask them if it's a PHP limitation. Ask them if they are blocking port (insert your port here).

Want to hide these adverts? Register an account for free!