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.
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.
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.
$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.