Código Streambox para Shoutcast 2.x
Aquí encontrará el código para el Streambox puede consultar la Shoutcast2.

<?php

/*
* Streambox Shoutcast2 (Version 1.2)
* Created on 05.04.2014 by Music Goal
* http://www.musicgoal.com/pages/docs/42/
*
*/

# shoutcast2 xml statuspage (e.g. http://85.214.96.78:8004/stats?sid=1)
define('STATUSPAGE','http://85.214.96.78:8004/stats?sid=1');

# create these files on http://www.musicgoal.com/tools/playlist-generator/
# include the full path e.g. http://yourdomain.com/listen.m3u
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 or javascript
define('OUTPUT','html'); // html, js

# design
define('BACKGROUND_IMAGE','http://www.musicgoal.com/static/pics/streambox/streambox_1.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"]
["AVERAGETIME"]
["SERVERGENRE"]
["SERVERURL"]
["SERVERTITLE"]
["SONGTITLE"]
["NEXTTITLE"]
["STREAMHITS"]
["STREAMSTATUS"]
["STREAMPATH"]
["BITRATE"]
["CONTENT"]
["VERSION"]
*/

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/42/" TARGET="_blank">your own streambox</A>'.
'</DIV>' .
'</DIV>'
);
}

class cURL {
var $headers;
var $compression;

function cURL($compression='gzip',$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 xml2array($get_attributes = 1, $priority = 'tag', $contents = '') {
$parser = xml_parser_create('');
# charset encoding
if(stristr(substr($contents,0,100),'iso-8859')) {
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
}
else {
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
}
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($contents), $xml_values);
xml_parser_free($parser);
$xml_array = array ();
$parents = array ();
$opened_tags = array ();
$arr = array ();
$current = & $xml_array;
$repeated_tag_index = array ();
$i = 0;
foreach ($xml_values as $data) {
// start
unset ($attributes, $value);
extract($data);
$result = array ();
$attributes_data = array ();
if (isset ($value)) {
if ($priority == 'tag') {
$result = $value;
}
else {
$result['value'] = $value;
}
}
if (isset ($attributes) and $get_attributes) {
foreach ($attributes as $attr => $val) {
if ($priority == 'tag') {
$attributes_data[$attr] = $val;
}
else {
$result['attr'][$attr] = $val; // Set all the attributes in a array called 'attr'
}
}
}
if ($type == "open") {
$parent[$level -1] = & $current;
if (!is_array($current) or (!in_array($tag, array_keys($current)))) {
$current[$tag] = $result;
if ($attributes_data)
$current[$tag . '_attr'] = $attributes_data;
$repeated_tag_index[$tag . '_' . $level] = 1;
$current = & $current[$tag];
}
else {
if (isset ($current[$tag][0])) {
$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
$repeated_tag_index[$tag . '_' . $level]++;
}
else {
$current[$tag] = array (
$current[$tag],
$result
);
$repeated_tag_index[$tag . '_' . $level] = 2;
if (isset ($current[$tag . '_attr'])) {
$current[$tag]['0_attr'] = $current[$tag . '_attr'];
unset ($current[$tag . '_attr']);
}
}
$last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
$current = & $current[$tag][$last_item_index];
}
}
elseif ($type == "complete") {
if (!isset ($current[$tag])) {
$current[$tag] = $result;
$repeated_tag_index[$tag . '_' . $level] = 1;
if ($priority == 'tag' and $attributes_data) {
$current[$tag . '_attr'] = $attributes_data;
}
}
else {
if (isset ($current[$tag][0]) and is_array($current[$tag])) {
$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
if ($priority == 'tag' and $get_attributes and $attributes_data) {
$current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
}
$repeated_tag_index[$tag . '_' . $level]++;
}
else {
$current[$tag] = array (
$current[$tag],
$result
);
$repeated_tag_index[$tag . '_' . $level] = 1;
if ($priority == 'tag' and $get_attributes) {
if (isset ($current[$tag . '_attr'])) {
$current[$tag]['0_attr'] = $current[$tag . '_attr'];
unset ($current[$tag . '_attr']);
}
if ($attributes_data) {
$current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
}
}
$repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
}
}
}
elseif ($type == 'close') {
$current = & $parent[$level -1];
}
}
return ($xml_array);
}

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,'');
$xmldata = xml2array('1','tag',$contents);

if(defined('PLAYER_LINK_PLS_WINAMP')) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_PLS_WINAMP'] = PLAYER_LINK_PLS_WINAMP;
}
if(defined('PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER')) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER'] = PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER;
}
if(defined('PLAYER_LINK_RAM_REALPLAYER')) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_RAM_REALPLAYER'] = PLAYER_LINK_RAM_REALPLAYER;
}
if(defined('PLAYER_LINK_M3U_DEFAULT')) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_M3U_DEFAULT'] = PLAYER_LINK_M3U_DEFAULT;
}
if(!$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER']) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_ASX_WINDOWS_MEDIA_PLAYER'] = str_replace('stats','listen.asx',STATUSPAGE);
}
if(!$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_M3U_DEFAULT']) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_M3U_DEFAULT'] = str_replace('stats','listen.m3u',STATUSPAGE);
}
if(!$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_RAM_REALPLAYER']) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_RAM_REALPLAYER'] = str_replace('stats','listen.m3u',STATUSPAGE); // realplayer use also m3u, but use ram if possible. it's only a hack!
}
if(!$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_PLS_WINAMP']) {
$xmldata['SHOUTCASTSERVER']['PLAYER_LINK_PLS_WINAMP'] = str_replace('stats','listen.pls',STATUSPAGE);
}

output(Streambox($xmldata['SHOUTCASTSERVER']));
exit;

?>
modificada por última vez: 17.05.2014
© MusicGoal 2006 - | Pie de imprenta | Política de privacidad