SVN: toys/fun/rsget.pl

sparky sparky at pld-linux.org
Thu Jan 8 00:02:17 CET 2009


Author: sparky
Date: Thu Jan  8 00:02:15 2009
New Revision: 10057

Modified:
   toys/fun/rsget.pl
Log:
- use URI; simplified


Modified: toys/fun/rsget.pl
==============================================================================
--- toys/fun/rsget.pl	(original)
+++ toys/fun/rsget.pl	Thu Jan  8 00:02:15 2009
@@ -342,6 +342,8 @@
 # }}}
 package Get; # {{{
 
+use URI;
+
 my %running;
 sub makenew
 {
@@ -369,7 +371,7 @@
 
 	my $line = new Line;
 
-	( my $fn = $url ) =~ s#/+$##; ## vim
+	( my $fn = $url ) =~ s{/+$}{};
 	$fn =~ s#^.*/##;
 
 	my $self = {
@@ -402,8 +404,21 @@
 	my $url = shift;
 	my $next_stage = shift;
 
+	$url = URI->new( $url )->abs( $self->{referer} )->as_string
+		if $self->{referer};
+
 	$self->{curl_next} = $next_stage;
-	Curl::start( $url, $self, @_ );
+	Curl::start( $url, $self,
+		($self->{referer} ? ( referer => $self->{referer} ) : ()),
+		($self->{cookies} ? ( cookies => $self->{cookies} ) : ()),
+		@_ );
+}
+
+sub download
+{
+	my $self = shift;
+	$self->print("starting download");
+	$self->curl( $self->{file_url}, \&finish, save => 1, @_ );
 }
 
 sub wait
@@ -435,15 +450,6 @@
 	$checklist = 1;
 }
 
-sub download
-{
-	my $self = shift;
-
-	$self->{curl_next} = \&finish;
-	$self->print("starting download");
-	Curl::start( $self->{file_url}, $self, save => 1, @_ );
-}
-
 sub error
 {
 	my $self = shift;
@@ -472,6 +478,7 @@
 sub stage1
 {
 	my $self = shift;
+	delete $self->{referer};
 
 	$self->print("starting...");
 	$self->curl( $self->{url}, \&stage2 );
@@ -481,6 +488,7 @@
 {
 	my ($self, $body, $url) = @_;
 	$self->print("starting......");
+	$self->{referer} = $url;
 
 	my $link;
 	if ( $body =~ /The file could not be found\.  Please check the download link\./m ) {
@@ -501,14 +509,14 @@
 		}
 	}
 
-	$self->curl( $link, \&stage3, post => 'dl.start=Free', referer => $url );
-
+	$self->curl( $link, \&stage3, post => 'dl.start=Free' );
 }
 
 sub stage3
 {
 	my ($self, $body, $url) = @_;
 	$self->print("starting.........");
+	$self->{referer} = $url;
 
 	if ( $body =~ /Please wait until the download is completed/m ) {
 		return $self->error( "multi-download not allowed" );
@@ -519,7 +527,6 @@
 		return $self->wait( $m * 60 + 10, \&stage1, "free limit reached, waiting" );
 	}
 	unless ( $body =~ /var c=([0-9]+);/m ) {
-		print "var c= missing\n $body\n";
 		return $self->stage1();
 	}
 	my $wait = $1;
@@ -558,7 +565,7 @@
 	my $cookie = ".nl.$nlcookie.txt";
 	unlink $cookie if -e $cookie;
 
-	Get::makenew( "NL", $class, $url, cookie => $cookie );
+	Get::makenew( "NL", $class, $url, cookies => $cookie );
 }
 
 sub stage1
@@ -566,14 +573,15 @@
 	my $self = shift;
 
 	$self->print("starting...");
-	$self->curl( $self->{url}, \&stage2, cookies => $self->{cookie} );
+	delete $self->{referer};
+	$self->curl( $self->{url}, \&stage2 );
 }
 
 sub stage2
 {
 	my ($self, $body, $url) = @_;
 	$self->print("starting......");
-	(my $dir = $url) =~ s#^(.*)/.*?$#$1/#; ## vim
+	$self->{referer} = $url;
 
 	if ( $body =~ /Sorry, we don't host the requested file/ ) {
 		return $self->error( "file not found" );
@@ -587,14 +595,14 @@
 	}
 	$link =~ s/&/&/g;
 
-	$self->curl( $dir . $link, \&stage3, cookies => $self->{cookie}, referer => $url );
+	$self->curl( $link, \&stage3 );
 }
 
 sub stage3
 {
 	my ($self, $body, $url) = @_;
 	$self->print("starting.........");
-	(my $dir = $url) =~ s#^(.*)/.*?$#$1/#; ## vim
+	$self->{referer} = $url;
 
 	if ( $body =~ /"(.*?captcha=1)"/) {
 		return $self->stage2( $body, $url );
@@ -616,9 +624,7 @@
 		}
 	}
 
-	$self->{s3dir} = $dir;
-	$self->{s3url} = $url;
-	$self->curl( $dir . $self->{captcha_img}, \&stage4, cookies => $self->{cookie}, referer => $url );
+	$self->curl( $self->{captcha_img}, \&stage4 );
 }
 
 sub stage4
@@ -629,7 +635,7 @@
 	my $captcha = Get::NetLoad::Captcha::resolve( $body );
 
 	unless ( defined $captcha ) {
-		return $self->curl( $self->{s3dir} . $self->{captcha_img}, \&stage4, cookies => $self->{cookie}, referer => $url );
+		return $self->curl( $self->{captcha_img}, \&stage4 );
 	}
 	$self->{captcha} = $captcha;
 
@@ -642,16 +648,14 @@
 	$self->print("starting............");
 
 	my $post = "file_id=$self->{file_id}&captcha_check=$self->{captcha}&start=";
-	$self->curl(
-		$self->{s3dir}.$self->{action}, \&stage6,
-		cookies => $self->{cookie}, post => $post, referer => $self->{s3url}
-	);
+	$self->curl( $self->{action}, \&stage6, post => $post );
 }
 
 sub stage6
 {
 	my ($self, $body, $url) = @_;
 	$self->print("starting...............");
+	$self->{referer} = $url;
 
 	if ( $body =~ /You may forgot the security code or it might be wrong/ ) {
 		return $self->stage1();
@@ -667,15 +671,20 @@
 			return $self->error( "unknown problem" );
 		} else {
 			$self->{s6problems} = 1;
-			return $self->wait( 5 * 60, \&stage1, "unknown problems, retrying in" );
+			return $self->wait( 5 * 60, \&stage1, "unknown problem, retrying in" );
 		}
 	}
-	$self->{s6problems} = 0;
 	my $wait = $1 / 100 + 1;
-
-	my ($full_link) = ($body =~ m#<a class="Orange_Link" href="(.*?)"#);
-	$self->{file_url} = $full_link;
-	$self->{file_referer} = $url;
+	unless ( $body =~ m#<a class="Orange_Link" href="(.*?)"#) {
+		if ( $self->{s6problems} ) {
+			return $self->error( "unknown problem" );
+		} else {
+			$self->{s6problems} = 1;
+			return $self->wait( 5 * 60, \&stage1, "unknown problem, retrying in" );
+		}
+	}
+	$self->{file_url} = $1;
+	$self->{s6problems} = 0;
 
 	$self->wait( $wait, \&stage7, "starting in" );
 }
@@ -685,13 +694,13 @@
 	my $self = shift;
 	$self->print("downloading");
 
-	$self->download( referer => $self->{file_referer} );
+	$self->download();
 }
 
 sub DESTROY
 {
 	my $self = shift;
-	unlink $self->{cookie};
+	unlink $self->{cookies};
 }
 
 # }}}
@@ -877,37 +886,37 @@
 	my $cookie = ".os.$oscookie.txt";
 	unlink $cookie if -e $cookie;
 
-	Get::makenew( "OS", $class, $url, slots => 16, cookie => $cookie );
+	Get::makenew( "OS", $class, $url, slots => 16, cookies => $cookie );
 }
 
 sub stage1
 {
 	my $self = shift;
 
-	my $url = $self->{url};
-	$url =~ s#/pokaz/#/pobierz/#;
-
 	$self->print("starting...");
-	$self->curl( $url, \&stage2, cookies => $self->{cookie} );
+	delete $self->{referer};
+
+	( my $url = $self->{url} ) =~ s#/pokaz/#/pobierz/#;
+
+	$self->curl( $url, \&stage2 );
 }
 
 sub stage2
 {
 	my ($self, $body, $url) = @_;
+	$self->print("downloading");
+	$self->{referer} = $url;
 
-	my $furl = $url;
-	$furl =~ s#/pobierz/#/download/#;
+	( my $furl = $url ) =~ s#/pobierz/#/download/#;
 	$self->{file_url} = $furl;
 
-	$self->print("downloading");
-
-	$self->download( referer => $url, cookies => $self->{cookie} );
+	$self->download();
 }
 
 sub DESTROY
 {
 	my $self = shift;
-	unlink $self->{cookie};
+	unlink $self->{cookies};
 }
 
 # }}}
@@ -929,7 +938,7 @@
 	my $cookie = ".mu.$nlcookie.txt";
 	unlink $cookie if -e $cookie;
 
-	Get::makenew( "MU", $class, $url, cookie => $cookie );
+	Get::makenew( "MU", $class, $url, cookies => $cookie );
 }
 
 sub stage1
@@ -937,13 +946,15 @@
 	my $self = shift;
 
 	$self->print("starting...");
-	$self->curl( $self->{url}, \&stage2, cookies => $self->{cookie} );
+	delete $self->{referer};
+	$self->curl( $self->{url}, \&stage2 );
 }
 
 sub stage2
 {
 	my ($self, $body, $url) = @_;
 	$self->print("starting......");
+	$self->{referer} = $url;
 
 	my %search = (
 		captcha_img => qr#<img src="(/capgen\.php\?[0-9a-f]+)"#,
@@ -962,16 +973,12 @@
 		}
 	}
 
-	(my $domain = $url) =~ s#^(.*?://.*?)/.*$#$1#; ## vim
-	$self->{s2url} = $url;
-
-	$self->curl( $domain . $self->{captcha_img}, \&stage3, cookies => $self->{cookie}, referer => $url );
+	$self->curl( $self->{captcha_img}, \&stage3 );
 }
 
 sub stage3
 {
 	my ($self, $body, $url) = @_;
-
 	$self->print("reading captcha");
 
 	my $captcha = Get::MegaUpload::Captcha::resolve( $body );
@@ -982,12 +989,14 @@
 
 	my $post = "d=$self->{s2id}&imagecode=$self->{s2icode}&megavar=$self->{s2mevagar}&imagestring=$captcha";
 
-	$self->curl( $self->{action}, \&stage4, post => $post, cookies => $self->{cookie}, referer => $url );
+	$self->curl( $self->{action}, \&stage4, post => $post );
 }
 
 sub stage4
 {
 	my ($self, $body, $url) = @_;
+	$self->print("starting.........");
+	$self->{referer} = $url;
 
 	my %search = (
 		s4wait => qr#x[0-9]+=([0-9]+);#,
@@ -1015,7 +1024,6 @@
 	$furl =~ s/' \+ . \+ . \+ '/$jg/;
 
 	$self->{file_url} = $furl;
-	$self->{file_referer} = $url;
 
 	$self->wait( $self->{s4wait}, \&stage5, "starting in" );
 }
@@ -1025,13 +1033,13 @@
 	my $self = shift;
 	$self->print("downloading");
 
-	$self->download( referer => $self->{file_referer}, cookies => $self->{cookie} );
+	$self->download();
 }
 
 sub DESTROY
 {
 	my $self = shift;
-	unlink $self->{cookie};
+	unlink $self->{cookies};
 }
 
 # }}}
@@ -1094,7 +1102,7 @@
 }
 
 # }}}
-package main;
+package main; # {{{
 
 my $get_list = shift @ARGV || 'get.list';
 print "Using '$get_list' file list\n";
@@ -1115,16 +1123,16 @@
 			next;
 		}
 		my $url = undef;
-		if ( $line =~ m#^\s*(http://rapidshare\.com/.*?)\s*$# ) { #){# vimbug
+		if ( $line =~ m{^\s*(http://rapidshare\.com/.*?)\s*$} ) {
 			$url = $1;
 			new Get::RapidShare( $1 );
-		} elsif ( $line =~ m#^\s*(http://netload\.in/datei.*?)\s*$# ) { #){# vimbug
+		} 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*$# ) { #){# vimbug
+		} 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*$# ) { #){# vimbug
+		} elsif ( $line =~ m{^\s*(http://(www\.)?megaupload\.com/\?d=.*?)\s*$} ) {
 			$url = $1;
 			new Get::MegaUpload( $1 );
 		}
@@ -1189,4 +1197,5 @@
 	return $_;
 }
 
+# }}}
 # vim:ts=4:sw=4:fdm=marker


More information about the pld-cvs-commit mailing list