Icecast Streaming Media Server Forum Index Icecast Streaming Media Server
Icecast is a Xiph Foundation Project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RDS like metadate update script (PHP)

 
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Dev Branches
View previous topic :: View next topic  
Author Message
BWare
Guest





PostPosted: Mon Sep 12, 2005 11:14 am    Post subject: RDS like metadate update script (PHP) Reply with quote

Heyaz,


In order to do manual metadata updates i wrote a simple PHP script. It's a bit ruff on the edges and only tested with icecast 2.1.0; but here goes:

Code:

<?php
/*
 * icemeta.php
 ***************
 *
 * Connects to icecast server and update
 * metadata information for mountpoint
 *
 * Written by: BWare <bware@s4s.dyndns.org>
 */

function http_get( $host, $port, $request="/ HTTP/1.0" ) {
        $fp = fsockopen($host, $port);

        if (!$fp) {
                return false;
        } else {
                fwrite($fp, "GET $request\r\n\r\n");
                stream_set_timeout($fp, 3);
                $res["data"] = fread($fp, 2000);

                $res["meta"] = stream_get_meta_data($fp);
                fclose($fp);

                if ($res["meta"]['timed_out']) {
                        return false;
                } else {
                        return $res;
                }
        }
}


/*** MAIN ***/
$host = "stream.mydomain.tld";
$port = 8000;
$password="letmein"
$song = $_REQUEST["song"];
$mountlist = array(
                "live",
                "studio",
                "fallback"
);
$defaultmount="live";
$mountpoint = $_REQUEST["mountpoint"];

if ( empty($song) ) {
        $song = "Welcome...";
}
$song = rawurlencode( $song );

if ( $mountpoint != "ALL" ) {
        if ( $mountpoint == "" ) {
                $mountpoint = "$defaultmount";
        }
        $mountlist = array( $mountpoint );
}

foreach( $mountlist as $mountpoint ) {
        $request="/admin/metadata?mode=updinfo&mount=/$mountpoint&song=$song HTTP/1.0\r\n";
        $request.="User-Agent: RDSupdater (Mozilla compatible)\r\n";
        $request.="Authorization: Basic ";
        $request.= base64_encode("admin:$password");
        $request.="\r\n";

        $statsraw = http_get( $host, $port, $request );
}
?>

<html>
 <head>
  <title>Icecast Stream RDS updater</title>
 </head>
 <body>
  <table>
   <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
    <tr>
     <td>Mountpoint</td>
     <td>
      <select name="mountpoint">
       <option value="ALL" selected>ALL</option>
<?php
       foreach( $mountlist as $mountpoint ) {
        echo "<option value=\"$mountpoint\">$mountpoint</option>";
       }
?>
      </select>
     </td>
    </tr>
    <tr>
     <td>RDS Message</td>
     <td>
      <input type"text" name="song" size="80" length="40" value="<?php echo rawurldecode($song);?>" />
     </td>
    </tr>
    <tr>
     <td>&nbsp;</td>
     <td><input type="submit"></td>
    </tr>
   </form>
  </table>
 </body>
</html>
Back to top
Anonymous
Guest





PostPosted: Sat Jan 28, 2006 12:20 am    Post subject: Reply with quote

I have bad news for you, it doesn't work. Maybe it's fault of my server but my friends test it too and they have this same problems.
During starting we have some errors and script doesn't work
Back to top
Anonymous
Guest





PostPosted: Sat Jan 28, 2006 11:41 am    Post subject: Reply with quote

Well, it does work, as I'm using it daily on several servers Wink

I guess you have a too strictly configured server, but my crystal ball is a bit unclear about this, as I don't have any error messages, php version, etc..

Check if your php version allows the fsockopen call and that open_basedir is not restricted.
Back to top
Anonymous
Guest





PostPosted: Tue May 27, 2008 6:07 pm    Post subject: Reply with quote

Well, to do this I'm writting a program called SHOUTrds to Icecast coder. It receives the stream from my program "SHOUTrds" (which provides SHOUTcast stream-title (metadat) updating and next send it to an Icecast server.
The coder is in test-mode now but will soon be available at http://www.SHOUTrds.com under the "Plugins and Tools" link.
Back to top
robertut



Joined: 31 Aug 2007
Posts: 156

PostPosted: Tue Jun 03, 2008 9:33 am    Post subject: Reply with quote

I am using it with some small mods, and an additional VB desktop software I wrote to extract metadata from a custom database:
Code:
<?php
/*
 * icemeta.php
 ***************
 *
 * Connects to icecast server and update
 * metadata information for mountpoint
 *
 * Written by: BWare <bware@s4s.dyndns.org>
 */

function http_get( $host, $port, $request="/ HTTP/1.0" ) {
        $fp = fsockopen($host, $port);

        if (!$fp) {
return false;
        } else {
fwrite($fp, "GET $request\r\n\r\n");
stream_set_timeout($fp, 3);
$res["data"] = fread($fp, 2000);

$res["meta"] = stream_get_meta_data($fp);
fclose($fp);

if ($res["meta"]['timed_out']) {
        return false;
} else {
        return $res;
}
        }
}


/*** MAIN ***/
$host = "stream.mydomain.tld";
$port = 8000;
$password="letmein";
$song = $_REQUEST["song"];
$mountlist = array(
                "live",
                "studio",
                "fallback"
);

$mountlist_all = $mountlist;

$defaultmount="";
$mountpoint = $_REQUEST["mountpoint"];

if ( empty($song) ) {
        $song = "";
}
$song = rawurlencode( $song );

if ( $mountpoint != "ALL" ) {
        if ( $mountpoint == "" ) {
      $mountpoint = "$defaultmount";
        }
        $mountlist = array( $mountpoint );
}

foreach( $mountlist as $mountpoint ) {
        $request="/admin/metadata?mode=updinfo&mount=/$mountpoint&song=$song HTTP/1.0\r\n";
        $request.="User-Agent: RDSupdater (Mozilla compatible)\r\n";
        $request.="Authorization: Basic ";
        $request.= base64_encode("admin:$password");
        $request.="\r\n";

        $statsraw = http_get( $host, $port, $request );
   $song1 = rawurldecode($song);
   echo "Updated metadata for /$mountpoint with: $song1<br>";
}

?>

<html>
 <head>
  <title>Icecast Stream Title metadata updater</title>
<meta name="robots" content="noindex,nofollow">
<meta http-equiv=Content-Type content="text/html; charset=windows-1250">

 </head>
 <body>
  <table>
   <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
    <tr>
     <td>Mountpoint</td>
     <td>
      <select name="mountpoint">

<?php
       foreach( $mountlist_all as $mountpoint ) {
        echo "<option value=\"$mountpoint\">$mountpoint</option>";
       }
?>
      </select>
     </td>
    </tr>
    <tr>
     <td>Title metadata</td>
     <td>
      <input type"text" name="song" size="80" length="40" value="<?php echo rawurldecode($song);?>" />
     </td>
    </tr>
    <tr>
     <td>&nbsp;</td>
     <td><input type="submit"></td>
    </tr>
   </form>
  </table>
 </body>
</html>
Back to top
View user's profile Send private message
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Fri May 29, 2009 9:08 am    Post subject: Reply with quote

This script works great and I have an even shorter script.

Bit HOW do I READ the title / current song / listener count? This is driving me crazy. None of the examples I have found work.


Here's how I update the meta tag:

Code:

<?php
updateMetadata($manchannel,"$server",$port, "$mountpoint", "$user", "$password");

function updateMetadata($string,$server,$port,$mountpoint,$admin,$pass) {
   $string = preg_replace("/ /","%20",$string);
   $currentsonguri = urlencode($string);
   $currentsonguri = preg_replace("/\%2520/","%20",$currentsonguri);
   $fp = fsockopen($server, $port, $errno, $errstr, 3);
   if ($fp) {
         fputs($fp,"GET /admin/metadata.xsl?song=".$currentsonguri."&mount=".urlencode($mountpoint)."&mode=updinfo HTTP/1.0\n");
         fputs($fp,"Authorization: Basic ".base64_encode($admin.":".$pass)."\n");
         fputs($fp,"User-Agent: IcecastDSP (Mozilla Compatible)\n\n");
         fclose($fp);
   }
}
?>

_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Dev Branches All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
subRebel style by ktauber