From 38723e017d0984d5d9a1ac2a8cd78a363f450ab4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 22 May 2010 19:55:01 +0200 Subject: Actually use the next_link for comirror --- bin/comirror | 27 +++++++++++++++++++++------ bin/comirror-setup | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bin/comirror b/bin/comirror index 8a9528b..b5e20ab 100755 --- a/bin/comirror +++ b/bin/comirror @@ -12,6 +12,7 @@ my $mech = WWW::Mechanize->new( my $uri = shift || first_line('last_uri'); my $image_re = first_line('image_re'); my $exit = 1; +my $next_link_text; if (not defined $uri or not defined $image_re) { die("last_uri or image_re not found / specified\n"); @@ -19,17 +20,31 @@ if (not defined $uri or not defined $image_re) { $image_re = qr{$image_re}; +if (-e 'next_link') { + $next_link_text = first_line('next_link'); +} + sub find_next_link { - foreach my $re ( - qr{ ^ next $ }ix, - qr{ next }ix, - ) - { - my $link = $mech->find_link(text_regex => $re); + + if (defined $next_link_text) { + my $link = $mech->find_link(text => $next_link_text); if ($link) { return $link; } } + else { + + foreach my $re ( + qr{ ^ next $ }ix, + qr{ next }ix, + ) + { + my $link = $mech->find_link(text_regex => $re); + if ($link) { + return $link; + } + } + } save_lasturi(); say "Cannot find next link. We might have reached the end of the comic."; exit $exit; diff --git a/bin/comirror-setup b/bin/comirror-setup index 05661bf..f5d4c76 100755 --- a/bin/comirror-setup +++ b/bin/comirror-setup @@ -39,6 +39,7 @@ print "\nComparing images"; for my $i ( 0 .. $#mechs ) { for my $image ($mechs[$i]->find_all_images()) { push(@{$images[$i]}, $image->url_abs()); + say "$i $images[$i]->[-1]"; } print q{.}; } @@ -94,6 +95,7 @@ for my $offset ( 0 .. $length ) { line_to_file($ARGV[0], 'last_uri'); line_to_file($image_re, 'image_re'); +line_to_file($next_link, 'next_link'); print "\nimage_re: ${image_re}\n\n"; say "\"next\" link text: ${next_link}"; -- cgit v1.2.3