Advertisement
Guest User

Untitled

a guest
Mar 29th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.56 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use URI;
  4. use Web::Scraper;
  5. use Encode;
  6. use Data::Dumper;
  7. use File::Fetch;
  8. use Try::Tiny;
  9.  
  10. my @volumes=(1..18);
  11. my @chapters=(1..126);
  12. #my $url_pat="http://mangapark.me/manga/eden-it-s-an-endless-world/s1/v%d/c%d/";
  13. my $url_pat="http://mangapark.me/manga/dragon-head/s1/v%d/c%d/";
  14.  
  15. my $imgs = scraper {
  16.       process 'section[id="viewer"] a[class="img-link"]', "imgs[]" => scraper {
  17.         process "img", uri => '@src', num=> '@rel';
  18.       };
  19.   };
  20.  
  21.  
  22. foreach my $vol(@volumes){
  23.     my $voldir=sprintf("vol%02d",$vol);
  24.     foreach my $ch(@chapters){
  25.         my $chdir=sprintf("$voldir-ch%02d",$ch);
  26.  
  27.         my $full_url=sprintf($url_pat,$vol,$ch);
  28.         print "$full_url\n";
  29.         my $res;
  30.         try{
  31.          $res = $imgs->scrape( URI->new($full_url) );
  32.          };
  33.          
  34.          if ($res) {
  35.  
  36.         for my $img (@{$res->{imgs}}) {
  37.             print "$voldir\n";
  38.             if(! -d $voldir){
  39.             mkdir $voldir or die "Dir cannot be created: $!";
  40.         }
  41.         if(! -d "$voldir/$chdir"){
  42.             mkdir "$voldir/$chdir" or die "Dir cannot be created: $!";
  43.             }
  44.  
  45.    
  46.             #print Encode::encode("utf8", "$img->{num}\t$img->{uri}\n");
  47.             my $url=$img->{uri};
  48.             my $pagenum=sprintf("%03d",$img->{num});
  49.             print $pagenum.' '.$url."\n";
  50.             my $ff = File::Fetch->new(uri => $url);
  51.             my $file = $ff->fetch();
  52.             my $newfile="$voldir/$chdir/$chdir-p$pagenum.jpg";
  53.             print "$newfile\n";
  54.             rename $file,$newfile;
  55.         }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement