<?xml version="1.0"?> <icestats><admin>icemaster@localhost</admin> <client_connections>120525</client_connections><clients>5</clients> <connections>120562</connections> <file_connections>352</file_connections> <host>localhost</host> <listener_connections>477</listener_connections> <listeners>4</listeners><location>Earth</location> <server_id>Icecast trunk</server_id><server_start>Sat, 28 May 2011 11:37:07 +0400</server_start> <source_client_connections>4</source_client_connections> <source_relay_connections>0</source_relay_connections> <source_total_connections>4</source_total_connections> <sources>1</sources><stats>0</stats> <stats_connections>0</stats_connections> <source mount="/live"><listeners>0</listeners> <listenurl>http://localhost:8000/live</listenurl> <max_listeners>unlimited</max_listeners></source> <source mount="/play"><audio_info>bitrate=96;channels=2;samplerate=44100</audio_info> <channels>2</channels><genre>Ofther</genre><listener_peak>9</listener_peak> <listeners>4</listeners><listenurl>http://localhost:8000/play</listenurl> <max_listeners>unlimited</max_listeners> <public>1</public> <samplerate>44100</samplerate> <server_description>Radio-Pirs 96kb</server_description> <server_name>Radio-Pirs</server_name> <server_type>audio/mpeg</server_type> <server_url>http://radio-pirs.ru/</server_url> <slow_listeners>74</slow_listeners><source_ip>::1</source_ip> <stream_start>Sat, 28 May 2011 11:37:07 +0400</stream_start> <title>Dilays - Belie rozi (Bold Brothers Rem</title> <total_bytes_read>6368396395</total_bytes_read> <total_bytes_sent>7040554708</total_bytes_sent> <user_agent>libshout/2.2.2</user_agent></source></icestats>
<? //Icecast stats.xml parser class Icestat { private $xml = array(); private $stat = array(); var $current = array(); function getfile($user, $pass, $serv, $port) { $url = "http://".$user.":".$pass."@".$serv.":".$port."/admin/stats.xml"; $this->xml = simplexml_load_file($url); } function parsefile() { $mcount = count($this->xml->source); for ($i=0; $i<$mcount; $i++) { foreach ($this->xml->source as $arr) { $mnt=str_replace("/","",$arr['mount']); $this->stat[$mnt]['mount_name'] = $mnt; //ID маунта (например: ices) $this->stat[$mnt]['audio_info'] = $arr->audio_info; //инфо маунта $this->stat[$mnt]['bitrate'] = $arr->bitrate; //битрейт $this->stat[$mnt]['genre'] = $arr->genre; //жанр $this->stat[$mnt]['channels'] = $arr->ice-channels; //каналы (моно, стерео) $this->stat[$mnt]['listener_peak'] = $arr->listener_peak; //пик слушателей $this->stat[$mnt]['listeners'] = $arr->listeners; //текущее кол-во слушателей $this->stat[$mnt]['max_listeners'] = $arr->max_listeners; //максимум слушателей $this->stat[$mnt]['server_description'] = $arr->server_description; //описание маунта $this->stat[$mnt]['server_name'] = $arr->server_name; //название маунта $this->stat[$mnt]['title'] = $arr->title; // название текущей песни } } } function currentmount() { //if (!$this->stat['ID маунта живого вещания (например: live)']['audio_info']) { if (!$this->stat['live']['audio_info']) { //$this->current = $this->stat['ID маунта нонстопа (например: play)']; $this->current = $this->stat['play']; } else { $this->current = $this->stat['live']; } $this->stat = 0; } function printcurrent() { //Выводимая инфа (+ диз если нужно). Можно дополнять и изменять print " <nowrap> Активный маунт: ".$this->current['mount_name']."<br /> Название маунта: ".$this->current['server_name']."<br /> Описание маунта: ".$this->current['server_description']."<br /> Композиция: ".$this->current['title']."<br />"; if (!$this->current['bitrate']) { print " Битрейт: 96 Кб/с<br />"; } else { print " Битрейт: ".$this->current['bitrate']." Кб/с<br />"; } print " Слушателей: ".$this->current['listeners']."<br /> Пик слушателей: ".$this->current['listener_peak']." </nowrap>"; } } //Непосредственно вывод $output = new Icestat; //заполнить данные //пример: $output->getfile('юзер', 'пароль', 'сервер', 'порт'); $output->getfile('', '', '', ''); $output->parsefile(); $output->currentmount(); $output->printcurrent(); //End of file ?>