2 ###APPNAME: namipan_download
4 ###APPDATE: 2009-01-27 04:52:02
6 ###APPDESC: namipan_download
8 ###APPEXAMPLE: namipan_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));
33 die("Error:no urls specified\n") unless(@urls);
35 my $ua = LWP
::UserAgent
->new;
36 my $cookie = HTTP
::Cookies
->new(file
=> "$ENV{'HOME'}/.lwp_cookies.dat", autosave
=> 1);
37 $ua->cookie_jar($cookie);
38 $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");
39 foreach my $url (@urls) {
40 $url = "http://$url" unless($url =~ /^http:/i);
41 my $req = HTTP
::Request
->new(GET
=> $url);
42 my $res = $ua->request($req);
43 if ($res->is_success) {
44 print STDERR
"$url\n";
45 my @content = split(/\n/,$res->content);
46 my ($fileurl,$filename);
48 $filename=$1 if(/\<H2 class=above\>([^\<\>]+)<\/H2\
>/);
49 if(/(namipan\.com\/downfile
)\
/([^\/]+)\
/([^\s'"\/]+)['"]/) {
50 $url = "http://www.$1/$2/$3";
51 $fileurl = "http://img.$1/$3/$2";
55 next unless($fileurl);
56 $filename ||= $fileurl;
57 $filename =~ s/^.*\///g;
58 $filename = uri_unescape($filename);
59 print STDERR "$fileurl\n";
60 print STDERR "Downloading $filename ...";
62 print STDERR "\tFile exists\n";
66 system("curl",'-b
',$cookie,"-#","-L","-o",$filename,"--url",$fileurl,"--refer",$url);
70 print STDERR $res->status_line, "\n";