0

I want to ask how i can readout the XML from shoutcast 2 ?

URL: IP:PORT/stats?sid=1

Now how i read the XML data and put the write the values down with php?

Thanks in advance.

Jonas
  • 121,568
  • 97
  • 310
  • 388
Goodpeace
  • 27
  • 1
  • 3

2 Answers2

2

Use SimpleXMLElement. You will do something like this:

$xml = new SimpleXMLElement(file_get_contents("http://{YOUR-SHOUTCAST_SERVER/admin.cgi?mode=viewxml&page=7&sid=".$sid."&pass=".$password"));

where $sid is your stream id and $password your stream admin password.

then extract the fields into variables like this:

$SERVERTITLE = $xml->SERVERTITLE;
$STREAMSTATUS = $xml->STREAMSTATUS;
$BITRATE = $xml->BITRATE;
$CONTENT = $xml->CONTENT;
$SERVERGENRE = $xml->SERVERGENRE;
$SERVERURL = $xml->SERVERURL;
$SONGTITLE = $xml->SONGTITLE;
$MAXLISTENERS = $xml->MAXLISTENERS;
$CURRENTLISTENERS = $xml->CURRENTLISTENERS;
$PEAKLISTENERS = $xml->PEAKLISTENERS;

The reason why I chose page 7 is because it contains the most stats on one page.

johnslippers
  • 81
  • 1
  • 16
-1
$url = "http://ip:port/stats?sid=1";
$nice_url = urlencode($url);
$sc_stats = simplexml_load_file($nice_url);

echo $sc_stats->SERVERTITLE;
echo $sc_stats->BITRATE;
echo $sc_stats->SONGTITLE;

etc.