]> git.donarmstrong.com Git - bin.git/blobdiff - get_one_manga
* document tex-only and log-only
[bin.git] / get_one_manga
index 6920c04835dd17e7c47c2ac55955ac467b73a995..6336726bff3ef6c493068899993be5325d991267 100755 (executable)
@@ -49,6 +49,7 @@ Display this manual.
 =cut
 
 
+use URI::Escape;
 use WWW::Mechanize;
 use IO::Dir;
 use IO::File;
@@ -92,7 +93,7 @@ my $failure = 0;
 my $m = WWW::Mechanize->new();
 for my $manga (@manga_to_get) {
     # see if the manga exists
-    mm_get($options{onemanga}.'/'.$manga);
+    mm_get($m,$options{onemanga}.'/'.$manga);
     if ($m->status() != 200) {
        print STDERR "Manga $manga doesn't exist\n";
        $failure ||= 1;
@@ -102,6 +103,8 @@ for my $manga (@manga_to_get) {
        mkdir($manga);
     }
     # figure out where to start getting stuff
+    # we need to escape ! apparently; there are probably other characters as well
+    my $manga_escaped = uri_escape($manga,'!');
     my @chapter_links = $m->find_all_links(url_abs_regex => qr{\Q$manga\E\/\d+});
     for my $chapter_link (reverse @chapter_links) {
        my ($chapter) = $chapter_link->url() =~ m/([\d.-]+)\/?$/;
@@ -113,8 +116,8 @@ for my $manga (@manga_to_get) {
            my $link = $m->find_link(text_regex => qr{Begin reading});
            mm_get($m,$link->url_abs());
            while ($m->uri() =~ m{\Q$chapter\E/(\d\d[^\/]*)/?$}) {
-               my $image = $m->find_image(alt_regex => qr{Loading\.+\s+media});
-               my $next_link = $m->find_link(url_regex => qr{\Q$manga\E/\Q$chapter\E/(\d\d[^\/]*)});
+               my $image = $m->find_image(alt_regex => qr{Loading\.+\s+(media|img)});
+               my $next_link = $m->find_link(url_regex => qr{\Q$manga_escaped\E/\Q$chapter\E/(\d\d[^\/]*)});
                mm_get($m,$image->url_abs());
                print "getting ".$image->url_abs()."\n";
                my ($page) = $image->url_abs =~ m/([^\/]+)$/;
@@ -137,7 +140,7 @@ sub mm_get{
            $return = $m->get($url);
        };
     } while ($@ and
-            $rerun-- > 0 and sleep 5);
+            ($rerun-- > 0) and sleep 5);
     return $return;
 }