Search code examples
phpapirapidshare

Using Rapidshare API to check if a file is downloadable


I'm new with this API thing, so I don't know how to use it very well. I want to make an application on C or PHP or AppleScript to check if a file is downloadable. I just need to know how to send the request properly.

I read the API docs but I still don't know how to get the return values.

Can anyone help me?

Happy holidays everyone =) since now thanks.


Solution

  • Use something like:

    http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&type=prem&login=MY_USERNAME&
    password=MY_PASSWORD&files=5044438&filenames=test1.rar
    

    This call makes use of the checkfiles_v1 subroutine which according to the API documentation:

    subroutine=checkfiles_v1
    Description:    Gets status details about a list of given files. (files parameter limited to 3000 bytes. filenames parameter limited to 30000 bytes.)
    Parameters:  files=comma separated list of file ids
                 filenames=comma separated list of the respective filename. Example: files=50444381,50444382 filenames=test1.rar,test2.rar
                    incmd5=if set to 1, field 7 is the hex-md5 of the file. This will double your points! If not given, all md5 values will be 0
    Reply fields:
            1:File ID
            2:Filename
            3:Size (in bytes. If size is 0, this file does not exist.)
            4:Server ID
            5:Status integer, which can have the following numeric values:
                0=File not found
                1=File OK (Anonymous downloading)
                2=File OK (TrafficShare direct download without any logging)
                3=Server down
                4=File marked as illegal
                5=Anonymous file locked, because it has more than 10 downloads already
                6=File OK (TrafficShare direct download with enabled logging. Read our privacy policy to see what is logged.)
            6:Short host (Use the short host to get the best download mirror: http://rs$serverid$shorthost.rapidshare.com/files/$fileid/$filename)
            7:md5 (See parameter incmd5 in parameter description above.)
    Reply format:   integer,string,integer,integer,integer,string,string
    

    You can make use of the Status from the reply and if its value is 1 it means the file is downloadable.

    Here goes the program in PHP:

    Click here to see the server reply

    <?php
    
    // This PHP script check if a file is publicly downloadable
    // I've taken a sample file: 
    // http://rapidshare.com/files/293360186/1597494240.pdf
    // which at the time of wring is available + is downloadable.
    
    // File ID
    $file_id = '293360186';
    
    // Filename
    $file_name = '1597494240.pdf';
    
    //construct the URL.
    $URL = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&files=$file_id&filenames=$file_name";
    
    // Now get the response for this URL.
    /* It looks something like:
       293360186,1597494240.pdf,6861070,59,1,gc,0 
    
       So we are just interested in field 5(Status), check if its 1(file downloadable) or 0
    */
    
    $reply = file_get_contents($URL);
    if(!$reply)
    {
        die("Failed for $URL<br>");
    }
    
    $arr = explode(',',$reply);
    
    if($arr[4] == 1)
        print "File $file_name is publicly downloadable<br>";
    else
        print "File $file_name is not publicly downloadable<br>";
    
    ?>
    

    Hope this helps.