2 ###APPNAME: rayfile_download
4 ###APPDATE: 2009-01-27 04:52:02
6 ###APPDESC: rayfile_download
8 ###APPEXAMPLE: rayfile_download
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
15 use lib
$ENV{XR_PERL_MODULE_DIR
};
17 use MyPlace
::Script
::Usage qw
/help_required help_even_empty/;
18 exit 0 if(help_required
($0,@ARGV));
19 #exit 0 if(help_even_empty($0,@ARGV));
32 die("Error:no urls specified\n") unless(@urls);
34 my $ua = LWP
::UserAgent
->new;
35 my $cookie = HTTP
::Cookies
->new(file
=> "$ENV{'HOME'}/.lwp_cookies.dat", autosave
=> 1);
36 $ua->cookie_jar($cookie);
37 $ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3 Firefox/3.0.1");
38 foreach my $url (@urls) {
39 $url = "http://$url" unless($url =~ /^http:/i);
40 my $req = HTTP
::Request
->new(GET
=> $url);
41 my $res = $ua->request($req);
42 if ($res->is_success) {
43 my @content = split(/\n/,$res->content);
44 my ($fileurl,$filename,$setcookie,$id,$digest);
46 $id=$1 if(/var virtual_file_id = \"([^"]+)\";/);
47 $filename=$1 if(/virtual_file = \"([^"]+)\";/);
48 $fileurl=$1 if(/downloads_url = \[\'([^']+)\'\];/);
49 $digest =$1 if(/var digest = \'([^']+)\';/);
51 if($digest and $fileurl) {
52 $ua->cookie_jar->set_cookie(0,'ROXCDNKEY',$digest,"/zh-cn/download/$id/",".rayfile.com",undef,1,0,86400,0);
53 $filename ||= $fileurl;
54 $filename =~ s/^.*\///g
;
55 print STDERR
"$fileurl\n";
56 print STDERR
"Downloading $filename ...";
58 print STDERR
"\tFile exists\n";
62 system("curl","-#","-b","ROXCDNKEY=$digest","-o",$filename,"--url",$fileurl);
67 print STDERR
$res->status_line, "\n";