All pastes #552028 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-09 02:06 UTC
rendered paste body
	print FILE $$content;
	close FILE;
}

sub fill{
	while(1){
		print "Getting post list, offset=$currpos.. ";
		
		my $req = (GET "$site/9/?position=$currpos&limit=50&request=GetPosts&postrating=$rating&search=$query");
		my $res = $ua->request($req);
		if ($res->is_success){
			$_=$res->content;
			while(/<item PostID="(\d+)">(.*?)<\/item>/g){
				my($num,$text)=($1,$2);
				my %post;
				$post{num}=$num;
				my($date,$userid,$md5,$contenttype,$w,$h,$ip,$ext)=map{
					$text=~/<$_>(.*)<\/$_>/;$post{lc $_}=$1;$1;
				}("UploadDate","UserID","MD5","ContentType","Width","Height","UploadIP","FileExtension");
				push @posts,\%post;
			}
			print "done!\n";
			last;
		}
		else{
			print "error:".$res->status_line."\n";
		}
	}
}

sub parse{
	while($_=shift @ARGV){ 
		if(/^--(limit|pos|rating|path|filename)=(.*)$/)
			{eval(qq{\$$1='$2'});}
		else
			{usage();}
	}
}

sub usage{
	print <<HERE;
Usage: $0 QUERY [OPTION]...
Downloads images from sagubooru into current directory.

      --filename=TEMPLATE    Use TEMPLATE to to generate file names (default
                             '\${num}'; ex: 'post\${num}', 'sagu-\${md5}')
      --limit=COUNT          Download up to COUNT images (default 16777216)
      --pos=POSITION         Start downloading from image with number POSITION
      --rating=RATING        Combination of 's' 'q' 'm' 'u' (ex: 'smq')
      --path=PATH            Download to PATH instead of current directory
HERE
	
	exit;
}