#!/usr/bin/perl
use LWP::Simple;

print "Enter the base URL of the PrintRoom photo album.\nExample - http://www.printroom.com/ViewGalleryPhoto.asp?evgroupid=0&userid=DavidMadison&gallery_id=1029074&image_id=\n";
print "Album base URL: ";
$base = <STDIN>;
chomp $base;

print "Enter the total number of photos in album. Should be listed on the page\n";
print "Photos in album: ";
$pcount = <STDIN>;
chomp $pcount;

for(my $i = 0; $i < $pcount; $i++){
	print "Image " . ($i+1) . " of $pcount:\n\tPage download...";
	my $data = get($base . $i);
	$data = get($base . $i) until($data);
	print " done!\n";
	
	print "\tPage parsing...";
	my @lines = split("\r", $data);
	my $hexurl = "";
	for(my $j = 0; $j < @lines && $hexurl eq ""; $j++){
		if($lines[$j] =~ s/imageURL\s+=\s+"http/http/g){
			$hexurl = $lines[$j];
			chop($hexurl);
			
			$hexurl =~ s/\s+//g;
			$hexurl =~ s/%3[aA]/:/g;
			$hexurl =~ s/%2[fF]/\//g;
			$hexurl =~ s/%2[eE]/./g;
			$hexurl =~ s/%5[fF]/_/g;
		}
	}
	print " done!\n";

	print "\tImage downloading...";
	system("wget -q $hexurl");
	print " done!\n";
}