SVN: toys/rsget.pl/Get/GigaSize

sparky sparky at pld-linux.org
Thu Oct 22 17:40:13 CEST 2009


Author: sparky
Date: Thu Oct 22 17:40:12 2009
New Revision: 10820

Modified:
   toys/rsget.pl/Get/GigaSize
Log:
- use new tools
- replace dedicated captcha solver with captcha processor
- checked


Modified: toys/rsget.pl/Get/GigaSize
==============================================================================
--- toys/rsget.pl/Get/GigaSize	(original)
+++ toys/rsget.pl/Get/GigaSize	Thu Oct 22 17:40:12 2009
@@ -4,47 +4,7 @@
 short: GS
 uri: qr{gigasize\.com/get\.php\?d=}
 cookie: gs
-status: OK 2009-10-11
-
-pre:
-	use IPC::Open2;
-	my @cap;
-	if ( require_prog( "djpeg" ) ) {
-		push @cap, 'djpeg -pnm -grey';
-	} elsif ( require_prog( "jpegtopnm" ) ) {
-		push @cap, 'jpegtopnm';
-		push @cap, 'ppmtopgm' if require_prog( "ppmtopgm" );
-		warn "Using jpegtopnm, but djpeg would give better results\n";
-	} else {
-		die "Required djpeg (preferred) or jpegtopnm\n";
-	}
-
-	push @cap, 'pamcut -left 15 -top 3 -right 42 -bottom 16'
-		if require_prog( "pamcut" );
-
-	if ( require_prog( "gocr" ) ) {
-		push @cap, 'gocr -f ASCII  -a 5 -m 56';
-	} elsif ( require_prog( "ocrad" ) ) {
-		push @cap, 'ocrad';
-		warn "Using ocrad, but gocr would give better results\n";
-	} else {
-		die "Required gocr (preferred) or ocrad\n";
-	}
-	my $cap_prog = join " | ", map "$_ 2>/dev/null", @cap;
-
-	sub captcha
-	{
-		my $data = shift;
-
-		IPC::Open2::open2( *READ, *WRITE, $cap_prog );
-		print WRITE $$data;
-		close WRITE;
-		my $out = <READ>;
-		close READ;
-
-		return $1 if $out =~ /([a-zA-Z]{3})/;
-		return undef;
-	}
+status: OK 2009-10-22
 
 start:
 	GET( $-{_uri} );
@@ -52,29 +12,57 @@
 	ERROR( "file not found" ) if /The file has been deleted/;
 
 	! m{<strong>Name</strong>:\s*<b>(.*?)</b></p>\s*<p>Size:\s*<span>($STDSIZE)</span>};
-	INFO( name => $1, asize => $2 );
+	my ( $name, $size ) = ( $1, $2 );
+	$name =~ s/\.\.\.$/\0/;
+	INFO( iname => $name, asize => $size );
 
 stage_captcha:
-	PRINT( "solving captcha" );
 	! $-{form} = $self->form( match => { action => qr{^/formdownload\.php$} } );
 
+stage_getimage:
 	GET( "/randomImage.php", keep_referer => 1 );
 
-	my $cap = captcha( \$_ );
-	RESTART( -1, "Can't decode captcha" ) unless $cap;
-	$-{form}->set( txtNumber => $cap );
+	CAPTCHA(
+		qr/[A-Z]{3}/,
+		process => \&gs_decaptcha
+	);
+	GOTO stage_getimage unless $_;
 
+	$-{form}->set( txtNumber => $_ );
 	GET( $-{form}->post() );
 
-	GOTO stage_captcha if $-{_referer} =~ /err=invalidchecksum$/;
+	if ( $-{_referer} =~ /err=invalidchecksum$/ ) {
+		CAPTCHA_RESULT( "FAIL" );
+		GOTO stage_captcha;
+	}
 	RESTART( -180 - int rand 360, "free limit reached, waiting time unknown" )
 		if /YOU HAVE REACHED YOUR FREE DOWNLOAD LIMIT/;
 
 	! $-{form} = $self->form( id => "formDownload" );
 
+	CAPTCHA_RESULT( "OK" );
+
 	! m{var seconds=(\d+)};
 	WAIT( $1, "starting download" );
 	
-	DOWNLOAD( $-{form}->post() );
+	CLICK_DOWNLOAD( $-{form}->post() );
+
+perl:
+
+sub gs_color_select
+{
+	my @s = sort { $a <=> $b } @_;
+	return $s[2];
+}
+
+sub gs_decaptcha
+{
+	my $img = shift;
+	$img->color_filter( \&gs_color_select );
+	$img = $img->crop( x1 => 15, y1 => 3, x2 => 42, y2 => 16 );
+	$img->luma_emphasize( 10, 50 );
+	return $img->doublesize->ocr();
+}
+
 
 # vim:ts=4:sw=4


More information about the pld-cvs-commit mailing list