I posted yesterday about grabbing ElfQuest comics with a script. And that it would be shorter in perl? Well, only if you don't add more features. :p
If you intend to settle in and read these, I'd recommend getting a comic reader. These are basically just an image viewers, but they can open archive files and organize the images in a logical way for reading.
For Linux, I like Comix. It's very simple and reads a number of formats. For windows I don't know, but this page should give an idea.
Here's the final script. It includes everything currently on the site. With little effort should even run on a windows box, if you have perl.
If you intend to settle in and read these, I'd recommend getting a comic reader. These are basically just an image viewers, but they can open archive files and organize the images in a logical way for reading.
For Linux, I like Comix. It's very simple and reads a number of formats. For windows I don't know, but this page should give an idea.
Here's the final script. It includes everything currently on the site. With little effort should even run on a windows box, if you have perl.
#!/usr/bin/perl
use strict;
use LWP::Simple;
my $MinSize=100000;
my $BaseUrl='http://www.elfquest.com/gallery/OnlineComics';
my $BasePath='.';
getSeries('oq','hy','sh','nb','tc','ess', 'ka','ts', 'jk','rb');
sub getIssuePage {
my ($seriesId, $issuePath, $issueNum, $pageNum) = @_;
my $pageName = sprintf("%s%02d-%d.jpg", (lc $seriesId), $issueNum, $pageNum);
my $url = sprintf("%s/%s/%s%02d/%s", $BaseUrl, (uc $seriesId), (uc $seriesId), $issueNum, $pageName);
my $fileName = "$issuePath/$pageName";
if ( -e $fileName ) {
my $fileSize = (-s $fileName);
if ( $fileSize < $MinSize) {
unlink $fileName;
} else {
return 1;
}
}
print "Downloading $pageName\n";
return getFile($url, $fileName);
}
sub getIssue {
my ($seriesId, $seriesPath, $issueNum) = @_;
my $issuePath = $seriesPath . "/" . sprintf("%02d", $issueNum);
mkdir $issuePath if ( ! -e $issuePath );
my $pageNum = 0;
while (getIssuePage($seriesId, $issuePath, $issueNum, $pageNum)) { $pageNum++; }
my @fl = <$issuePath/*>;
rmdir $issuePath if ($#fl < 0);
return $pageNum>0;
}
sub getSeries {
my (@seriesList) = @_;
foreach my $seriesId (@seriesList) {
$seriesId = lc $seriesId;
my $seriesPath = "$BasePath/$seriesId";
mkdir $seriesPath if ( ! -e $seriesPath );
my $issueNum = 1;
while (getIssue($seriesId, $seriesPath, $issueNum)) { $issueNum++; }
}
}
sub getFile {
my ($url, $fileName) = @_;
my $response = getstore($url, $fileName);
if ( ! -e $fileName ) {
print "Fail $response\n";
} else {
my $fileSize = (-s $fileName);
if ( $fileSize < $MinSize) {
print "Fail, file too small ($fileSize)\n";
unlink $fileName;
} else {
print "got it ($fileSize)\n";
return 1;
}
}
return;
}