Stats para Radios por Internet (No necesita password de Dj)

Manuales de Instalacion, Configuración de Radio Streaming, Como Tips.

Stats para Radios por Internet (No necesita password de Dj)

Notapor admin » Sab Ago 29, 2009 10:48 pm

Al Primer Archivo le llamaremos - info.php

$puerto_radio="6070"; ------------> Puerto de la Radio


include('ShoutcastInfo.class.php'); ----> llama al archivo ShoutcastInfo.class.php que mencionearemos a continuación.

$scs = &new ShoutcastInfo($ip_radio,$puerto_radio);

if( !$scs->connect() )
{

$error = FALSE;
}


if( $error != TRUE )
{
$scs->send();

if( !$scs->get_stat() ) //If server isn't online..
{
print '<br>Estamos Offline<br><br>';

}
else
{
echo "<meta>";
$string=$scs->get_track();
$musica=explode("-",$string);

echo "<table>";
echo "<tr><td><b>Programa:</b></td></tr>";
echo "<tr><td>".$scs->get_icq()."</td></tr>";
echo "<tr><td><b>Género:</b></td></tr>";
echo "<tr><td>".$scs->get_genre()."</td></tr>";
echo "<tr><td><b>Locución:</b></td></tr>";
echo "<tr><td>".$scs->get_aim()."</td></tr>";
echo "<tr><td><b>Artista</b>:</td></tr>";
echo "<tr><td>".$musica['0']."</td></tr>";
echo "<tr><td><b>Canción:</b></td></tr>";
echo "<tr><td>".$musica['1']."</td></tr>";
echo "</table><br>";


} //Thats it!

$scs->close();

} //end if no error was made

?>
<br>

*****************************************

2do Archivo llamado: ShoutcastInfo.class.php


<php>hostname = $hostname;
$this->port = $port;
$this->timeout = $timeout;
} // ShoutcastInfo()

//
// Begin of socket and connection functions
//

/*****
* bool connect( void )
* creates server connection, returns true on success, else retruns false.
*/
function connect()
{
if( !$this->sock )
{
//Connect
$this->sock = @fsockopen($this->hostname, $this->port, $this->error[0] , $this->error[1], $this->timeout);
}

//Check connection
if( $this->sock )
{
return TRUE;
}
else
{
return FALSE;
}
} // connect()

/*****
* bool close( void )
* closes current connection
*/
function close()
{
if( $this->sock )
{
fclose($this->sock);
}
} // close()

/*****
* bool refresh( void )
* closes connection and opens it again to get new datas.
* parsed datas will not replaced, but parsing will be
* able again.
*/
function refresh()
{
$this->close();
$this->sock = NULL;
if( !$this->connect() )
{
return FALSE;
}
$this->parsed = FALSE;
$this->send();
return TRUE;
} // refresh()

/*****
* void send( void )
* Sends http header and recives datas from server
*/
function send()
{
if( $this->sock )
{
//Send HTTP Header
fputs($this->sock, "GET / HTTP/1.0\r\n"
."Host: 127.0.0.1\r\n"
."User-Agent: Mozilla/4.0 (compatible; ShoutCastInfoClass/0.0.2; ".PHP_OS.")\r\n"
."\r\n"
);

//Get datas
$this->datas = NULL;
while( !feof($this->sock) )
{
$this->datas .= fgets($this->sock, 128);
}
}
} // send()

/*****
* mixed error( [bool return])
* if return is true it will return a error message,
* else it will print it out (HTML Formatted!).
*/
function error($return=FALSE)
{
if( $return == FALSE )
{
print "<br><b>Error:</b> {$this->error[1]} (<i>{$this->error[0]}</i>)<br>";
return;
}
return "{$this->error[1]} ({$this->error[0]})";
}

//
// Begin of public functions
//

/*****
* bool get_stat( void )
* Checks that stream will be up and private/public.
*/
function get_stat()
{
if( strstr($this->datas, 'Server is currently up and') )
{
$this->pdatas['status'] = 1;
return TRUE;
}
else
{
$this->pdatas['status'] = 0;
return FALSE;
}
} // get_stat()






/*****
* integer get_listener( void )
* returns and resets the number of accutal listener.
*/
function get_listener()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['listener'] = 0;
return 0;
}

$this->pdatas['listener_max'] = explode('kbps with <B>', $this->datas);
$this->pdatas['listener'] = explode(' of ', $this->pdatas['listener_max'][1]);
$this->pdatas['listener_max'] = $this->pdatas['listener'][1];
$this->pdatas['listener'] = $this->pdatas['listener'][0];
$this->pdatas['listener_max'] = explode(' l', $this->pdatas['listener_max']);
$this->pdatas['listener_max'] = $this->pdatas['listener_max'][0];

return $this->pdatas['listener'];
} // get_listener()

/*****
* integer get_peak( void )
* returns the listener peak from stream and resets it.
*/
function get_peak()
{
$this->pdatas['peak'] = $this->_extract_datas('Listener Peak: </font></td><td><font><b>');
return $this->pdatas['peak'];
} // get_peak()

/*****
* string get_title( void )
* returns and resetts the actual moderator/dj/stream_title at stream.
*/
function get_title()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['title'] = FALSE;
return FALSE;
}

$this->pdatas['title'] = $this->_extract_datas('Stream Title: </font></td><td><font><b>');
return $this->pdatas['title'];
} // get_title()

/*****
* string get_content_type( void )
* returns and resetts the actual ContentType at stream.
*/
function get_content_type()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['content_type'] = FALSE;
return FALSE;
}

$this->pdatas['content_type'] = $this->_extract_datas('Content Type: </font></td><td><font><b>');
return $this->pdatas['content_type'];
} // get_content_type()

/*****
* string get_genre( void )
* returns and resetts the actual Stream Genre.
*/
function get_genre()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['genre'] = FALSE;
return FALSE;
}

$this->pdatas['genre'] = $this->_extract_datas('Stream Genre: </font></td><td><font><b>');
return $this->pdatas['genre'];
} // get_genre()

/*****
* string get_url( void )
* returns and resetts the actual Stream URL.
*/
function get_url()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['url'] = 'none';
return 'none';
}

$this->pdatas['url'] = $this->_extract_datas('Stream URL: </font></td><td><font><b><a href="', '"');
return $this->pdatas['url'];
} // get_url()

/*****
* string get_icq( void )
* returns and resetts the actual Stream ICQ.
*/
function get_icq()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['icq'] = FALSE;
return FALSE;
}

$this->pdatas['icq'] = $this->_extract_datas('ICQ: </font></td><td><font><b><a href="http://wwp.icq.com/scripts/contact.dll?msgto=', '"');
//ICQ is aviable?
$this->pdatas['icq'] = ( $this->pdatas['icq'] == 'NA' ) ? FALSE : $this->pdatas['icq'];
return $this->pdatas['icq'];
} // get_icq()

/*****
* string get_aim( void )
* returns and resetts the actual Stream AIM.
*/
function get_aim()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['aim'] = FALSE;
return FALSE;
}

$this->pdatas['aim'] = $this->_extract_datas('AIM: </font></td><td><font><b><a href="aim:goim?screenname=', '"');
//AIM is aviable?
$this->pdatas['aim'] = ( $this->pdatas['aim'] == 'NA' ) ? FALSE : $this->pdatas['aim'];
return $this->pdatas['aim'];
} // get_aim()

/*****
* string get_irc( void )
* returns and resetts the actual Stream IRC.
* Note: This often is not a valid form of URL!
*/
function get_irc()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['irc'] = FALSE;
return FALSE;
}

$this->pdatas['irc'] = $this->_extract_datas('Stream IRC: </font></td><td><font><b><a>');
$this->pdatas['irc'] = substr($this->pdatas['irc'], 2);
return $this->pdatas['irc'];

} // get_irc()

/*****
* string get_track( void )
* returns and resetts the current track informations.
*/
function get_track()
{
//Is stream up?
if( $this->pdatas['status'] == 0 )
{
$this->pdatas['track'] = FALSE;
return FALSE;
}

$this->pdatas['track'] = $this->_extract_datas('Current Song: </font></td><td><font><b>');
return $this->pdatas['track'];

} // get_track()

/*****
* array parse( void )
* get all the items aviable and return an assoc array.
* Note: Use this only if you need ALL the informations!
*/
function parse()
{
if( $this->parsed != TRUE )
{
//get all single infos
$this->get_stat();
$this->get_listener();
$this->get_peak();
$this->get_title();
$this->get_content_type();
$this->get_genre();
$this->get_url();
$this->get_icq();
$this->get_aim();
$this->get_irc();
$this->get_track();
//set parsed stat
$this->parsed = TRUE;
}
return $this->pdatas;

} // parse()

/*****
* mixed get_parsed_value( string key )
* Sucht aus dem geparsten array einen wert herraus und gibt ihn zurück
* wenn er noch nicht gesetzt ist wird NULL zurückgegeben.
*/
function get_parsed_value($key)
{
return ( isset($this->pdatas[$key]) ) ? $this->pdatas[$key] : FALSE;

} // get_parsed_value()

//
// Begin private functions
//

/*****
* private mixed _extract_datas(string match_str [, string ending])
* extracts and returns datas after an match_string and before net html tag or ending.
*/
function _extract_datas($match_str, $ending='<datas>datas, $match_str);
//remove match_str because strstr starts before..
$datas = str_replace($match_str, '', $datas);
//split text after ending mark and throw all away isnt needed.
$datas = explode($ending, $datas);
return $datas[0];

} // _extract_datas()

} // ShoutcastInfo class

//
// Thats it folks!
//

?>

***********************************************
3 er achivo llamaremos shoutcast.class.info
<php>host, $this->port, $errno, $errstr, 10);
If (!$fp) {
$this->_error = "$errstr ($errno)";
return(0);
} else {
fputs($fp, "GET /admin.cgi?pass=".$this->passwd."&mode=viewxml HTTP/1.0\r\n");
fputs($fp, "User-Agent: Mozilla\r\n\r\n");
while (!feof($fp)) {
$this->_xml .= fgets($fp, 512);
}
fclose($fp);

if (stristr($this->_xml, "HTTP/1.0 200 OK") == true) {
// <H> Thanks to Blaster for this fix.. trim();
$this->_xml = trim(substr($this->_xml, 42));
} else {
$this->_error = "Bad login";
return(0);
}

$xmlparser = xml_parser_create();
if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
$this->_error = "Unparsable XML";
return(0);
}

xml_parser_free($xmlparser);

return(1);
}
}

function GetCurrentListenersCount() {
return($this->_values[$this->_indexes["CURRENTLISTENERS"][0]]["value"]);
}

function GetPeakListenersCount() {
return($this->_values[$this->_indexes["PEAKLISTENERS"][0]]["value"]);
}

function GetMaxListenersCount() {
return($this->_values[$this->_indexes["MAXLISTENERS"][0]]["value"]);
}

function GetReportedListenersCount() {
return($this->_values[$this->_indexes["REPORTEDLISTENERS"][0]]["value"]);
}

function GetAverageListenTime() {
return($this->_values[$this->_indexes["AVERAGETIME"][0]]["value"]);
}

function GetServerGenre() {
return($this->_values[$this->_indexes["SERVERGENRE"][0]]["value"]);
}

function GetServerURL() {
return($this->_values[$this->_indexes["SERVERURL"][0]]["value"]);
}

function GetServerTitle() {
return($this->_values[$this->_indexes["SERVERTITLE"][0]]["value"]);
}

function GetCurrentSongTitle() {
return($this->_values[$this->_indexes["SONGTITLE"][0]]["value"]);
}

function GetIRC() {
return($this->_values[$this->_indexes["IRC"][0]]["value"]);
}

function GetAIM() {
return($this->_values[$this->_indexes["AIM"][0]]["value"]);
}

function GetICQ() {
return($this->_values[$this->_indexes["ICQ"][0]]["value"]);
}

function GetWebHitsCount() {
return($this->_values[$this->_indexes["WEBHITS"][0]]["value"]);
}

function GetStreamHitsCount() {
return($this->_values[$this->_indexes["STREAMHITS"][0]]["value"]);
}

function GetStreamStatus() {
return($this->_values[$this->_indexes["STREAMSTATUS"][0]]["value"]);
}

function GetBitRate() {
return($this->_values[$this->_indexes["BITRATE"][0]]["value"]);
}

function GetSongHistory() {
for($i=1;$i<sizeof>_indexes['TITLE']);$i++) {
$arrhistory[$i-1] = array(
"playedat"=>$this->_values[$this->_indexes['PLAYEDAT'][$i]]['value'],
"title"=>$this->_values[$this->_indexes['TITLE'][$i]]['value']
);
}

return($arrhistory);
}

function GetListeners() {
for($i=0;$i<sizeof>_indexes['USERAGENT']);$i++) {
$arrlisteners[$i] = array(
"hostname"=>$this->_values[$this->_indexes['HOSTNAME'][$i]]['value'],
"useragent"=>$this->_values[$this->_indexes['USERAGENT'][$i]]['value'],
"underruns"=>$this->_values[$this->_indexes['UNDERRUNS'][$i]]['value'],
"connecttime"=>$this->_values[$this->_indexes['CONNECTTIME'][$i]]['value'],
"pointer"=>$this->_values[$this->_indexes['POINTER'][$i]]['value'],
"uid"=>$this->_values[$this->_indexes['UID'][$i]]['value'],
);
}

return($arrlisteners);
}

function geterror() { return($this->_error); }
}

?>

Atte.

www.inkawebdesign.com
Avatar de Usuario
admin
Site Admin
 
Mensajes: 238
Registrado: Sab Jun 30, 2007 2:31 am
Ubicación: Lima

Volver a Radio Streaming

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados

cron