<?
#################################
#WebNapster Client copyright 2000
#Aakash Kambuj - aakash@kambuj.com
#Kalpak Kothari - kalpak@mit.edu
#################################
#
#You are welcome to modify and distribute this code, but please retain
#this copyright notice above any notices you put. Please send us a
#copy of your modified code.
#
#Napster is a registered trademark of Napster Inc - http://www.napster.com
#
function download($rhost,$rport,$title,$filename) {
$MTU = 2048;
$title = rawurldecode($title);
$title = stripslashes($title);
$filename = rawurldecode($filename);
$filename = stripslashes($filename);
$remote_user = fsockopen($rhost, $rport, &$errstr, &$errno); //open a connection to the remote user
if (!$remote_user){
echo "ERROR $errstr ($errno)<br>\n";
return;
}
//read magic character '1'
$dt = (string)fread($remote_user, 1);
if ($dt != "1") {
print("<br>ERROR Expected magic character '1' from remote user: $dt");
return;
}
fwrite($remote_user, "GET"); // write string "GET"
flush();
//send file name to get
$mess = "idearingwn " . $title . " 0";
// echo "$mess <br>";
fwrite($remote_user, $mess);
//read the size of the mp3 file
$file_length ="";
$temp=0;
for ($i=0;$i<$MTU;$i++){
$temp = (int)fread($remote_user,1);
if ($temp==255){
break;
}
$file_length .= $temp;
}
$mpsize = (int)$file_length;
if ($mpsize <= 0) {
echo "<br>ERROR. Remote user sent an invalid filesize: $mpsize";
fclose($remote_user);
exit;
}
$num = pack("C",255);
// start sending file. indicate browser to download.
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=$filename" );
echo $num; //first byte of mp3 file
$count=1;
do {
$received = fread($remote_user, $MTU);
$count +=$MTU;
echo $received;
} while ($count<$file_length);
fclose($remote_user);
exit;
}
download($rhost,$rport,$title,$filename);
?>
|