ich habe da auch eine abfrage, wer sendet, was sendet und wieviele zuhören. Dies habe ich allerdings nicht selbst gebaut.
radio.class.php
PHP-Code:
<?php
/****************************************************************/
/* */
/* Copyright: Xitara Websolution */
/* Home: http://www.xitara.net */
/* E-Mail: info@xitara.net */
/* */
/* Software: RSC - Radio Statistic Class */
/* Codename: Ichenu */
/* */
/* Startdate: 09.02.05 */
/* Version: 0.2.1 */
/* */
/* Autor: Manuel Burghammer */
/* Filename: radio.class.php */
/* */
/* Licence: GPL */
/* Description: */
/* */
/****************************************************************/
/* */
/* Dieses Copyright darf weder entfernt noch verändert werden */
/* */
/****************************************************************/
class radio{
function init(){ // Initialisierung und erzeugung des Arrays mit den Werten
$x_xml = $this->get_xml();
$this->parse_xml($x_xml);
}
function get_xml(){ // XML Status auslesen und alles unnötige entfernen
// return implode(file("icecast2.xml")); // Auskommentieren beim Einsatz, nur für Testzwecke
$sp = @fsockopen($this->host, $this->port, &$errno, &$errstr, 10);
if (!$sp)
die('Error while connecting to Server.');
else{
set_socket_blocking($sp, false);
if($this->serv == "shoutcast"){
fputs($sp, "GET /admin.cgi?pass=" . $this->pass . "&mode=viewxml HTTP/1.1\nUser-Agent: Mozilla\n\n");
}
else if($this->serv == "icecast"){
fputs($sp, "GET /admin/stats.xml HTTP/1.1\nUser-Agent: Mozilla\n");
fputs($sp, "Host: " . $this->host . "\n");
fputs($sp, "Authorization: Basic " . base64_encode("admin:" . $this->pass) . "\n\n");
}
else
die('There is no Server selected. Please select \"shoutcast\" or \"icecast\".');
for($i = 0; $i < 30; $i++) {
if(feof($sp))
break;
$sp_data .= fread($sp, 31337);
usleep(500000);
}
}
if($this->serv == "shoutcast")
$sp_data = ereg_replace("^.*<SHOUTCASTSERVER", "<SHOUTCASTSERVER", $sp_data);
if($this->serv == "icecast")
$sp_data = ereg_replace("^.*<icestats", "<icestats", $sp_data);
return $sp_data;
}
function set_host($host){ // Host schreiben
$this->host = $host;
}
function set_port($port){ // Port schreiben
$this->port = $port;
}
function set_pass($pass){ // Passwort schreiben
$this->pass = $pass;
}
function set_serv($serv){ // Serverart schreiben
$this->serv = $serv;
}
function parse_xml($x_xml){ // XML Baum verarbeiten, Array mit Tags und Werten, Array mit Songhistory (Shoutcast) und Array mit Hörern (shoutcast) erzeugen
$x_data_flag = FALSE;
$x_parser = xml_parser_create();
xml_parse_into_struct($x_parser, $x_xml, $x_vals, $x_index);
xml_parser_free($x_parser);
$this->x_vals = $x_vals;
$this->x_index = $x_index;
if($this->serv == "shoutcast"){
$this->status = $x_vals[$x_index['STREAMSTATUS'][0]]['value'];
$this->current_listeners = $x_vals[$x_index['CURRENTLISTENERS'][0]]['value'];
$this->peak_listeners = $x_vals[$x_index['PEAKLISTENERS'][0]]['value'];
$this->max_listeners = $x_vals[$x_index['MAXLISTENERS'][0]]['value'];
$this->average_time = $x_vals[$x_index['AVERAGETIME'][0]]['value'];
$this->server_genre = $x_vals[$x_index['SERVERGENRE'][0]]['value'];
$this->server_url = $x_vals[$x_index['SERVERURL'][0]]['value'];
$this->server_title = $x_vals[$x_index['SERVERTITLE'][0]]['value'];
$x_title = explode(" - ", $x_vals[$x_index['SONGTITLE'][0]]['value']);
$this->artist = $x_title[0];
$this->title = $x_title[1];
$this->song_url = $x_vals[$x_index['SONGURL'][0]]['value'];
$this->irc = $x_vals[$x_index['IRC'][0]]['value'];
$this->aim = $x_vals[$x_index['AIM'][0]]['value'];
$this->icq = $x_vals[$x_index['ICQ'][0]]['value'];
$this->version = $x_vals[$x_index['VERSION'][0]]['value'];
$this->listeners();
$this->song_history();
}
else if($this->serv == "icecast"){
$x_count = 0;
$xa_count = 0;
while($x_index['SOURCE'][$x_count]){
if($x_vals[$x_index['SOURCE'][$x_count]]['type'] == "open"){
$x_array[] = $x_index['SOURCE'][$x_count];
$this->mounts[$xa_count]['mount'] = $x_vals[$x_index['SOURCE'][$x_count]]['attributes']['MOUNT'];
$this->mounts[$xa_count]['artist'] = $x_vals[$x_index['ARTIST'][$xa_count]]['value'];
$this->mounts[$xa_count]['audio_bitrate'] = $x_vals[$x_index['AUDIO_BITRATE'][$xa_count]]['value'];
$this->mounts[$xa_count]['audio_channels'] = $x_vals[$x_index['AUDIO_CHANNELS'][$xa_count]]['value'];
$this->mounts[$xa_count]['audio_info'] = $x_vals[$x_index['AUDIO_INFO'][$xa_count]]['value'];
$this->mounts[$xa_count]['audio_samplerate'] = $x_vals[$x_index['AUDIO_SAMPLERATE'][$xa_count]]['value'];
$this->mounts[$xa_count]['bitrate'] = $x_vals[$x_index['BITRATE'][$xa_count]]['value'];
$this->mounts[$xa_count]['genre'] = $x_vals[$x_index['GENRE'][$xa_count]]['value'];
$this->mounts[$xa_count]['ice-bitrate'] = $x_vals[$x_index['ICE-BITRATE'][$xa_count]]['value'];
$this->mounts[$xa_count]['ice-channels'] = $x_vals[$x_index['ICE-CHANNELS'][$xa_count]]['value'];
$this->mounts[$xa_count]['ice-quality'] = $x_vals[$x_index['ICE-QUALITY'][$xa_count]]['value'];
$this->mounts[$xa_count]['ice-samplerate'] = $x_vals[$x_index['ICE-SAMPLERATE'][$xa_count]]['value'];
$this->mounts[$xa_count]['listeners'] = $x_vals[$x_index['LISTENERS'][$xa_count]]['value'];
$this->mounts[$xa_count]['listenurl'] = $x_vals[$x_index['LISTENURL'][$xa_count]]['value'];
$this->mounts[$xa_count]['public'] = $x_vals[$x_index['PUBLIC'][$xa_count]]['value'];
$this->mounts[$xa_count]['server_description'] = $x_vals[$x_index['SERVER_DESCRIPTION'][$xa_count]]['value'];
$this->mounts[$xa_count]['server_name'] = $x_vals[$x_index['SERVER_NAME'][$xa_count]]['value'];
$this->mounts[$xa_count]['server_url'] = $x_vals[$x_index['SERVER_URL'][$xa_count]]['value'];
$this->mounts[$xa_count]['subtype'] = $x_vals[$x_index['SUBTYPE'][$xa_count]]['value'];
$this->mounts[$xa_count]['title'] = $x_vals[$x_index['TITLE'][$xa_count]]['value'];
if($this->mounts[$xa_count]['artist'] == ""){
$artist = explode(" - ", $this->mounts[$xa_count]['title']);
$this->mounts[$xa_count]['artist'] = $artist[0];
$this->mounts[$xa_count]['title'] = $artist[1];
}
$xa_count++;
}
$x_count++;
}
if($this->mounts[0]['mount'] != ""){
$this->mount['mount'] = $x_vals[$x_index['SOURCE'][0]]['attributes']['MOUNT'];
$this->mount['artist'] = $x_vals[$x_index['ARTIST'][0]]['value'];
$this->mount['audio_bitrate'] = $x_vals[$x_index['AUDIO_BITRATE'][0]]['value'];
$this->mount['audio_channels'] = $x_vals[$x_index['AUDIO_CHANNELS'][0]]['value'];
$this->mount['audio_info'] = $x_vals[$x_index['AUDIO_INFO'][0]]['value'];
$this->mount['audio_samplerate'] = $x_vals[$x_index['AUDIO_SAMPLERATE'][0]]['value'];
$this->mount['bitrate'] = $x_vals[$x_index['BITRATE'][0]]['value'];
$this->mount['genre'] = $x_vals[$x_index['GENRE'][0]]['value'];
$this->mount['ice-bitrate'] = $x_vals[$x_index['ICE-BITRATE'][0]]['value'];
$this->mount['ice-channels'] = $x_vals[$x_index['ICE-CHANNELS'][0]]['value'];
$this->mount['ice-quality'] = $x_vals[$x_index['ICE-QUALITY'][0]]['value'];
$this->mount['ice-samplerate'] = $x_vals[$x_index['ICE-SAMPLERATE'][0]]['value'];
$this->mount['listeners'] = $x_vals[$x_index['LISTENERS'][0]]['value'];
$this->mount['listenurl'] = $x_vals[$x_index['LISTENURL'][0]]['value'];
$this->mount['public'] = $x_vals[$x_index['PUBLIC'][0]]['value'];
$this->mount['server_description'] = $x_vals[$x_index['SERVER_DESCRIPTION'][0]]['value'];
$this->mount['server_name'] = $x_vals[$x_index['SERVER_NAME'][0]]['value'];
$this->mount['server_url'] = $x_vals[$x_index['SERVER_URL'][0]]['value'];
$this->mount['subtype'] = $x_vals[$x_index['SUBTYPE'][0]]['value'];
$this->mount['title'] = $x_vals[$x_index['TITLE'][$xa_count]]['value'];
}
else{
unset($this->mount);
$this->mount['mount'] = "N/A";
}
$this->version = $x_vals[$x_index['SERVER'][0]]['value'];
$this->current_listeners = $x_vals[$x_index['CLIENTS'][0]]['value'];
}
else
die('There is no Server selected. Please select \"shoutcast\" or \"icecast\".');
}
function listeners(){
foreach($this->x_index['LISTENERS'] as $listener){
if($this->x_vals[$listener]['type'] == "close" || $this->x_vals[$listener + 2]['value'] == "\n" || $this->x_vals[$listener + 2]['value'] == "")
break;
$this->listener_array .= array( "hostname" => $this->x_vals[$listener + 2]['value'],
"useragent" => $this->x_vals[$listener + 4]['value'],
"underruns" => $this->x_vals[$listener + 6]['value'],
"connect_time" => $this->x_vals[$listener + 8]['value'],
"pointer" => $this->x_vals[$listener + 10]['value'],
"uid" => $this->x_vals[$listener + 12]['value']);
}
}
function song_history(){
$x_array = count($this->x_index['SONG']);
$x_array_count = 0;
for($x_count = 0; $x_count < $x_array; $x_count += 2){
$x_song_ = $this->x_vals[$this->x_index['SONG'][$x_count] + 2]['value'];
$x_song = explode(" - ", $x_song_);
$this->song_history[$x_array_count++] = array("time" => date($this->timeformat, $this->x_vals[$this->x_index['SONG'][$x_count] + 1]['value']),
"artist" => $x_song[0],
"title" => $x_song[1]);
}
}
function value($x_nodename){
return $this->x_vals[$this->x_index[$x_nodename][0]]['value'];
}
function time_format($x_timeformat){
$this->timeformat = $x_timeformat;
}
}
?>
Sendung.php
PHP-Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/transitional.dtd">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<html>
<head>
<style>
body {
font-family: Tahoma, Verdana, Arial;
color: #FFD700;
background-color: #101056;
margin-top: 0px;
margin-bottom: 0px;
font-weight: bold;
}
a {
text-decoration: none;
color: white;
}
a:hover {
text-decoration: underline;
}
table {
color: #FFD700;
}
#overall {
width: 350px;
margin-left: 0px;
}
.text {
font-size: 10px;
font-weight: normal;
}
.heading {
font-size: 10px;
}
</style>
<meta http-equiv="refresh" content="5" />
</head>
<body>
<div id="overall">
<?php
include("radio.class.php"); // Klasse einbinden
$radio = new Radio; // Klasse initialisieren
$radio->set_host("91.121.20.164"); // ServerURL
$radio->set_port("8000"); // Serverport
$radio->set_pass("xxxxx"); // Passwort für den Adminbereich des Servers
$radio->set_serv("shoutcast"); // Legt die Serversoftware fest: "icecast" oder "shoutcast"
$radio->time_format("d.m.Y - H:i:s"); // Datumsformat festlegen. Beispiele unter http://de2.php.net/manual/de/function.date.php
$radio->init(); // Statistik initialisieren
if($radio->status == 1){ // 1 -> Sendung läuft, 0-> keine Sendung
?>
<head>
<style type="text/css">
.style1 {
text-align: center;
}
</style>
</head>
<table cellspacing="0" cellpadding="0" style="width: 350px">
<tr>
<td colspan="3"><h4 class="style1">Aktuell on Stream</h4></td>
</tr>
<tr>
<td style="height: 8px">
<h6>Moderator:
<br>Sendung:
<br>Interpret:
<br>Titel:
<br>Zuhörer:
</h6>
</td>
<td style="height: 8px; width: 30px"></td>
<td style="height: 8px">
<h6><?php echo $radio->aim;?>
<br><?php echo $radio->server_title;?>
<br><?php echo $radio->artist;?>
<br><?php echo $radio->title;?>
<br><?php echo $radio->current_listeners;?>
</h6>
</td>
</tr>
<?php
}
else
echo " ";
?>
sorry für so viel code ... ich bin etwas ratlos, wie ich eine solche abfrage einfügen kann, dass er dann anstatt eines moderators das bild zeigt, und wenn kein mod sendet wohl was mit else) den grünen haken....