Announcement

Collapse
No announcement yet.

php code for shoutcast status

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

  • #2
    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
    KNSJ.org 89.1 FM San Diego

    Comment


    • #3
      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
      "If you don't like DNAS, write your own damn system"

      So I did

      Comment


      • #4
        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?

        Comment


        • #5
          index.html
          played.html
          "If you don't like DNAS, write your own damn system"

          So I did

          Comment


          • #6
            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
            WACUP Project <‖> "Winamp Ramblings" - Indie Winamp Dev Blog

            Comment


            • #7
              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. ([email protected])
               * @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


              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

              Comment


              • #8
                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
                EDIT: Looks like theres a problem with the php tag.
                ***91; have to be changed to [
                ***93; have to be changed to ]

                Comment


                • #9
                  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)"

                  Comment


                  • #10
                    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
                    "If you don't like DNAS, write your own damn system"

                    So I did

                    Comment


                    • #11
                      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?

                      Comment


                      • #12
                        you've changed these to suit?
                        $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
                        "If you don't like DNAS, write your own damn system"

                        So I did

                        Comment


                        • #13
                          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.

                          Comment


                          • #14
                            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.

                            Comment


                            • #15
                              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
                              "If you don't like DNAS, write your own damn system"

                              So I did

                              Comment

                              Working...
                              X