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 "
Error: {$this->error[1]} ({$this->error[0]})
";
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 ', $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: