使用Rapidshare API检查文件是否可下载

时间:2009-12-27 02:11:36

标签: php api rapidshare

我是这个API的新手,所以我不知道如何使用它。我想在C或PHP或AppleScript上创建一个应用程序来检查文件是否可下载。我只需要知道如何正确发送请求。

我阅读了API文档,但我仍然不知道如何获取返回值。

任何人都可以帮助我吗?

节日快乐大家=) 从现在开始谢谢。

1 个答案:

答案 0 :(得分:2)

使用类似:

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

此调用使用checkfiles_v1子例程,该子例程根据API文档:

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

您可以使用回复中的状态,如果其值为1,则表示该文件可下载。

这是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>";

?>

希望这有帮助。