Shoutcast-Script erweitern

Psychognom

Grünschnabel
Habe hier eine php, die mir einige Dinge anzeigt von meinem Shoutcast-Server.
habe dennoch ein Prob.

Möchte gerne noch den DJ(Stream Title), Genre, Stream URl und Stream ICQ angezeigt haben.
wer kann mir da helfen.

Code:
<?php
/////////////////////////////////////////shoutcast song status\\\\\\\\\\\\\\\\\\\
// Author: dstjohn (Mediacast1/Casterclub)
// Date started: 05-03-2002 (10:00A.M)
// Date Ended: 05-03-2002 (6:03 P.M)
// Requirements:
// 1.SHOUTcast streaming server
// 2.Oddcast dsp with winamp/xmms (recomended setup)
// 3.Webserver with php 4.x (Recommended environment: Unix (Freebsd, Red Hat etc.. with Apache 3.x)
// Support: None, post in the casterclub forums
// Core script Information:
// SHOUTcast Song Status was written and developed on Windows Xp with apache and php4.1.2
// Has not been tested on IIs webservers, if you do so and get it to work please let us know
// At the forums (http://casterclub.com/forums)
// Also has been tested on freebsd with apache, php4.1.2 and works fine.
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////open connection\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//connect to shoutcast server
include('config.php');  //you may edit this path to fit your server environment otherwise leave it alone
$scfp = fsockopen("$scip", $scport, &$errno, &$errstr, 30);
 if(!$scfp) {
  $scsuccs=1;
echo''.$scdef.' is Offline';
 }
if($scsuccs!=1){
 fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
 while(!feof($scfp)) {
  $page .= fgets($scfp, 1000);
 }
######################################################################################################################
/////////////////////////part 1 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//define  xml elements
 $loop = array("STREAMSTATUS", "BITRATE");
 $y=0;
 while($loop[$y]!=''){
  $pageed = ereg_replace(".*<$loop[$y]>", "", $page);
  $scphp = strtolower($loop[$y]);
  $$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);
  if($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE)
   $$scphp = urldecode($$scphp);

// uncomment the next line to see all variables
// echo'$'.$scphp.' = '.$$scphp.'<br>';
  $y++;
 }
//end intro xml elements
######################################################################################################################
######################################################################################################################
/////////////////////////part 2\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//get song info and history
 $pageed = ereg_replace(".*<SONGHISTORY>", "", $page);
 $pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed);
 $songatime = explode("<SONG>", $pageed);
 $r=1;
 while($songatime[$r]!=""){
  $t=$r-1;
  $playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);
  $playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);
  $song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);
  $song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);
  $song[$t] = urldecode($song[$t]);

$r++;
 }
//end song info

fclose($scfp);
}

//display stats
if($streamstatus == "1"){
//you may edit the html below, make sure to keep variable intact
echo'
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0"> 
<meta name="ProgId" content="FrontPage.Editor.Document"> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 


<meta content="10" http-equiv="refresh"> 

<center><title>'.$scdef.'</title> 
</head>

<body text="#FFFFFF" bgcolor="#000000"> 
<p style="margin-top: 0; margin-bottom: 0">

<font face="Arial" size="2">

Status:&nbsp;<img src="/images/silverstar/user_online.gif"><br> 

Winamp-Direktlink: <a href="http://mmtn.info:8200/listen.pls" title="Psycho-Radio"> 
<img src="/images/winamp.gif" border="0"></a> 

<p style="margin-top: 0; margin-bottom: 0"> 
<font face="Verdana" size="2" color="#FFFFFF"> 
 
Current Song: '.$song[0].'</font></p> 
Stream Bitrate:&nbsp; '.$bitrate.' kbps</font></p>
<p style="margin-top: 0; margin-bottom: 0"> 
<font face="Verdana" size="2" color="#FFFFFF"> 

Past Songs:</font></p> 
<p style="margin-top: 0; margin-bottom: 0"><font color="#FFFFFF"><font face="Verdana" size="2"> 
1. '.$song[1].'<BR>
2. '.$song[2].'<BR> 
3. '.$song[3].'<BR> 
4. '.$song[4].'<BR> 
5. '.$song[5].'<BR></font><BR> 
</center></body> 

</html>'; 
} 


else 
echo'<html><meta content="10" http-equiv="refresh"> <body><p><font face="Verdana" size="1" color="#000000"><center>Status:&nbsp;<img src="/images/silverstar/user_offline.gif"><br> 
Zur Zeit wird nicht gesendet.<br><br>Nächste Sendetermine entnehmen Sie bitte dem Sendeplan!</center></body></html>'; 
?>
 
Das kann dein Snippet bereits. Siehe Zeile:
PHP:
$loop = array("STREAMSTATUS", "BITRATE");
Dort kannst du weitere XML Childs mit aufnehmen, die du gerne ausgegeben haben moechtest. Vom schlechten Programmierstil moechte ich besser erst garnicht anfangen zu reden.

Cheers,
stanleyB
 
Okay, habe ich hinzugefügt, aber angezeigt wird nichts.

Code:
Status: <img src="/images/silverstar/user_online.gif"><br> 

Winamp-Direktlink: <a href="http://mmtn.info:8200/listen.pls" title="Psycho-Radio"> 
<img src="/images/winamp.gif" border="0"></a> 

<p style="margin-top: 0; margin-bottom: 0"> 
<font face="Verdana" size="2" color="#FFFFFF"> 
 
Current Song: '.$song[0].'</font></p> 
Stream Bitrate:  '.$bitrate.' kbps</font></p>
<p style="margin-top: 0; margin-bottom: 0"> 
<font face="Verdana" size="2" color="#FFFFFF"> 

Past Songs:</font></p> 
<p style="margin-top: 0; margin-bottom: 0"><font color="#FFFFFF"><font face="Verdana" size="2"> 
1. '.$song[1].'<BR>
2. '.$song[2].'<BR> 
3. '.$song[3].'<BR> 
4. '.$song[4].'<BR> 
5. '.$song[5].'<BR></font><BR> 
</center></body>

Nur das wird angezeigt.
 
Ich stell dir einfach mal meine Funktion zur Verfuegung. Hab ich vor langer, langer Zeit fuer ein komisches Webradio geschrieben.

PHP:
function shoutcast_info($file, $port, $pass, $item, $quantity=10) { 
  $fp = @fsockopen ($file, $port, &$errno, &$errstr, 5); 
  if (!$fp) { 
    return 0; 
  } else { 
      fputs($fp, "GET /admin.cgi?pass={$pass}&mode=viewxml HTTP/1.1\r\n" 
                ."User-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); 
      while (!feof($fp)) { 
        $xml .= fgets($fp,1024); 
      }
      fclose($fp); 
      if (is_array($item)) {
        $return_r = array();
        foreach ($item as $value) {
        preg_match("/\<".$value."\>(.*?)\<\/".$value."\>/si", $xml, $return);
        $tempArray = array( $value => $return[1]);
        $return_r = array_merge($return_r, $tempArray);
        }
      return $return_r;
      }
      if ($item == "playlist") {
        $return_r = array();
        preg_match_all("/\<SONG\>(.*?)\<\/SONG\>/si", $xml, $results);
        for($i=0; $i<$quantity && $i<count($results[1]);$i++) {
          preg_match("/\<PLAYEDAT\>(.*?)\<\/PLAYEDAT\>/si", $results[1][$i], $date);
          preg_match("/\<TITLE\>(.*?)\<\/TITLE\>/si", $results[1][$i], $title);
          $date = $date[1];
          $title = $title[1];
          $return_r[] = date("G:i:s", $date)."  ".$title;
        }
      return $return_r; 
      } else {
        preg_match("/\<".$item."\>(.*?)\<\/".$item."\>/si", $xml, $return);
        return $return[1];
      }
  }
}

Aufgerufen wird das Ganze beispielsweise so:

PHP:
$item = array('streamstatus', 
              'currentlisteners',
              'bitrate',
              'servergenre',
              'irc',
              'servertitle');
$value = shoutcast_info("66.66.66.66", "6666", "adminpass", $item);
if ($value[streamstatus] == 0) {
  echo "futurefm.de:9000 - <span class=\"red\">offline</span>";
} else {
  $ircchannel = str_replace("#", "", $value[irc]);
  echo "<b>futurefm.de:9000</b> - <span class=\"green\">online</span><br />\n
        <b>Zuhörer:</b>     {$value[currentlisteners]}<br />\n
        <b>Bitrate:</b>     {$value[bitrate]} kbit/s<br />\n
        <b>Genre:</b>       {$value[servergenre]}<br />\n
        <b>IRC:</b>         <a href=\"irc://irc.de.quakenet.org/{$ircchannel}\">{$value[irc]}</a><br />\n
        <b>Servertitel:</b> {$value[servertitle]}<br />\n";
  }


Cheers,
stanleyB
 
Zurück