TinyPortal

Development => Block Codes => Topic started by: Zetan on April 25, 2008, 12:33:13 PM

Title: Radio Stream Status Indicator - On Air / Off Air [Shoutcast / IceCast]
Post by: Zetan on April 25, 2008, 12:33:13 PM
This is an Online / Offline Status Indicator for Shoutcast / Icecast audio streams.
The original Request is HERE (http://www.tinyportal.net/index.php?topic=23521.0).

The original source of the code can be found HERE (http://www.streamsolutions.co.uk/index.php?page=scripts) at my stream hosting company, Stream Solutions.

I have stripped the original code to display no other details than the Stream Status, Online and Offline, the original script has listener count, current track etc.. I didn't need those details as I use other scripts.




There are 5 parts:


The files need to be created by you and uploaded to the root directory of your server, along with the 2 images.
You need to edit the details to match the stream configuration.




Block Snippet

Block type: script block


<iframe name="AnyNameHere" src="radio_stats.php" style="background-color="#AnyColorHereOrDelete" width="70" height="59" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>





File 1

file name: radio_stats.php


  <?php
// Shoutcast Server Stats
// Parses shoutcasts xml to make an effective stats thing for any website
// Â©2004-2005 Daniel Brown http://www.gmtt.co.uk
// Please refer to the readme file for use.


// Add-On MAXLISTNERS insead of the / 10 MAXLISTENERS which was set, and the BITRATE add-on.
// Online and Offline graphics, and add-on code.
// Better HTML Script.

// Do Not Try To Edit This Only Unless You Know What You're Doing!!!!!!!

//---------------------------------------------------------
include('config_radio.php');

$scfp fsockopen("$scip"$scport, &$errno, &$errstr30);
 if(!
$scfp) {
  
$scsuccs=1;
echo
''.$scdef.' is Offline'
 }
if(
$scsuccs!=1){
 
fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
 while(!
feof($scfp)) {
  
$page .= fgets($scfp1000);
 }

//---------------------------------------------------------
//define  xml elements
//---------------------------------------------------------
 
$loop = array("STREAMSTATUS");
 
$y=0;
 while(
$loop[$y]!=''){
  
$pageed ereg_replace(".*<$loop[$y]>"""$page);
  
$scphp strtolower($loop[$y]);
  $
$scphp ereg_replace("</$loop[$y]>.*"""$pageed);
// uncomment the next line to see all variables
//echo'$'.$scphp.' = '.$$scphp.'<br>';
  
$y++;
 }

//end intro xml elements
fclose($scfp);
}

//---------------------------------------------------------
//display stats
//---------------------------------------------------------
if($streamstatus == "1"){
//you may edit the html below, make sure to keep variable intact
echo'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel=stylesheet href="" type="text/css">
<title>'
.$scdef.'</title>
</head>
<body text="" bgcolor="">
<center>

<img src="online.gif">
</body>
</html>'
;
}
//---------------------------------------------------------
//---------------------------------------------------------
if($streamstatus == "0"){
//you may edit the html below, make sure to keep variable intact
echo'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel=stylesheet href="" type="text/css">
<title>Radio Server Is Offline</title>
</head>

<body text="" bgcolor="">
<center>

<img src="offline.gif">
</body>

</html>'
;
}
?>






File 2

File name: config_radio.php


<?php

         
$scip 
"StreamAddressHere";
$scport "PortNumberHere";                  
$scpass "ShoutcastPasswordHere";                 


?>






You need to create some Online / Offline  or  On Air / Off Air images and they need to be named:

Note: I didn't write this script, if you have errors such as "fsock error". That is something you need to take up with your website hosting company. If they block the incoming data stream, there is nothing I can do about it.