updated git and svn scripts
[xrzperl.git] / rayfile_download
blob2600f4179e60669367c88f24ffb72eb5e5b83e88
1 #!/usr/bin/perl -w
2 ###APPNAME: rayfile_download
3 ###APPAUTHOR: duel
4 ###APPDATE: 2009-01-27 04:52:02
5 ###APPVER: 0.1
6 ###APPDESC: rayfile_download
7 ###APPUSAGE: (urls...)
8 ###APPEXAMPLE: rayfile_download
9 ###APPOPTION:
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
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));
21 use LWP::UserAgent;
22 use HTTP::Cookies;
24 my @urls = @ARGV;
25 unless(@urls) {
26 while(<STDIN>) {
27 chomp;
28 push @urls,$_;
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);
45 foreach(@content) {
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 ...";
57 if(-f $filename) {
58 print STDERR "\tFile exists\n";
60 else {
61 print STDERR "\n";
62 system("curl","-#","-b","ROXCDNKEY=$digest","-o",$filename,"--url",$fileurl);
66 else {
67 print STDERR $res->status_line, "\n";