SVN: toys/fun/rsget.pl

sparky sparky at pld-linux.org
Sat Jan 10 14:56:44 CET 2009


Author: sparky
Date: Sat Jan 10 14:56:44 2009
New Revision: 10061

Modified:
   toys/fun/rsget.pl
Log:
- use list of available backends instead of checking one by one


Modified: toys/fun/rsget.pl
==============================================================================
--- toys/fun/rsget.pl	(original)
+++ toys/fun/rsget.pl	Sat Jan 10 14:56:44 2009
@@ -16,6 +16,8 @@
 my %gotlist;
 $SIG{CHLD} = "IGNORE";
 
+my %getters;
+
 package Line; # {{{
 use Term::Size;
 
@@ -565,6 +567,11 @@
 	$self->download( post => 'mirror=on' );
 }
 
+$getters{RS} = {
+	uri => qr{rapidshare\.com/.*?},
+	add => sub { Get::RapidShare->new( @_ ) },
+};
+
 # }}}
 package Get::NetLoad; # {{{
 
@@ -714,6 +721,11 @@
 	unlink $self->{cookies};
 }
 
+$getters{NL} = {
+	uri => qr{netload\.in/datei.*?},
+	add => sub { Get::NetLoad->new( @_ ) },
+};
+
 # }}}
 package Get::NetLoad::Captcha; # {{{
 
@@ -934,6 +946,11 @@
 	unlink $self->{cookies};
 }
 
+$getters{OS} = {
+	uri => qr{odsiebie\.com/(?:pokaz|pobierz)/.*?},
+	add => sub { Get::OdSiebie->new( @_ ) },
+};
+
 # }}}
 package Get::MegaUpload; # {{{
 
@@ -974,6 +991,9 @@
 	if ( $body =~ /The file you are trying to access is temporarily unavailable/ ) {
 		return $self->error( "file temporarily unavailable" );
 	}
+	if ( $body =~ /Unfortunately, the link you have clicked is not available./ ) {
+		return $self->error( "file not found" );
+	}
 	my %search = (
 		captcha_img => qr#<img src="(/capgen\.php\?[0-9a-f]+)"#,
 		action => qr#<form method="POST" action="(.*?)"#,
@@ -1060,6 +1080,11 @@
 	unlink $self->{cookies};
 }
 
+$getters{MU} = {
+	uri => qr{(?:www\.)?megaupload\.com/\?d=.*?},
+	add => sub { Get::MegaUpload->new( @_ ) },
+};
+
 # }}}
 package Get::MegaUpload::Captcha; # {{{
 
@@ -1151,6 +1176,9 @@
 	$self->print("starting......");
 	$self->{referer} = $url;
 
+	if ( $url =~ m#/\?view=# ) {
+		return $self->error( ($url =~ /fileremoved/) ? "file not found" : "unknown error" );
+	}
 	if ( $body =~ /Or wait (\d+) minutes/ ) {
 		return $self->wait( $1 * 60, \&stage1, "free limit reached, waiting" );
 	}
@@ -1168,6 +1196,11 @@
 	$self->download( post => "download_submit=Download");
 }
 
+$getters{UT} = {
+	uri => qr{uploaded\.to/file/.*?},
+	add => sub { Get::UploadedTo->new( @_ ) },
+};
+
 # }}}
 package main; # {{{
 
@@ -1189,29 +1222,21 @@
 			push @newlist, $line;
 			next;
 		}
-		my $url = undef;
-		if ( $line =~ m{^\s*(http://rapidshare\.com/.*?)\s*$} ) {
-			$url = $1;
-			new Get::RapidShare( $1 );
-		} elsif ( $line =~ m{^\s*(http://netload\.in/datei.*?)\s*$} ) {
-			$url = $1;
-			new Get::NetLoad( $1 );
-		} elsif ( $line =~ m{^\s*(http://odsiebie\.com/(pokaz|pobierz)/.*?)\s*$} ) {
-			$url = $1;
-			new Get::OdSiebie( $1 );
-		} elsif ( $line =~ m{^\s*(http://(www\.)?megaupload\.com/\?d=.*?)\s*$} ) {
-			$url = $1;
-			new Get::MegaUpload( $1 );
-		} elsif ( $line =~ m{^\s*(http://uploaded\.to/file/.*?)\s*$} ) {
-			$url = $1;
-			new Get::UploadedTo( $1 );
+		my $uri = undef;
+		my $getter = undef;
+		if ( $line =~ m{^\s*(http://)?(.*?)\s*$} ) {
+			my $proto = $1 || "http://";
+			$uri = $2;
+			($getter) = grep { $uri =~ m/^$getters{$_}->{uri}$/ } keys %getters;
+			$uri = $proto.$uri;
 		}
 
-		if ( $url ) {
-			if ( exists $gotlist{$url} ) {
-				push @newlist, "# " . $gotlist{$url} . ":\n# " . $line;
+		if ( $getter ) {
+			if ( exists $gotlist{$uri} ) {
+				push @newlist, "# " . $gotlist{$uri} . ":\n# " . $line;
 			} else {
-				push @newlist, $url . "\n";
+				push @newlist, $uri . "\n";
+				&{$getters{ $getter }->{add}}( $uri );
 			}
 			next;
 		}
@@ -1263,7 +1288,7 @@
 sub bignum($)
 {
 	local $_ = shift;
-	s/(...?)(?=(...)+$)/$1_/g;
+	s/(..?.?)(?=(...)+$)/$1_/g;
 	return $_;
 }
 


More information about the pld-cvs-commit mailing list