Streambox Code für Shoutcast 1.x
Hier finden sie den Code für die Streambox die den Shoutcast1 abfragen kann. Diese gibt ihnen nützliche Informationen über Ihren Streamserver und zeigt sie auf einer Webseite an. Sie können den Code nach Ihren Bedürfnissen anpassen.

<?php

/*
* Streambox Shoutcast1 (Version 1.1)
* Created on 05.04.2014 by Music Goal
* http://www.musicgoal.com/pages/docs/41/
*
*/

# shoutcast1 statuspage (e.g. http://stream.groovefm.de:10028/)
define('STATUSPAGE','http://stream.groovefm.de:10028/'); // http://HOST:PORT/

# create these files on http://www.musicgoal.com/tools/playlist-generator/
define('PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER','');
define('PLAYER_LINK_RAM_REALPLAYER','');
define('PLAYER_LINK_M3U_DEFAULT','');
define('PLAYER_LINK_PLS_WINAMP','');

# switch 1 or 0
define('SHOW_BITRATE',1);
define('SHOW_PLAYLIST',1);
define('SHOW_LISTENER',1);

# choose output html and javascript
define('OUTPUT','html'); // html, js

# design
define('BACKGROUND_IMAGE','http://www.musicgoal.com/static/pics/streambox/streambox_4.png');
define('STREAMBOX_WIDTH',150);
define('STREAMBOX_HEIGHT',200);
define('STREAMBOX_FONT','Verdana, Arial, Helvetica, sans-serif');
define('STREAMBOX_FONT_COLOR','#000060');
# change html in the Streambox function

/*
* available values:

["CURRENTLISTENERS"]
["PEAKLISTENERS"]
["MAXLISTENERS"]
["UNIQUELISTENERS"]
["SONGTITLE"]
["STREAMSTATUS"]
["BITRATE"]
*/

function Streambox($xmldata) {
# online
if($xmldata['STREAMSTATUS'] == '1') {
# host + port
$player_links = '';
if($xmldata['PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER']) {
$player_links .= '<AREA SHAPT=\'rect\' COORDS=\'30, 135, 50, 155\' HREF=\''.$xmldata['PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER'].'\' TITLE=\'Windows Media Player\'>';
}
if($xmldata['PLAYER_LINK_PLS_WINAMP']) {
$player_links .= '<AREA SHAPT=\'rect\' COORDS=\'55, 135, 75, 155\' HREF=\''.$xmldata['PLAYER_LINK_PLS_WINAMP'].'\' TITLE=\'Winamp\'>';
}
if($xmldata['PLAYER_LINK_RAM_REALPLAYER']) {
$player_links .= '<AREA SHAPT=\'rect\' COORDS=\'80, 135, 100, 155\' HREF=\''.$xmldata['PLAYER_LINK_RAM_REALPLAYER'].'\' TITLE=\'RealPlayer\'>';
}
if($xmldata['PLAYER_LINK_M3U_DEFAULT']) {
$player_links .= '<AREA SHAPT=\'rect\' COORDS=\'105, 135, 125, 155\' HREF=\''.$xmldata['PLAYER_LINK_M3U_DEFAULT'].'\' TITLE=\'Default Player\'>';
}
# song
if(SHOW_PLAYLIST === 1) {
$text_song =
'<DIV STYLE=\'position: absolute; width: '.(STREAMBOX_WIDTH-10).'px; height: 20px; z-index: 4; top: 90px; left: 5px;\'><FONT COLOR=\''.STREAMBOX_FONT_COLOR.'\' FACE=\''.STREAMBOX_FONT.'\'><MARQUEE SCROLLDELAY=\'170\'>'.$xmldata['SONGTITLE'].'</MARQUEE></FONT></DIV>';
}
# bitrate
if(SHOW_BITRATE === 1) {
$text_bitrate =
'<DIV STYLE=\'position: absolute; width: '.STREAMBOX_WIDTH.'px; height: 20px; z-index: 3; top: 60px; left: 5px;\'><FONT COLOR=\''.STREAMBOX_FONT_COLOR.'\' FACE=\''.STREAMBOX_FONT.'\'>Bitrate: '.$xmldata['BITRATE'].' kbps</FONT></DIV>';
}
# listener
if(SHOW_LISTENER === 1) {
$text_listener =
'<DIV STYLE=\'position: absolute; width: '.STREAMBOX_WIDTH.'px; height: 20px; z-index: 2; top: 40px; left: 5px;\'><FONT COLOR=\''.STREAMBOX_FONT_COLOR.'\' FACE=\''.STREAMBOX_FONT.'\'>Listener: '.$xmldata['CURRENTLISTENERS'].' ('.$xmldata['MAXLISTENERS'].')</FONT></DIV>';
}
$status = 'Status: <FONT COLOR=\'green\' FACE=\''.STREAMBOX_FONT.'\'>online</FONT>';
}
else {
$status = 'Status: <FONT COLOR=\'red\' FACE=\''.STREAMBOX_FONT.'\'>offline</FONT>';
}
# ausgabe
return(
'<DIV STYLE=\'width: '.STREAMBOX_WIDTH.'px; height: '.STREAMBOX_HEIGHT.'px;\'>' .
'<DIV STYLE=\'position: absolute; z-index: 1;\'>' .
'<IMG SRC=\''.BACKGROUND_IMAGE.'\' usemap=\'#streambox\' BORDER=\'0\'>'.
'<DIV STYLE=\'position: absolute; width: '.STREAMBOX_WIDTH.'px; height: 20px; z-index: 2; top: 5px; left: 5px;\'><H3><B><FONT COLOR=\''.STREAMBOX_FONT_COLOR.'\' FACE=\''.STREAMBOX_FONT.'\'>'.$status.'</FONT></B></H3></DIV>'.
$text_listener.
$text_bitrate.
$text_song.
'<MAP NAME=\'streambox\'>' .
'<AREA SHAPT=\'rect\' COORDS=\'100, 170, 160, 200\' HREF=\'http://www.musicgoal.com/\' TITLE=\'Online Radio and Internet Radio\' TARGET=\'_blank\'>' .
$player_links.
'</MAP>'.
'<BR><A HREF="http://www.musicgoal.com/pages/docs/41/" TARGET="_blank">your own streambox</A>'.
'</DIV>' .
'</DIV>'
);
}

class cURL {
var $headers;
var $compression;

function cURL($compression='gzip',$accept='text') {
if($accept == '') { $accept = 'text'; }
$this->headers[] = 'Accept: '.$accept.'/*';
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->compression=$compression;
}
function get($url) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, false);
curl_setopt($process, CURLOPT_USERAGENT, 'Mozilla');
curl_setopt($process, CURLOPT_URL, $url);
curl_setopt($process,CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 6);
curl_setopt($process, CURLOPT_CONNECTTIMEOUT, 6);
curl_setopt($process, CURLOPT_DNS_CACHE_TIMEOUT, 6);
curl_setopt($process, CURLOPT_FAILONERROR, 1);
curl_setopt($process, CURLOPT_FORBID_REUSE, 1);
curl_setopt($process, CURLOPT_FTP_USE_EPRT, 0);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($process, CURLOPT_MAXCONNECTS, 10);
curl_setopt($process, CURLOPT_HTTPGET, true);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($process, CURLOPT_MAXREDIRS, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
}

function text2array($contents = '') {
$stream_data = explode(',',strip_tags($contents));
$xmldata = array();
$xmldata['UNIQUELISTENERS'] = $stream_data[0];
$xmldata['PEAKLISTENERS'] = $stream_data[2];
$xmldata['MAXLISTENERS'] = $stream_data[3];
$xmldata['CURRENTLISTENERS'] = $stream_data[4];
$xmldata['BITRATE'] = $stream_data[5];
$xmldata['SONGTITLE'] = $stream_data[6];
if($xmldata['MAXLISTENERS'] > '0') {
$xmldata['STREAMSTATUS'] = '1';
}
else {
$xmldata['STREAMSTATUS'] = '0';
}
return($xmldata);
}

function output($xmldata) {
$xmldata = str_replace('"',' ',$xmldata);
if(OUTPUT == 'html') {
echo $xmldata;
}
elseif(OUTPUT == 'js') {
echo 'document.write(escape("'.$xmldata.'"));'."\n";
}
}

$cc = new cURL(false);
$contents = $cc->get(STATUSPAGE.'7.html','');
$xmldata = text2array($contents);

if(defined('PLAYER_LINK_PLS_WINAMP')) {
$xmldata['PLAYER_LINK_PLS_WINAMP'] = PLAYER_LINK_PLS_WINAMP;
}
if(defined('PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER')) {
$xmldata['PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER'] = PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER;
}
if(defined('PLAYER_LINK_RAM_REALPLAYER')) {
$xmldata['PLAYER_LINK_RAM_REALPLAYER'] = PLAYER_LINK_RAM_REALPLAYER;
}
if(defined('PLAYER_LINK_M3U_DEFAULT')) {
$xmldata['PLAYER_LINK_M3U_DEFAULT'] = PLAYER_LINK_M3U_DEFAULT;
}
if(!$xmldata['PLAYER_LINK_PLS_WINAMP']) {
$xmldata['PLAYER_LINK_PLS_WINAMP'] = STATUSPAGE.'listen.pls';
}

output(Streambox($xmldata));
exit;

?>
zuletzt geändert: 17.05.2014
© MusicGoal 2006 - | Impressum | Datenschutzerklärung