1

I am trying to download a rapidshare file using its "download" subroutine as a free user. The following is the code that I use to get response from the subroutine.

function rs_download($params)
{
    $url = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=".$params['fileid']."&filename=".$params['filename'];

    $reply = @file_get_contents($url);

    if(!$reply)
    {
        return false;
    }

    $result_arr = array();
    $result_keys = array(0=> 'hostname', 1=>'dlauth', 2=>'countdown_time', 3=>'md5hex');

    if( preg_match("/DL:(.*)/", $reply, $reply_matches) )
    {
        $reply_altered = $reply_matches[1];        
    }
    else
    {
        return false;
    }

    foreach( explode(',', $reply_altered) as $index => $value )
    {
        $result_arr[ $result_keys[$index] ] = $value;        
    }

    return $result_arr;

}

For instance; trying to download this... http://rapidshare.com/files/440817141/AutoRun__live-down.com_Champ.rar

I pass the fileid(440817141) and filename(AutoRun__live-down.com_Champ.rar) to rs_download(...) and I get a response just as rapidshare's api doc says.

The rapidshare api doc (see "sub=download") says call the server hostname with the download authentication string but I couldn't figure out what form the url should take.

Any suggestions?, I tried

$download_url = "http://$the-hostname/$the-dlauth-string/files/$fileid/$filename"

and a couple other variations of the above, nothing worked.

I use curl to download the file, like the following;

    $cr = curl_init();
    $fp = fopen ("d:/downloaded_files/file1.rar", "w");    
    // set curl options 
    $curl_options = array( 
         CURLOPT_URL => $download_url
        ,CURLOPT_FILE => $fp
        ,CURLOPT_HEADER => false
        ,CURLOPT_CONNECTTIMEOUT => 0 
        ,CURLOPT_FOLLOWLOCATION => true
    );
    curl_setopt_array($cr, $curl_options);

    curl_exec($cr);
    curl_close($cr);
    fclose($fp);

The above curl code doesn't seem to work, nothing gets downloaded. Probably its the download url that is incorrect.

Also tried this format for the download url:

"http://rs$serverid$shorthost.rapidshare.com/files/$fileid/$filename"

With this curl writes a file entry but that is all it does(writes a 0/1 kb file).

Here is the code that I use to get the serverid, shorthost, among a few other values from rapidshare.

function rs_checkfile($params)
{
    $url = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&files=".$params['fileids']."&filenames=".$params['filenames'];

    // the response from rapishare would a string something like:
    // 440817141,AutoRun__live-down.com_Champ.rar,47768,20,1,l3,0 

    $reply = @file_get_contents($url);
    if(!$reply)
    {
        return false;
    }

    $result_arr = array();
    $result_keys = array(0=> 'file_id', 1=>'file_name', 2=>'file_size', 3=>'server_id', 4=>'file_status', 5=>'short_host'
    , 6=>'md5');

    foreach( explode(',', $reply) as $index => $value )
    {
        $result_arr[ $result_keys[$index] ] = $value;        
    }

    return $result_arr;
}

rs_checkfile(...) takes comma seperated fileids and filenames(no commas if calling for a single file)

Thanks in advance for any suggestions.

freedayum
  • 301
  • 2
  • 7
  • 17

1 Answers1

0

You start by requesting ?sub=download&fileid=X&filename=Y, and it returns $hostname,$dlauth,$countdown,$md5hex.. since you're a free user you have to delay for $countdown seconds, and then call ?sub=download&fileid=X&filename=Y&dlauth=Z to perform the download.

There's a working implementation in python here that would probably answer any of your other questions.

mappu
  • 329
  • 2
  • 16