Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use URI;
- use Web::Scraper;
- use Encode;
- use Data::Dumper;
- use File::Fetch;
- use Try::Tiny;
- my @volumes=(1..18);
- my @chapters=(1..126);
- #my $url_pat="http://mangapark.me/manga/eden-it-s-an-endless-world/s1/v%d/c%d/";
- my $url_pat="http://mangapark.me/manga/dragon-head/s1/v%d/c%d/";
- my $imgs = scraper {
- process 'section[id="viewer"] a[class="img-link"]', "imgs[]" => scraper {
- process "img", uri => '@src', num=> '@rel';
- };
- };
- foreach my $vol(@volumes){
- my $voldir=sprintf("vol%02d",$vol);
- foreach my $ch(@chapters){
- my $chdir=sprintf("$voldir-ch%02d",$ch);
- my $full_url=sprintf($url_pat,$vol,$ch);
- print "$full_url\n";
- my $res;
- try{
- $res = $imgs->scrape( URI->new($full_url) );
- };
- if ($res) {
- for my $img (@{$res->{imgs}}) {
- print "$voldir\n";
- if(! -d $voldir){
- mkdir $voldir or die "Dir cannot be created: $!";
- }
- if(! -d "$voldir/$chdir"){
- mkdir "$voldir/$chdir" or die "Dir cannot be created: $!";
- }
- #print Encode::encode("utf8", "$img->{num}\t$img->{uri}\n");
- my $url=$img->{uri};
- my $pagenum=sprintf("%03d",$img->{num});
- print $pagenum.' '.$url."\n";
- my $ff = File::Fetch->new(uri => $url);
- my $file = $ff->fetch();
- my $newfile="$voldir/$chdir/$chdir-p$pagenum.jpg";
- print "$newfile\n";
- rename $file,$newfile;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement