--- /dev/null
+#! /usr/bin/perl
+# , and is released
+# under the terms of the GPL version 2, or any later version, at your
+# option. See the file README and COPYING for more information.
+# Copyright 2009 by Don Armstrong <don@donarmstrong.com>.
+# $Id: perl_script 1432 2009-04-21 02:42:41Z don $
+
+
+use warnings;
+use strict;
+
+use Getopt::Long;
+use Pod::Usage;
+
+=head1 NAME
+
+get_one_manga - get_one_manga [manga]
+
+=head1 SYNOPSIS
+
+ [options]
+
+ Options:
+ --debug, -d debugging level (Default 0)
+ --help, -h display this help
+ --man, -m display manual
+
+=head1 OPTIONS
+
+=over
+
+=item B<--debug, -d>
+
+Debug verbosity. (Default 0)
+
+=item B<--help, -h>
+
+Display brief usage information.
+
+=item B<--man, -m>
+
+Display this manual.
+
+=back
+
+=head1 EXAMPLES
+
+
+=cut
+
+
+use WWW::Mechanize;
+use IO::Dir;
+use IO::File;
+use vars qw($DEBUG);
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ onemanga => 'http://www.onemanga.com',
+ );
+
+GetOptions(\%options,
+ 'debug|d+','help|h|?','man|m');
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+my @USAGE_ERRORS;
+# if (1) {
+# push @USAGE_ERRORS,"You must give the name of a manga";
+# }
+
+pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
+
+
+my @manga_to_get = @ARGV;
+
+if (not @ARGV) {
+ my $d = IO::Dir->new('.') or die "Unable to open directory . for reading";
+ while (defined($_ = $d->read)) {
+ next if /^./;
+ next unless -d $_;
+ push @manga_to_get,$_;
+ }
+}
+
+
+my $failure = 0;
+my $m = WWW::Mechanize->new();
+for my $manga (@manga_to_get) {
+ # see if the manga exists
+ $m->get($options{onemanga}.'/'.$manga);
+ if ($m->status() != 200) {
+ print STDERR "Manga $manga doesn't exist\n";
+ $failure ||= 1;
+ next;
+ }
+ if (! -d $manga) {
+ #mkdir($manga);
+ }
+ # figure out where to start getting stuff
+ my @chapter_links = $m->find_all_links(url_abs_regex => qr{\Q$manga\E\/\d+});
+ for my $chapter_link (reverse @chapter_links) {
+ print $chapter_link->url(),qq(\n);
+ my ($chapter) = $chapter_link->url() =~ m/(\d+)\/?$/;
+ if (! -d "$manga/$chapter_link") {
+ #mkdir("$manga/$chapter");
+ my $page = 0;
+ $m->get($chapter_link->url_abs());
+ $m->follow_link(text_regex => qr{Begin reading});
+ while ($m->uri() =~ m{\Q$chapter\E\/\d+/?$}) {
+ $page++;
+ 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+});
+ $m->get($image->url_abs());
+ print "getting ".$image->url_abs()."\n";
+ # $m->save_content("$manga/$chapter/".sprintf('%04d',$page).".jpg");
+ $m->get($next_link->url_abs());
+ print $m->uri();
+ sleep 3;
+ }
+ exit 0;
+ }
+ }
+}
+
+
+__END__