SVN: toys/fun/rsget.pl
sparky
sparky at pld-linux.org
Tue Jan 6 01:25:23 CET 2009
Author: sparky
Date: Tue Jan 6 01:25:23 2009
New Revision: 10051
Modified:
toys/fun/rsget.pl
Log:
- some improvements
Modified: toys/fun/rsget.pl
==============================================================================
--- toys/fun/rsget.pl (original)
+++ toys/fun/rsget.pl Tue Jan 6 01:25:23 2009
@@ -55,9 +55,9 @@
} elsif ( $steps > 0 ) {
$move = "\033[" . $steps . "B";
}
- if ( length $text > $columns ) {
- $text = (substr $text, 0, $columns - 4) . '...';
- }
+ my $tl = length $text;
+ substr $text, 15, $tl - $columns + 18, '...'
+ if $tl > $columns;
print $move . "\r\033[K" . $text;
}
@@ -97,11 +97,6 @@
{
my $fn = $self->{file_name};
- if ( length $fn >= $columns - 30 ) {
- my $l = int ( ( $columns - 34 ) / 2 );
- $fn =~ s/^(.{$l}).*(.{$l})$/$1...$2/;
- }
-
my $net = $self->{obj}->{net};
$self->{obj}->{netname} = "[$net] $fn: ";
}
@@ -221,8 +216,8 @@
if ( $obj->{curl_next} ) {
my $func = $obj->{curl_next};
+ my $body = $ecurl->{file} ? "DONE" : $ecurl->{body};
my $eurl = $curl->getinfo( CURLINFO_EFFECTIVE_URL );
- my $body = $ecurl->{body};
&$func( $obj, $body, $eurl );
}
@@ -399,9 +394,10 @@
sub finish
{
my $self = shift;
+ my $reason = shift;
my $url = $self->{url};
- $gotlist{ $url } = 1;
+ $gotlist{ $url } = $reason;
my $net = $self->{net};
my $id = $self->{id};
@@ -425,6 +421,7 @@
my $msg = shift;
$self->print( $msg );
+ $self->finish( $msg );
}
# }}}
@@ -512,18 +509,16 @@
@ISA = qw(Get);
}
+my $nlcookie = 0;
sub new
{
my $proto = shift;
my $class = ref $proto || $proto;
my $url = shift;
- my $cookie;
- my $i = 0;
- do {
- $i++;
- $cookie = ".nl.$i.txt";
- } while ( -r $cookie );
+ ++$nlcookie;
+ my $cookie = ".nl.$nlcookie.txt";
+ unlink $cookie if -e $cookie;
Get::makenew( "NL", $class, $url, cookie => $cookie );
@@ -543,6 +538,9 @@
$self->print("starting......");
(my $dir = $url) =~ s#^(.*)/.*?$#$1/#; ## vim
+ if ( $body =~ /Sorry, we don't host the requested file/ ) {
+ return $self->error( "file not found" );
+ }
my ($link) = ($body =~ /"(.*?captcha=1)"/);
unless ( defined $link ) {
if ($body =~ /MAINTENANCE/ ) {
@@ -568,7 +566,7 @@
my %search = (
action => qr#<form method="post" action="(.*?)">#,
captcha_img => qr#"(share/includes/captcha\.php\?t=[0-9]+)"#,
- file_id => qr#input name="file_id" .*value="([0-9a-f]+)"#,
+ file_id => qr#input name="file_id" .*value="(.*?)"#,
s3wait => qr#please wait .*countdown\(([0-9]+),#,
);
@@ -577,10 +575,9 @@
if ( $body =~ m/$search/ ) {
$self->{$name} = $1;
} else {
- print "\rmissing: $name \n";
+ return $self->stage1()
}
}
- # return $self->stage1();
$self->{s3dir} = $dir;
$self->{s3url} = $url;
@@ -624,7 +621,9 @@
}
if ( $body =~ /You could download your next file in.*countdown\(([0-9]+)/ ) {
- return $self->wait( $1 / 100, \&stage1, "free limit reached, waiting" );
+ my $wait = $1 / 100;
+ $wait = 1200 if $wait > 1200;
+ return $self->wait( $wait, \&stage1, "free limit reached, waiting" );
}
$body =~ /please wait .*countdown\(([0-9]+),/;
my $wait = $1 / 100 + 1;
@@ -724,7 +723,7 @@
open2( *READ, *WRITE, "pngtopnm | gocr -f ASCII -a 5 -m 56 -C 0123456789 - 2>/dev/null" );
print WRITE $nimg->png;
close WRITE;
- my $num = <READ>;
+ my $num = <READ> || "";
close READ;
my ($gocr) = ($num =~ /^([0-9])/);
More information about the pld-cvs-commit
mailing list