Old 19th December 2008, 06:02   #1
brettcave
Junior Member
 
Join Date: Dec 2008
Posts: 1
grabxml.phps

Hi there,

I would like to build a custom frontend for DNAS, and have looked at the XML output from the admin cgi.

In the readme, there is a mention of http://beta.shoutcast.com/~tpepper/grabxml.phps, which no longer exists. Anyone have the code for this as a base? (its easier than writing everything from scratch )

or could you maybe point me in the direction of some resources that will assist in this.

*jkey - moved to discussions*
brettcave is offline   Reply With Quote
Old 7th January 2009, 16:14   #2
datagutt
Junior Member
 
Join Date: Oct 2008
Location: Norway
Posts: 1
I used web archive and found the code:

PHP Code:
<?

// grabxml 0.1.2 (php)
// 1-12-2001 t. pepper
// yay i made this
// yay i stole some of it off php.net's xml docs pages

// SET THESE VARIABLES

$password="changeme";
$host="host.shoutcast.com";
$port=8000;

// you can change these event handlers to do whatever
// you want upon receiving the XML data.  right now, they
// just dump the parsed xml in as pretty a way as they can

function startElement($parser$name$attrs) {
  global 
$depth$lastelem;
  if(
$lastelem!='data') echo "\n";

  for (
$i 0$i $depth[$parser]; $i++) echo "  ";
  echo 
"+ <b>$name</b>  ";
  
$depth[$parser]++;

  
$lastelem='start';
}
 
function 
endElement($parser$name) {
   global 
$depth$lastelem;
   
//echo "<b>/$name</b>  ";
   
if ($lastelem=='data') echo "\n";
   
$depth[$parser]--;
}

function 
characterData($parser$data) {
   global 
$depth$lastelem;
   
$data=trim($data);
   if (
$data) { echo $data$lastelem='data'; }
}

// here we go

$depth = array();
$lastelem="";

// set up html

echo "<HTML>\n<HEAD><TITLE>XML parsing for $host:$port</TITLE></HEAD>\n<BODY><PRE>\n";

// connect to sc_serv

$sp=fsockopen($host,$port,&$errno,&$errstr,10);
if(!
$sp) die("Could not contact $host:$port - $errstr\n");

set_socket_blocking($sp,false);

// send request

fputs($sp,"GET /admin.cgi?pass=$password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");

// fetch response, timeout if it takes > 15s

for($i=0$i<30$i++) {
  if(
feof($sp)) break; // exit if connection broken
  
$sp_data.=fread($sp,31337);
  
usleep(500000);
}

// strip HTTP headers so all we have is XML data

$sp_data=ereg_replace("^.*<\?xml ","<?xml ",$sp_data);

/* xml code goes here, here's a plain empty parser */
 
$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");

if (!
xml_parse($xml_parser$sp_data1)) {
  die(
sprintf("XML error: %s at line %d",
  
xml_error_string(xml_get_error_code($xml_parser)),
  
xml_get_current_line_number($xml_parser)));
}

xml_parser_free($xml_parser);

// close up HTML

echo "</PRE></BODY></HTML>";

?>
datagutt is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump