diff -pruN slimrat-0.9.2.orig/slimrat slimrat-0.9.2/slimrat --- slimrat-0.9.2/slimrat 2009-01-13 21:21:00.000000000 +0700 +++ slimrat-patched/slimrat 2009-01-13 21:23:05.000000000 +0700 @@ -21,7 +21,7 @@ use Plugin; use warnings; -my ($list, $link, @links, $check, @failedlinks, @oklinks, $download_to); +my ($list, $link, @links, $check, @failedlinks, @oklinks, $download_to, $wget_opts); sub usage { print " SlimRat @@ -36,23 +36,24 @@ -l | --list filename load links from file (one per line) -c | --check check links instead of downloading them -t | --to directory destination directory (where to download) - + -w | --wget wget options, enclosed in quotes + "; exit; } &usage if(scalar @ARGV==0); GetOptions ( - "help!" => \&usage, - "check!" => \$check, - "list=s" => \$list, - "to=s" => \$download_to, - ); - + "help!" => \&usage, + "check!" => \$check, + "list=s" => \$list, + "to=s" => \$download_to, + "wget=s" => \$wget_opts, + ); if($list){ # load links from file - if(open (LIST, $list)){ - m/^\s*(\S+)\s*/ and push @links, $1 while(<LIST>); - close LIST; - } else {warn "Can't open '$list'\n";} + if(open (LIST, $list)){ + m/^\s*(\S+)\s*/ and push @links, $1 while(<LIST>); + close LIST; + } else {warn "Can't open '$list'\n";} } push @links, $link while($link = shift); # read links from command line @@ -63,45 +64,51 @@ if($check){ check($_) foreach @links;} else { - download($_) foreach @links; - if(scalar @oklinks){ - print GREEN, "\nDOWNLOADED:\n", RESET; - print $_,"\n" foreach @oklinks; - print "to '",YELLOW, $download_to, RESET, "'\n" if ($download_to); - } - if(scalar @failedlinks){ - print RED, "\nFAILED:\n", RESET; - print $_,"\n" foreach @failedlinks; - } + download($_) foreach @links; + if(scalar @oklinks){ + print GREEN, "\nDOWNLOADED:\n", RESET; + print $_,"\n" foreach @oklinks; + print "to '",YELLOW, $download_to, RESET, "'\n" if ($download_to); + } + if(scalar @failedlinks){ + print RED, "\nFAILED:\n", RESET; + print $_,"\n" foreach @failedlinks; + } } sub check{ - $link = shift; - my $pluginname = Plugin::get_name($link); - my $check = eval $pluginname."::check('$link')"; - $check ||=0; - if($check>0) {print GREEN, "[OK]", RESET;} - elsif($check<0) {print RED, "[DEAD]", RESET; $return++} - else {print "[?]";} - print "\t", YELLOW, $link, RESET, " (", $pluginname, ")\n"; + $link = shift; + my $pluginname = Plugin::get_name($link); + my $check = eval $pluginname."::check('$link')"; + $check ||=0; + if($check>0) {print GREEN, "[OK]", RESET;} + elsif($check<0) {print RED, "[DEAD]", RESET; $return++} + else {print "[?]";} + print "\t", YELLOW, $link, RESET, " (", $pluginname, ")\n"; } + sub download{ - $link = shift; - my $pluginname = Plugin::get_name($link); - print "\nDownloading '", YELLOW, $link, RESET, "' using '", YELLOW, $pluginname, RESET, "' plugin.\n"; - if(my $fileurl = eval $pluginname."::download('$link')"){ # rename download to get_link???? - if(!system("wget ".($download_to?"-P '$download_to' ":"")."'$fileurl'")){ #success - print GREEN "OK", RESET, "\n\n"; - push @oklinks, $link; - } else { # wget failed - print RED "Download failed\n\n"; - push @failedlinks, $link; - } - } else { # get fileurl failed - print RED "Plugin failed\n\n"; - push @failedlinks, $link; - } + $link = shift; + my $pluginname = Plugin::get_name($link); + print "\nDownloading '", YELLOW, $link, RESET, "' using '", YELLOW, $pluginname, RESET, "' plugin.\n"; + if(my $fileurl = eval $pluginname."::download('$link')"){ # rename download to get_link???? + my $wget = 'wget ' . + ($wget_opts ? qq($wget_opts ) : '') . + ($download_to? "-P '$download_to' " : "") . + "'$fileurl'"; + + if(!system $wget){ #success + print GREEN "OK", RESET, "\n\n"; + push @oklinks, $link; + } else { # wget failed + print RED "Download failed\n\n"; + push @failedlinks, $link; + } + } else { # get fileurl failed + print RED "Plugin failed\n\n"; + push @failedlinks, $link; + } }