Login   Register  
PHP Classes
elePHPant
Icontem

File: demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Henrik Malmberg  >  shoutcast.class.php  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: A demonstration of the class
Class: shoutcast.class.php
Gets info from SHOUTcast XML
Author: By
Last change:
Date: 11 years ago
Size: 3,116 bytes
 

Contents

Class file image Download
<?php
include("shoutcast.class.php");

function 
ConvertSeconds($seconds) {
    
$tmpseconds substr("00".$seconds 60, -2);
    if (
$seconds 59) {
        if (
$seconds 3599) {
            
$tmphours substr("0".intval($seconds 3600), -2);
            
$tmpminutes substr("0".intval($seconds 60 - (60 $tmphours)), -2);
            
            return (
$tmphours.":".$tmpminutes.":".$tmpseconds);
        } else {
            return (
"00:".substr("0".intval($seconds 60), -2).":".$tmpseconds);
        }
    } else {
        return (
"00:00:".$tmpseconds);
    }
}

$shoutcast = new ShoutCast();
$shoutcast->host "localhost";
$shoutcast->port 8000;
$shoutcast->passwd "YOURPASSWORDGOESHERE";

if (
$shoutcast->openstats()) {
    
// We got the XML, gogogo!..
    
if ($shoutcast->GetStreamStatus()) {
        echo 
"<b>".$shoutcast->GetServerTitle()."</b> (".$shoutcast->GetCurrentListenersCount()." of ".$shoutcast->GetMaxListenersCount()." listeners, peak: ".$shoutcast->GetPeakListenersCount().")<p>\n\n";
        
        echo 
"<table border=0 cellpadding=0 cellspacing=0>\n";
        echo 
"<tr><td width=\"180\"><b>Server Genre: </b></td><td>".$shoutcast->GetServerGenre()."</td></tr>\n";
        echo 
"<tr><td><b>Server URL: </b></td><td><a href=\"".$shoutcast->GetServerURL()."\">".$shoutcast->GetServerURL()."</a></td></tr>\n";
        echo 
"<tr><td><b>Server Title: </b></td><td>".$shoutcast->GetServerTitle()."</td></tr><tr><td colspan=2>&nbsp;</td></tr>\n";
        
        echo 
"<tr><td><b>Current Song: </b></td><td>".$shoutcast->GetCurrentSongTitle()."</td></tr>\n";
        echo 
"<tr><td><b>BitRate: </b></td><td>".$shoutcast->GetBitRate()."</td></tr><tr><td colspan=2>&nbsp;</td></tr>\n";
        
        echo 
"<tr><td><b>Average listen time: </b></td><td>".ConvertSeconds($shoutcast->GetAverageListenTime())."</td></tr><tr><td colspan=2>&nbsp;</td></tr>\n";
        
        echo 
"<tr><td><b>IRC: </b></td><td>".$shoutcast->GetIRC()."</td></tr>\n";
        echo 
"<tr><td><b>AIM: </b></td><td>".$shoutcast->GetAIM()."</td></tr>\n";
        echo 
"<tr><td><b>ICQ: </b></td><td>".$shoutcast->GetICQ()."</td></tr><tr><td colspan=2>&nbsp;</td></tr>\n";
        
        echo 
"<tr><td><b>WebHits Count: </b></td><td>".$shoutcast->GetWebHitsCount()."</td></tr>\n";
        echo 
"<tr><td><b>StreamHits Count: </b></td><td>".$shoutcast->GetStreamHitsCount()."</td></tr>\n";
        echo 
"</table><p>";
        
        echo 
"<b>Song history;</b><br>\n";
        
$history $shoutcast->GetSongHistory();
        if (
is_array($history)) {
            for (
$i=0;$i<sizeof($history);$i++) {
                echo 
"[".$history[$i]["playedat"]."] - ".$history[$i]["title"]."<br>\n";
            }
        } else {
            echo 
"No song history available..";
        }
        echo 
"<p>";
        
        echo 
"<b>Listeners;</b><br>\n";
        
$listeners $shoutcast->GetListeners();
        if (
is_array($listeners)) {
            for (
$i=0;$i<sizeof($listeners);$i++) {
                echo 
"[".$listeners[$i]["uid"]."] - ".$listeners[$i]["hostname"]." using ".$listeners[$i]["useragent"].", connected for ".ConvertSeconds($listeners[$i]["connecttime"])."<br>\n";
            }
        } else {
            echo 
"Noone listens right now..";
        }
    } else {
        echo 
"Server is up, but no stream available..";
    }
} else {
    
// Ohhh, damnit..
    
echo $shoutcast->geterror();
}
?>