SVN: toys/fun/rsget.pl

sparky sparky at pld-linux.org
Sun Dec 28 15:19:49 CET 2008


Author: sparky
Date: Sun Dec 28 15:19:49 2008
New Revision: 10042

Modified:
   toys/fun/rsget.pl
Log:
- added download ETA, support "file not found"


Modified: toys/fun/rsget.pl
==============================================================================
--- toys/fun/rsget.pl	(original)
+++ toys/fun/rsget.pl	Sun Dec 28 15:19:49 2008
@@ -33,16 +33,20 @@
 	print $file $chunk;
 
 	my $size = "$self->{got} / $self->{total}";
+	my $eta = "";
+	my $time = time;
 	if ( int $self->{total} > 0 ) {
-		$size .= sprintf " [%.2f%%]", $self->{got} * 100 / $self->{total}
+		$size .= sprintf " [%.2f%%]", $self->{got} * 100 / $self->{total};
+		if ( $time > $self->{start} ) {
+			my $tleft = ($self->{total} - $self->{got}) / $self->{got} * ($time - $self->{start});
+			$eta = sprintf "%2d:%.2d", $tleft / 60, $tleft % 60;
+		}
 	}
 	my $speed = "???";
-	my $time = time;
-	if ( $time > $self->{start} ) {
-		$speed = sprintf "%.2f", $self->{got} / ($time - $self->{start}) / 1024;
-	}
+	$speed = sprintf "%.2f", $self->{got} / ($time - $self->{start}) / 1024
+		if $time > $self->{start};
 
-	print "\r$self->{fn}: $size; ${speed}KB/s   ";
+	print "\r$self->{fn}: $size; ${speed}KB/s $eta  ";
 
 	return $len;
 }
@@ -110,7 +114,7 @@
 rsget_restart:
 	$try -= 1;
 	if ( $try <= 0 ) {
-		return undef;
+		return "problems";
 	}
 
 	print "\r[RS] $fn: (re)starting...         ";
@@ -118,6 +122,10 @@
 	unless ( $body ) {
 		goto rsget_restart;
 	}
+	if ( $body =~ /The file could not be found\.  Please check the download link\./m ) {
+		print "\r[RS] $fn: file not found    \n";
+		return "file not found";
+	}
 	$body =~ /form id="ff" action="(.*?)"/m;
 	my $link = $1;
 
@@ -151,7 +159,7 @@
 	curl( $link, post => 'mirror=on', file => $fn, net => '[RS] ' );
 	print "DONE!\n";
 
-	return $fn;
+	return "DONE";
 }
 
 my $get_list = shift @ARGV || 'get.list';
@@ -173,7 +181,8 @@
 		if ( $line =~ m/^\s*(http:\/\/rapidshare\.com\/.*?)\s*$/ ) {
 			$get_url = $1;
 			if ( exists $gotlist{$get_url} ) {
-				push @newlist, "# " . $line;
+				chomp $line;
+				push @newlist, "# " . $line . " " . $gotlist{$get_url} . "\n";
 			} else {
 				$get_func = \&rsget;
 				push @newlist, $get_url . "\n";
@@ -193,8 +202,8 @@
 	}
 
 	if ( $get_url and $get_func ) {
-		if ( my $file = &$get_func( $get_url ) ) {
-			$gotlist{$get_url} = $file;
+		if ( my $reason = &$get_func( $get_url ) ) {
+			$gotlist{$get_url} = $reason;
 		}
 	} else {
 		print "\rwaiting for urls";


More information about the pld-cvs-commit mailing list