Old 7th October 2012, 00:26   #1
kreza
Junior Member
 
Join Date: Jan 2009
Posts: 4
Easy PHP stats grab for Shoutcast DNAS 2

Hi guys,

Sometimes you just want the individual data from the shoutcast server. As I'm not an XML/PHP guru, it took me a long time to figure out how to do this! Posting it here as I think other people might find it useful.

The below code will give you the current listener count for your station;

code:

<?php
$url = "http://yourdomain.com:8000/stats?sid=1";
$nice_url = urlencode($url);
$sc_stats = simplexml_load_file($nice_url);
echo $sc_stats->CURRENTLISTENERS;
?>



You should be able to replace CURRENTLISTENERS with any of the variables from the wiki;

http://wiki.winamp.com/wiki/SHOUTcas...Server_Summary

Cheers,


Kreza
kreza is offline   Reply With Quote
Old 17th October 2012, 15:40   #2
Wavestreaming
Major Dude
 
Wavestreaming's Avatar
 
Join Date: Apr 2004
Location: United Kingdom
Posts: 1,563
Send a message via AIM to Wavestreaming Send a message via Yahoo to Wavestreaming
Thats a really nice simple way of doing it SimpleXML has made things much easier when it comes to parsing XML with PHP.

We've also built a free PHP class to do this on github, it also handles SHOUTcast v1 servers too. Plus rumour has it that the next version of the DNAS supports JSON which will completely eliminate the need for PHP allowing you to request stats client-side from the users browser using jQuery!

https://github.com/Wavestreaming/SHOUTcast-PHP-Class
https://github.com/Wavestreaming/jquery-shoutcast
Wavestreaming is offline   Reply With Quote
Old 7th July 2014, 03:16   #3
singfa
Junior Member
 
Join Date: Jul 2014
Posts: 2
PHP stats grab for Shoutcast DNAS 1 ?

I'm searching for long time a simple way to extract the shoutcast status data.
Thank you kreza for this simple code that working well.

I would like to know how I can use this method for SHOUTcast DNAS v.1 ?
I tried to use your code for shoutcast v.1 but as expected, does not work.

It gives me an error:

Warning: simplexml_load_file () [function.simplexml-load-file]: I / O warning: failed to load external entity "http% 3A% 2F% 2F94.23.8.191% 3A8888% 2Fstats% 3Fsid% 3D1 "in /xxxx/xxx/public_html /xxxx/status/shoutcast-conf.php on line 7


This line is:

$sc_stats = simplexml_load_file($nice_url);

Any help is welcome.

Thanks
singfa is offline   Reply With Quote
Old 7th July 2014, 09:19   #4
DrO
 
Join Date: Sep 2003
Posts: 27,873
you really should just be using a v2.x DNAS than trying to hack things to work on the unsupported v1.x DNAS as you can get at the stats with properly documented API methods with the v2.x DNAS.
DrO is offline   Reply With Quote
Old 7th July 2014, 12:06   #5
Colin2
Junior Member
 
Join Date: Dec 2011
Posts: 6
Quote:
Originally Posted by singfa View Post
I would like to know how I can use this method for SHOUTcast DNAS v.1 ?
code:
<?php
ini_set("user_agent", "Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0");
$html = file_get_contents("http://94.23.8.191:8888/");
preg_match('#<b>(\d+) of \d+ listeners#i', $html, $matches);
echo isset($matches[1]) ? $matches[1] : 0;
?>

Colin2 is offline   Reply With Quote
Old 7th July 2014, 12:18   #6
DrO
 
Join Date: Sep 2003
Posts: 27,873
seriously? scraping the page? even the v1.x DNAS has means to get the stats without doing that sort of heinous method above *shudders*
DrO is offline   Reply With Quote
Old 7th July 2014, 14:13   #7
singfa
Junior Member
 
Join Date: Jul 2014
Posts: 2
I tried your code, Colin2 but I have an error:

Warning: file_get_contents(http://94.23.8.191:8888/) [function.file-get-contents]: failed to open stream: Connection refused in /xxx/xxx/public_html/xxx/status/xxx-conf.php on line 5
0
singfa 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