Old 26th February 2011, 17:09   #1
planetmosh
Junior Member
 
Join Date: Feb 2011
Posts: 2
php code for shoutcast status

the previous version of shoutcast was easy .. anything I needed to display on my website was contained in 7.html

none of the old scripts now work with shoutcast2

After a fruitless search of the interwebs for a script or tutorial maybe you guys could help.

Can anyone direct me to a code snippet that will show Peak Listeners, current listeners, now playing and last 9 songs for the new shoutcast2.
planetmosh is offline   Reply With Quote
Old 26th February 2011, 22:52   #2
Brutish Sailor
Major Dude
 
Brutish Sailor's Avatar
 
Join Date: Jan 2009
Location: San Diego CA
Posts: 998
Send a message via Skype™ to Brutish Sailor
The new server doesnt support 7html. When 7html was discovered, it was more of a hack to supporting metadata, granted is does use MUCH less bandwidth /w massive listener counts than conventional php stat displays. Then again, something could have changed over the last 7 months and I just don't know
Brutish Sailor is offline   Reply With Quote
Old 26th February 2011, 23:56   #3
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
Quote:
Originally Posted by Brutish Sailor View Post
The new server doesnt support 7html. When 7html was discovered, it was more of a hack to supporting metadata, granted is does use MUCH less bandwidth /w massive listener counts than conventional php stat displays. Then again, something could have changed over the last 7 months and I just don't know
you can mitigate the bandwidth issue by "caching" the result, and only getting new data from DNAS every so often

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 27th February 2011, 09:12   #4
planetmosh
Junior Member
 
Join Date: Feb 2011
Posts: 2
which brings us back to the original question.

what is the name of the file that I need to extract the data from now that 7.html does not exist?
planetmosh is offline   Reply With Quote
Old 27th February 2011, 11:44   #5
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
index.html
played.html

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 27th February 2011, 16:48   #6
DrO
 
Join Date: Sep 2003
Posts: 27,873
http://dev.winamp.com/wiki/SHOUTcast...stration_Pages lists all of the options for querying things from the v2 DNAS either as public pages or as private pages for specific admin details along with the means to only get certain sets of data instead of a full-blown xml response (which the default output has been reduced since the initial v2 build 7 + 10 was outputting stuff that was never populated).

-daz
DrO is offline   Reply With Quote
Old 1st March 2011, 11:38   #7
MADxHAWK
Senior Member
 
Join Date: Jan 2010
Posts: 181
Hi,

if you have access to the admin.cgi of the DNAS you could use this script:


PHP Code:
<?php
/**
 *
 * @package:    shoutcast
 * @version:    $Id: shoutcast.php 4 2011-12-02 17:27:36Z MADxHAWK $
 * @copyright:    (c) 2010 by Martin H. (madxhawk@radio-blackpearl.de)
 * @licence:    [url]http://opensource.org/licenses/gpl-license.php[/url] GNU Public License
 *
 */

// ----------------------------------------------------------------------------
// You need to change data to your specific use
// ----------------------------------------------------------------------------
$useragent    "Mozilla (DNAS 2 Statuscheck)";
$sc_host    '127.0.0.1';
$sc_port    '8000';
$sc_user    'admin';
$sc_pass    'your_pass_here';
$sc_sid        '1';


// ----------------------------------------------------------------------------
// DO NOT EDIT
// ----------------------------------------------------------------------------

//init curl connection
$ch curl_init($sc_host '/admin.cgi?mode=viewxml&sid=$sc_sid');

// set curl connection parameter
curl_setopt($chCURLOPT_PORT$sc_port);
curl_setopt($chCURLOPT_USERAGENT$useragent);
curl_setopt($chCURLOPT_TIMEOUT5);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
curl_setopt($chCURLOPT_USERPWD$sc_user ':' $sc_pass);

// connect to shoutcastserver
$curl curl_exec($ch);

// now get the xml data
if ($curl)
{
    
$xml = @simplexml_load_string($curl);

    
$dnas_data = array (
        
'CURRENTLISTENERS'    => (string)$xml->CURRENTLISTENERS,
        
'PEAKLISTENERS'        => (string)$xml->PEAKLISTENERS,
        
'MAXLISTENERS'        => (string)$xml->MAXLISTENERS,
        
'REPORTEDLISTENERS'    => (string)$xml->REPORTEDLISTENERS,
        
'AVERAGETIME'        => (string)$xml->AVERAGETIME,
        
'SERVERGENRE'        => (string)$xml->SERVERGENRE,
        
'SERVERURL'            => (string)$xml->SERVERURL,
        
'SERVERTITLE'        => (string)$xml->SERVERTITLE,
        
'SONGTITLE'            => (string)$xml->SONGTITLE,
        
'NEXTTITLE'            => (string)$xml->NEXTTITLE,
        
'SONGURL'            => (string)$xml->SONGURL,
        
'IRC'                => (string)$xml->IRC,
        
'ICQ'                => (string)$xml->ICQ,
        
'AIM'                => (string)$xml->AIM,
        
'STREAMHITS'        => (string)$xml->STREAMHITS,
        
'STREAMSTATUS'        => (string)$xml->STREAMSTATUS,
        
'BITRATE'            => (string)$xml->BITRATE,
        
'CONTENT'            => (string)$xml->CONTENT,
        
'VERSION'            => (string)$xml->VERSION,
    );

    
// Get Listeners and Songhistory
    
if ($dnas_data['STREAMSTATUS'] == 1)
    {
        
// store listener in array
        
foreach ($xml->LISTENERS->LISTENER as $listener)
        {
            
$sc_data['LISTENERS'][] = array(
                
'HOSTNAME' => (string) $listener->HOSTNAME,
                
'USERAGENT' => (string) $listener->USERAGENT,
                
'CONNECTTIME' => (string) $listener->CONNECTTIME,
                
'POINTER' => (string) $listener->POINTER,
                
'UID' => (string) $listener->UID,
            );
        }

        
// store songhistory in array
        
foreach ($xml->SONGHISTORY->SONG as $song)
        {
            
$sc_data['SONGHISTORY'][] = array(
                
'PLAYEDAT' => (string) $song->PLAYEDAT,
                
'TITLE' => (string) $song->TITLE,
            );
        }
    }
}
else
{
    
$dnas_data = array('ERROR' => 'Could not connect to dnas-server!');
}
?>
EDIT: Looks like theres a problem with the php tag.
***91; have to be changed to [
***93; have to be changed to ]

This script reads all infos from the xml-file generatet by DNAS and make them available as an array. you can simply include the file in your current php website.

If you want to view the current song you can access it by


Quote:
echo dnas_data['SONGTITLE'];

Hope that helps


EDIT: the php CURL-Lib must be installed, but thats this lib afaik is standard on php 5 and higher installations.

Greeting
MAD
MADxHAWK is offline   Reply With Quote
Old 14th March 2011, 05:08   #8
neralex
Major Dude
 
Join Date: Mar 2011
Posts: 576
hey MADxHAWK!

do you have test it? i have no output with echo. can you fixit, please?

examples:
PHP Code:
echo ($)dnas_data ['SONGTITLE'];
echo 
$xml->SONGTITLE
Quote:
EDIT: Looks like theres a problem with the php tag.
***91; have to be changed to [
***93; have to be changed to ]
neralex is offline   Reply With Quote
Old 21st March 2011, 16:54   #9
pimphesus
Junior Member
 
Join Date: Mar 2011
Posts: 7
Is it possible to change this to use the v1 server too?

Does it work if I change this var?

PHP Code:
$useragent "Mozilla (DNAS 1 Statuscheck)"
pimphesus is offline   Reply With Quote
Old 21st March 2011, 21:19   #10
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
It's not that simple ... you need to change the URL

possibly from

PHP Code:
$ch curl_init($sc_host '/admin.cgi?mode=viewxml&sid=$sc_sid'); 
to

PHP Code:
$ch curl_init($sc_host '/admin.cgi?mode=viewxml'); 
and remove

PHP Code:
       'NEXTTITLE'            => (string)$xml->NEXTTITLE
NOTE: I have not checked the above, but I'm confident

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 22nd March 2011, 00:06   #11
pimphesus
Junior Member
 
Join Date: Mar 2011
Posts: 7
I have made the suggested changes to the script, but I'm getting the could not connect error. I have 3 different streams to test this with and tried them all. None of them are v2. Do I need to include the path to curl on that page?
pimphesus is offline   Reply With Quote
Old 22nd March 2011, 00:35   #12
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
you've changed these to suit?
Quote:
$sc_host = '127.0.0.1';
$sc_port = '8000';
$sc_user = 'admin';
$sc_pass = 'your_pass_here';
also ... does your host allow outgoing connections? most DO NOT

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 22nd March 2011, 01:10   #13
pimphesus
Junior Member
 
Join Date: Mar 2011
Posts: 7
Well, they have allowed it in the past. I'd say a few years ago. I just sent them a ticket, so I should know in the morning, hopefully. Do you think they would re-enable this if i asked them? I've been with the same host since 2002. Doubt that makes a difference.

@jaromanda - Yes, I did make the necessary changes to those variables too, but the truth is I've been looking for a flash player and a script like this that works on my server for days.
pimphesus is offline   Reply With Quote
Old 22nd March 2011, 07:24   #14
MADxHAWK
Senior Member
 
Join Date: Jan 2010
Posts: 181
Hi,

sorry have missed this post :S

This script uses the phpCURL libary to connect to the shoutcast server. If you dont get any data maybe this lib is not installed on your server/webspace. Also most free webspacehoster dont allow external connections (like funpic for example).

Look for the line:
code:
$curl = curl_exec($ch);

after add:
code:
var_dump($curl)

This line will dump the data curl gets.


You can use this script with a shoutcast 1 also. you just have to change the line like jaromanda sugested. But you wont get all data from shoutcast 1. For example shoutcast 1 provided also webhits, admin logins and a few more data that shoutcast 2 doesnt.

To get an output you need this line for example: (sorry there was a typo in the example)
echo $dnas_data ['SONGTITLE'];

This line wont give you any output:
echo $xml->SONGTITLE;


A simple html file to get the current song and songhistory could look something like this:

current_song.php
code:

<html>
<head>
<title>Currently played song</title>
</head>
<body>
<?php include("/path/to/shoutcast.php"); ?>
welcome to my station <br />
<br />
Now playing: <?php echo $dnas_data['SONGTITLE']; ?><br />
<br />
Last played songs:<br />
<?php
foreach ($sc_data['SONGHISTORY'] as $song)
{
echo "[" . date('H:i', $song['PLAYEDAT']) . "] - " . $song['TITLE'] . "<br />;
}
?>
</body>
</html>



The file have to be named *.php NOT *.htm or *.html !! else the phpcode wont be parsed.

Maybe i will write a shoutcast class working where you can select weather to use curl or fsockopen for connection to shoutcast working with both versions of the DNAS.
MADxHAWK is offline   Reply With Quote
Old 22nd March 2011, 07:48   #15
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
Quote:
Originally Posted by MADxHAWK View Post
Maybe i will write a shoutcast class working where you can select weather to use curl or fsockopen for connection to shoutcast working with both versions of the DNAS.
why not also a straight file_get_contents with a context that sets a appropriate useragent ... works for my host

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 22nd March 2011, 08:42   #16
MADxHAWK
Senior Member
 
Join Date: Jan 2010
Posts: 181
The script is for radio stations not for Listeners (you need admin access to the DNAS)

The most common problem is, most webspace Hoster still have php_save_mode restrictions active and these restrictions will block all external fileaccess. I have used phpcurl, cause it a simple and easy way to get the data i need. Even mor simple than using fsockopen or file_get_contend.
With fsockopen and file_get_contend you have to open the connection with

http://login:password@streamurl:port and i dont like that way to transmit the logindata ;)

and thats another reason, why i desided to use php-curl.
MADxHAWK is offline   Reply With Quote
Old 22nd March 2011, 09:10   #17
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
ok, good explanation

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 22nd March 2011, 15:25   #18
pimphesus
Junior Member
 
Join Date: Mar 2011
Posts: 7
Well the host has never been a free one that I'm using, but as I said in the earlier post, they have allowed outgoing connections in the past. They definitely have curl installed. I know I'm the admin of these stations because I made them. I can safely consider myself at least above a novice in php since I built my stations site in nothing but php & mysql. Here is my code for the array output:

code:

elseif( $_GET['q'] == "m" )
{
include_once "shoutcast.php";
//print_r($dnas_data); To Get the Error
echo $dnas_data['SONGTITLE'];
}



I'm still waiting on a reply from the host to verify if they allow it or not, but based on the scripts I've tried, my opinion is that they don't.
pimphesus is offline   Reply With Quote
Old 22nd March 2011, 23:03   #19
neralex
Major Dude
 
Join Date: Mar 2011
Posts: 576
Quote:
Originally Posted by MADxHAWK View Post
Hi,

sorry have missed this post :S

This script uses the phpCURL libary to connect to the shoutcast server. If you dont get any data maybe this lib is not installed on your server/webspace. Also most free webspacehoster dont allow external connections (like funpic for example).

Look for the line:
code:
$curl = curl_exec($ch);

after add:
code:
var_dump($curl)

This line will dump the data curl gets.

To get an output you need this line for example: (sorry there was a typo in the example)
echo $dnas_data ['SONGTITLE'];

This line wont give you any output:
echo $xml->SONGTITLE;
hey MADxHAWK!

thanks for your reply but the script is not working. i become a redirect to the index.html. can you test your script before you post it, please.

my questions:
why is the curl not close and/or where is the right place for this line?
code:
curl_close($ch);


why is'nt in your script a call to the port?
code:
$ch = curl_init($sc_host . '/admin.cgi?mode=viewxml&sid=$sc_sid');


why give the the sc_serv2 a redirect?
i have try in my putty:
code:
curl -g -u admin:PASSWORD domain.tld:PORT/admin.cgi?mode=viewxml&sid=1


greets
neralex is offline   Reply With Quote
Old 25th March 2011, 14:13   #20
pimphesus
Junior Member
 
Join Date: Mar 2011
Posts: 7
So I got sick of waiting for a response for the ticket I sent in and gave my host a call and they pretty much told me that I needed to change my shoutcast servers to port 80, which is apparently the only way to get past their firewall. So how is that supposed to work when two of my servers are free servers and I have no access to their configs?

Edit: making a similar reply to the ticket I sent.
pimphesus is offline   Reply With Quote
Old 26th March 2011, 16:03   #21
MADxHAWK
Senior Member
 
Join Date: Jan 2010
Posts: 181
Hi pimphesus,

well the script works fine, im using it on my own station. But you are right, i realy forgot the line
PHP Code:
curl_close($ch); 
This line should be added befor
PHP Code:
?> 
Quote:
why is'nt in your script a call to the port?
code:
$ch = curl_init($sc_host . '/admin.cgi?mode=viewxml&sid=$sc_sid');
The port is set. Take a look at this line:
PHP Code:
curl_setopt($chCURLOPT_PORT$sc_port); 
Quote:
So I got sick of waiting for a response for the ticket I sent in and gave my host a call and they pretty much told me that I needed to change my shoutcast servers to port 80, which is apparently the only way to get past their firewall. So how is that supposed to work when two of my servers are free servers and I have no access to their configs?

Edit: making a similar reply to the ticket I sent.
They blocked all ports except Port 80? I would change hoster emediatly LOL.
1. you have to decide running a webserver or a shoutcast, both doesnt work cause webserver also run on port 80.
2. if the realy only allow port 80 you shoutcast wont run ayway cause you need 2 ports for shoutcast, portbase and portbase +1, so you would need port 80 and 81

-MAD
MADxHAWK is offline   Reply With Quote
Old 26th March 2011, 23:30   #22
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
Quote:
Originally Posted by MADxHAWK View Post
2. if the realy only allow port 80 you shoutcast wont run ayway cause you need 2 ports for shoutcast, portbase and portbase +1, so you would need port 80 and 81

-MAD
a) there's a difference between incoming and outgoing connections
b) also, just because the webhost has port restrictions don't mean the shoutcast host has restrictions
c) MOST cheap/free webhosts do not allow outgoing requests on "exotic" ports ... i.e. they will allow http(80), probably https(443), maybe ftp and maybe a few others

Is it just me or are shoutcast users getting dumber?
jaromanda is offline   Reply With Quote
Old 27th March 2011, 00:55   #23
MADxHAWK
Senior Member
 
Join Date: Jan 2010
Posts: 181
ok thought it was the server with the restrictions shoutcast is running on, sorry.

anyway i pay less than 3us$/month for my privat webspace and dont have such restrictions

try to start shoutcast on port 80 when a webserver is running, i bet shoutcast wouldnt start.

shoutcast using port 80 for incoming and outgoing connects and the webserve to, it wont work

-MAD
MADxHAWK is offline   Reply With Quote
Old 16th May 2011, 09:50   #24
m4xin30n
Junior Member
 
Join Date: May 2011
Posts: 1
Nice script!
But I encountered a problem. This didn't work for me:
PHP Code:
$ch curl_init($sc_host '/admin.cgi?mode=viewxml&sid=$sc_sid'); 
So I changed it to:
PHP Code:
$ch curl_init($sc_host '/admin.cgi?sid=' $sc_sid '&mode=viewxml'); 
I wonder why no one else had this problem.
m4xin30n is offline   Reply With Quote
Old 19th May 2011, 04:31   #25
hackerdork
Forum King
 
hackerdork's Avatar
 
Join Date: Feb 2006
Location: Earth Circa sometime.
Posts: 3,297
just an FYI all this is clear text so the username and password can be intercepted to your shoutcast admin interface. why not read 7.html or last.html neigher require you to use the username and password at all.

I have a now playing that inside a wordpress page template and it shows the now playing and even puts in a link to amazon to purchase that track if its on amazon. Less than 40 lines of php code and it doesn't send the admin username or password. as its not needed to read the now playing. Also less overhead on the shoutcast server as well.

~ According to the ship's log we're down to our last 3000 vomit bags.It'll never be enough.
search the forums! don't PM me on how-to, or ask me to setup you system. you do it so you learn.
hackerdork is offline   Reply With Quote
Old 30th October 2011, 16:43   #26
ridz
Senior Member
 
Join Date: Oct 2011
Posts: 105
i got

string(112) "Click HERE for redirect." when i tried to echo $dnas_data['SONGTITLE'];

what could be the problem?
ridz is offline   Reply With Quote
Old 30th October 2011, 17:24   #27
ridz
Senior Member
 
Join Date: Oct 2011
Posts: 105
it now works by changing URL to

$ch = curl_init($sc_host . '/admin.cgi?sid=' . $sc_sid . '&mode=viewxml');


anyway, how can i make the song update in real time? i dont know ajax
ridz is offline   Reply With Quote
Old 1st February 2012, 13:52   #28
iccbroadcast
Junior Member
 
Join Date: Jan 2012
Posts: 31
Hi guys...

I have taylored a php munin plugin using your code.
It is also based on the stable shoutcast 198 munin plugin public at the repository.
It works great: now we have v2 graphs!!!

Since it uses most of your essential code, I wonder wether I could make it available at the munin repository so it can be useable.

Thanks, regards
iccbroadcast is offline   Reply With Quote
Old 1st February 2012, 15:53   #29
iccbroadcast
Junior Member
 
Join Date: Jan 2012
Posts: 31
Also note:
the 32 bit binary uses UNIQUELISTENERS as XML tag
whereas
the 64 bit binary uses REPORTEDLISTENERS as XML tag

take this into account when working on it!
iccbroadcast is offline   Reply With Quote
Old 1st February 2012, 16:07   #30
DrO
 
Join Date: Sep 2003
Posts: 27,873
are you sure you're using the same and current build as REPORTEDLISTENERS was removed in the RC builds and also there is no platform specific differences on the stats reporting as it would server no purpose and would completely defeat the whole point of the v2 DNAS acting the same on any platform it is run on.

http://wiki.winamp.com/wiki/SHOUTcas...2_XML_Reponses is pretty clear on what values are provided. i'd suggest re-reading and making sure you're DNAS builds are current.

-daz
DrO is offline   Reply With Quote
Old 2nd February 2012, 07:37   #31
iccbroadcast
Junior Member
 
Join Date: Jan 2012
Posts: 31
well.... I actually simply downloaded the binaries, i didnt build/compile anything, get them from winamp, paste, and let them run flawlesly... maybe I'm doing wrong.

and, about the difference, I simply noted that, using my brand new new plugin on different (production, lab was done in a 64 bit machine) 32bit machines, I missed unique listeners field information... At first I was confused, since I simply copy/paste it, but, as I directly put the url on my browser against the conflicting servers, I could see the difference when comparing with the 64 bit binary... In the browser window opened at the testbed system 64bit I saw a flag (is the fourth if I remember) REPORTEDLISTENERS whereas in the 32bit server it appeared in the same position as UNIQUELISTENERS

As a side note... my plugin is not working with munin in the 32 bit machines, although it runs perfect by munin-node it doesnt feed graphs to the munin server... all this work rock stable in the 64 bit machines, but I guess its just coincident, and strictly munin stuff related, and I have to let munin people discuss about it
iccbroadcast is offline   Reply With Quote
Old 2nd February 2012, 08:30   #32
DrO
 
Join Date: Sep 2003
Posts: 27,873
i will repeat myself, REPORTEDLISTENERS is not a field which is returned by _any_ of the current builds and you really need to confirm what version of the DNAS builds you are using.

-daz
DrO is offline   Reply With Quote
Old 31st August 2012, 07:06   #33
adampoconnor
Junior Member
 
Join Date: Aug 2012
Posts: 1
Reply

Quote:
Originally Posted by MADxHAWK View Post
Hi,

if you have access to the admin.cgi of the DNAS you could use this script:


PHP Code:
<?php
/**
 *
 * @package:    shoutcast
 * @version:    $Id: shoutcast.php 4 2011-12-02 17:27:36Z MADxHAWK $
 * @copyright:    (c) 2010 by Martin H. (madxhawk@radio-blackpearl.de)
 * @licence:    [url]http://opensource.org/licenses/gpl-license.php[/url] GNU Public License
 *
 */

// ----------------------------------------------------------------------------
// You need to change data to your specific use
// ----------------------------------------------------------------------------
$useragent    "Mozilla (DNAS 2 Statuscheck)";
$sc_host    '127.0.0.1';
$sc_port    '8000';
$sc_user    'admin';
$sc_pass    'your_pass_here';
$sc_sid        '1';


// ----------------------------------------------------------------------------
// DO NOT EDIT
// ----------------------------------------------------------------------------

//init curl connection
$ch curl_init($sc_host '/admin.cgi?mode=viewxml&sid=$sc_sid');

// set curl connection parameter
curl_setopt($chCURLOPT_PORT$sc_port);
curl_setopt($chCURLOPT_USERAGENT$useragent);
curl_setopt($chCURLOPT_TIMEOUT5);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
curl_setopt($chCURLOPT_USERPWD$sc_user ':' $sc_pass);

// connect to shoutcastserver
$curl curl_exec($ch);

// now get the xml data
if ($curl)
{
    
$xml = @simplexml_load_string($curl);

    
$dnas_data = array (
        
'CURRENTLISTENERS'    => (string)$xml->CURRENTLISTENERS,
        
'PEAKLISTENERS'        => (string)$xml->PEAKLISTENERS,
        
'MAXLISTENERS'        => (string)$xml->MAXLISTENERS,
        
'REPORTEDLISTENERS'    => (string)$xml->REPORTEDLISTENERS,
        
'AVERAGETIME'        => (string)$xml->AVERAGETIME,
        
'SERVERGENRE'        => (string)$xml->SERVERGENRE,
        
'SERVERURL'            => (string)$xml->SERVERURL,
        
'SERVERTITLE'        => (string)$xml->SERVERTITLE,
        
'SONGTITLE'            => (string)$xml->SONGTITLE,
        
'NEXTTITLE'            => (string)$xml->NEXTTITLE,
        
'SONGURL'            => (string)$xml->SONGURL,
        
'IRC'                => (string)$xml->IRC,
        
'ICQ'                => (string)$xml->ICQ,
        
'AIM'                => (string)$xml->AIM,
        
'STREAMHITS'        => (string)$xml->STREAMHITS,
        
'STREAMSTATUS'        => (string)$xml->STREAMSTATUS,
        
'BITRATE'            => (string)$xml->BITRATE,
        
'CONTENT'            => (string)$xml->CONTENT,
        
'VERSION'            => (string)$xml->VERSION,
    );

    
// Get Listeners and Songhistory
    
if ($dnas_data['STREAMSTATUS'] == 1)
    {
        
// store listener in array
        
foreach ($xml->LISTENERS->LISTENER as $listener)
        {
            
$sc_data['LISTENERS'][] = array(
                
'HOSTNAME' => (string) $listener->HOSTNAME,
                
'USERAGENT' => (string) $listener->USERAGENT,
                
'CONNECTTIME' => (string) $listener->CONNECTTIME,
                
'POINTER' => (string) $listener->POINTER,
                
'UID' => (string) $listener->UID,
            );
        }

        
// store songhistory in array
        
foreach ($xml->SONGHISTORY->SONG as $song)
        {
            
$sc_data['SONGHISTORY'][] = array(
                
'PLAYEDAT' => (string) $song->PLAYEDAT,
                
'TITLE' => (string) $song->TITLE,
            );
        }
    }
}
else
{
    
$dnas_data = array('ERROR' => 'Could not connect to dnas-server!');
}
?>
EDIT: Looks like theres a problem with the php tag.
***91; have to be changed to [
***93; have to be changed to ]

This script reads all infos from the xml-file generatet by DNAS and make them available as an array. you can simply include the file in your current php website.

If you want to view the current song you can access it by





Hope that helps


EDIT: the php CURL-Lib must be installed, but thats this lib afaik is standard on php 5 and higher installations.

Greeting
MAD

Hello Mad,

Your code works great except for the fact that when I load the page all of the XML data shows up right away. This is obviously an issue seeing as I can't do a custom way. If you have any way of fixing this please let me know.

Regards,

Adam

EDIT: It also keeps screwing with the <title> of the website.
adampoconnor is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Site Design

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