| View previous topic :: View next topic |
| Author |
Message |
Anonymous Guest
|
Posted: Mon Apr 23, 2007 9:45 pm Post subject: Icecast Statistics w/ GeoIP PHP Script |
|
|
Does anyone know of a PHP script that can display the listener statistics of an Icecast server meaning current listener count, max listeners allowed, current IPs connected and what countries they are from?
Basically, I have a current PHP script for shoutcast that I like that does all this and I didn't know if it was easy to incoroprate the icecast server into it? |
|
| Back to top |
|
 |
Anonymous Guest
|
Posted: Thu Jun 21, 2007 8:06 am Post subject: |
|
|
I would like to see a way of doing this.
I have been trying to find a work around with shoutcast.class.php for Icecast but Icecast parses the XML differently to Shoutcast.
I have been told it can be done with some programming. |
|
| Back to top |
|
 |
Anonymous Guest
|
Posted: Tue Jul 24, 2007 12:18 am Post subject: Well... |
|
|
| qmr wrote: |
| I have been told it can be done with some programming. |
Indeed, it could ... put together a custom admin page with all connecting IP's (little bit of xslt work), parse that with PHP, and then put it through geolocation, stick it on a map or something, and done.
I will mention that getting accurate geolocation's probably the biggest hurdle here - the free services I've seen are wildly inaccurate, and the pay services start in the hundreds of $USD.
-bhance |
|
| Back to top |
|
 |
SC-Tools
Joined: 16 Apr 2009 Posts: 2
|
Posted: Tue May 12, 2009 9:46 am Post subject: icecast.class.php |
|
|
New
icecast.class.php
<?php
/*******************************************************************
* icecast.class.php
* Version: 1.0
* Author: W. Herrmann
* Copyright (C) 2009, SC-Tools
*******************************************************************/
class icecast {
// Public
var $host;
var $port;
var $mount;
var $user;
var $passwd;
//Private
var $_xml;
var $_error;
function openStats() {
$fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10);
if (!$fp) {
$this->_error = "$errstr ($errno) - $this->port";
return(0);
} else {
// grab XML stats
stream_set_timeout($fp, 2);
$status = null;
$status = socket_get_status($fp);
fputs($fp, "GET /admin/listclients?mount=/".$this->mount." HTTP/1.1\nUser-Agent: Mozilla\n");
fputs($fp, "Authorization: Basic ".base64_encode ($this->user.':'.$this->passwd)."\n\n");
while (!feof($fp) && !$status['timed_out']) {
$line = trim(fgets($fp, 512));
$this->_xml .= (empty($line)) ? null : $line;
$status = socket_get_status($fp);
}
$this->_xml = ereg_replace("^.*<icestats", "<icestats", $this->_xml);
fclose($fp);
$xmlparser = xml_parser_create();
if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
$this->_error = "Unparsable XML";
echo $this->_xml;
return(0);
}
xml_parser_free($xmlparser);
return(1);
}
}
function getStreamStatus() {
return (isset($this->_streamStatus)) ? $this->_streamStatus : $this->_values[$this->_indexes["LISTENERS"][0]]["value"];
}
function GetListeners() {
for($i=0;$i<sizeof($this->_indexes['USERAGENT']);$i++) {
$arrlisteners[$i] = array(
"connected"=>$this->_values[$this->_indexes['CONNECTED'][$i]]['value'],
"id"=>$this->_values[$this->_indexes['ID'][$i]]['value'],
"ip"=>$this->_values[$this->_indexes['IP'][$i]]['value'],
"useragent"=>$this->_values[$this->_indexes['USERAGENT'][$i]]['value'],);
}
return($arrlisteners);
}
function geterror() { return($this->_error); }
}
?>
icecast-demo.php
<?php
include("icecast.class.php");
$icecast = new icecast();
$icecast->host = "192.168.2.2";
$icecast->port = 8000;
$icecast->mount = "rmbl.mp3";
$icecast->user = "admin";
$icecast->passwd = "polo";
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
if ($icecast->openstats()) {
// We got the XML, gogogo!..
if ($icecast->GetStreamStatus()) {
echo "<b>Listeners;</b><br>\n";
$listeners = $icecast->GetListeners();
if (is_array($listeners)) {
sort($listeners);
//rsort($listeners);
for ($i=0;$i<sizeof($listeners);$i++) {
echo "[".$listeners[$i]["id"]."] - ".$listeners[$i]["ip"]." using ".$listeners[$i]["useragent"].", ".elapsedtime($listeners[$i]["connected"])."<br>\n";
}
} else {
echo "Noone listens right now..";
}
} else {
echo "Server is up, but no stream available..";
}
} else {
echo $icecast->geterror();
}
?> |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group subRebel style by ktauber
|