PDA

View Full Version : Getting stream instead of html


serg_kr
31st October 2006, 17:02
Hi,

I try to connect this shoutcast server
http://205.188.215.226:8000/
from my php page using fsockopen function. As response I receive html code from the server, not stream. But if I enter this link in Winamp, it starts buffering and playing the stream.

How can I get this stream in my web page instead of html text message, like in Winamp? Any ideas?

Thanks for help.

Sawg
31st October 2006, 17:18
Pass mozilla in the beginning of the User-Agent string.

serg_kr
31st October 2006, 18:05
I already did this in my http request. But it did not work.

This is the code:

//connection function
function http_fsearch ($host, $path, $port = 80) {
$conn_host = $host;
$conn_port = $port;

//set real URL
$conn_url = "http://$host:$port$path";

//create connection query
$query = "GET $path HTTP/1.1\r\n" .
"Accept: audio/mpeg mp3, */*\r\n" .
"Host: $host:$port\r\n" .
"Connection: Keep-Alive\r\n" .
"User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n" .
"\r\n";

//open the server
//set_time_limit(60);
$fp = fsockopen($conn_host, $conn_port);
if (!$fp) die("$errstr ($errno)\n");

if (!$fp) { //connection error
return false;
} else {
//send the query
fputs($fp, $query);
//receive results
return $fp;
}
}

//main code

$url = "http://205.188.215.226:8000/";
$urldata = parse_url($url);
if (!$urldata["port"]) {
$urldata["port"] = 80;
}
if (!$urldata["path"]) {
$urldata["path"] = "/";
}
//check if host is ip address
$isp = explode('.', $urldata["host"]);
$myisp = $isp[1].'.'.$isp[0];
if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}/", $myisp)) {
$host = gethostbyaddr($urldata["host"]);//ip
} else {
$host = $urldata["host"]; //host
}
//connecting to server
$fp = http_fsearch($host, $urldata["path"], $urldata["port"]);

if (!$fp) {
echo("Error: your request is not accepted.");
exit;
} else {
while (!feof($fp)) {
$line = fgets($fp, 1024);
echo ($line);
flush();
}
fclose($fp);
}

And all that I have is only html text from the server, not stream.
BTW if I use this link
$url = "http://scfire-chi0l-2.stream.aol.com:80/stream/1048";
it returns me stream music.

Sawg
31st October 2006, 18:08
Ahh.. that's because that isn't a normal SHOUTcast stream, it uses AOL's Ultravox. It doesn't have a publicly available status page.

serg_kr
31st October 2006, 18:18
But how can I get this real stream for "normal" shoucast server instead of its status page? Is it possible to do inside web page? How can winamp connect to such a server and get the stream?

Sawg
31st October 2006, 18:25
Okay, misread the original post. If you want the stream and not the HTML, just drop the user-agent string all together. Or just change it to something that doesn't begin with Mozilla.

serg_kr
31st October 2006, 18:33
Sawg, you are the man!!

I put this line "User-Agent: PHP/class http 0.1\r\n" and it is working now.

Thanks a lot!!!

hackerdork
1st November 2006, 02:15
if you open a URL with winamp is ASSUMES its the stream address so using http://205.188.215.226:8000/ it would connect to tune in, also real media, and windows media player.

~ D