Shoutcast for Winamp?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Shoutcast for Winamp?

Post by Cruzado_Mainfrm »

why don't we take a deep look at this?
can we read the song playing information?

check this out

Code: Select all

<?php
$stream_ip = "http://sb.mthn.net";
$stream_port = "8000";

$fp = fsockopen($stream_ip, $stream_port, &$errno, &$errstr, 30);
if ($fp) {
    fputs($fp, "GET / HTTP/1.0\r\n\r\n");
    fputs($fp, "User-Agent: SHOUTcast PHP Proxy 10.1\r\n\r\n");
    fputs($fp, "icy-metadata:1\r\n\r\n");
    while(!feof($fp)) {
        echo fgets($fp,128) . "\n";
    }
} else {
    echo "Cannot open stream. ($errstr)";
    exit;
}
?>
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

what i have so far is to get the stuff from a shoutcast server, but i don't know how to read it with a program

Code: Select all

<?php
$stream_ip = "127.0.0.1"; 
$stream_port = "8000"; 
$errorno = &$errno;
$errorstr = &$errstr;
$fp = fsockopen($stream_ip, $stream_port, $errno, $errstr, 30); 
if ($fp) { 
    fputs($fp, "GET / HTTP/1.0\r\n\r\n"); 
    fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; NetCaptor 7.2.2; .NET CLR 1.1.4322)\r\n\r\n"); 
    fputs($fp, "icy-metadata:1\r\n\r\n"); 
	$i=0;	header('Content-Type:audio/mpeg');
    while(!feof($fp)) { 

        $temp = fgets($fp,128) . "\n";  //ad ."\n" if echoing
		if ($i >= 10) {
		echo $temp;
		}
		$i++;
    } 
} else { 
    echo "Cannot open stream. ($errstr)"; 
    exit; 
}
?>
will echo sumthin' like:

Code: Select all

@:j&#125;Póûj–1?ÿƧ–ÿÿÔ=„Ù/~I5K^ë?oÔbýþêø ¸D†Æ‡Ã¢¼ú @Šñ¼ˆ„ÿó0Äç^ØÂÄ”“w©¦gÍÿj `Õºº
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

I found it! here's the script to get information about the Shoutcast Server:

Code: Select all

<pre>
<?php
$fp = @fsockopen("127.0.0.1", 8000, $errno, $errstr, 30);
if($fp) {
 fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Reader(Mozilla Compatible)\r\n\r\n");
 while(!feof($fp)) {
  $dataset .= fgets($fp, 1000);
 }
fclose($fp);
 $dataset1 = $dataset;
 $headerinfo = ereg_replace("<body>.*","",$dataset);
 $dataset = ereg_replace(".*<body>", "", $dataset);
 $dataset = ereg_replace("</body>.*", ",", $dataset);
 $entries = explode(",",$dataset);
 $listener=$entries[0];
 $status=$entries[1];
 $listenerpeak = $entries[2];
 $maxlisteners=$entries[3];
 $totallisteners=$entries[4];
 $bitrate=$entries[5];
 $songtitel=$entries[6];

}
print_r($entries);
?></pre>
0 is total listeners (total users connected at the moment)
1 is the status(which i guess 0 for offline, and 1 for online)
2 is listener peak (max users connected at the same time
3 is maximun listeners at a time
4 is unique listeners(two connections to server with same ip)
5 is the bitrate in kbps
6 is the artist name plus title name (ex.: Chad Kroeger - Hero)
7 is empty... doesn't contain anything, but i don't know if it will change
Post Reply