#!/usr/bin/perl -w
-use LWP::UserAgent;
use Getopt::Long;
+use Anime::ANN;
-sub get
-{
- my($uri, $ua, $res);
- ($uri) = @_;
-
- $ua = LWP::UserAgent->new;
- $ua->agent("ANNData/0.1");
-
- $res = $ua->request(HTTP::Request->new("GET", "$uri"));
-
- die "could not fetch $uri\n" unless $res->is_success;
- return $res->content;
-}
-
-sub getlist
-{
- my($name, $il, $html, @ret);
- ($name) = @_;
-
- $il = uc(($name =~ /^(.)/)[0]);
- $il = "9" if (!($il =~ /[A-Z]/));
- $html = get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il";
-
- # The only way to recognize entries that seems sure is to look
- # after the "HOVERLINE" class.
-
- push @ret, $1 while $html =~ /<A\s.*CLASS=HOVERLINE\s.*>.*<FONT.*>([^<>]*$name[^<>]*)<\/FONT/ig;
-
- return(@ret);
-}
-
-sub getid
-{
- my($name, $il, $html, $url);
- ($name) = @_;
-
- $il = uc(($name =~ /^(.)/)[0]);
- $il = "9" if (!($il =~ /[A-Z]/));
- $html = get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il";
-
- # The only way to recognize entries that seems sure is to look
- # after the "HOVERLINE" class.
-
- (($url) = ($html =~ /<A\s.*CLASS=HOVERLINE\s.*HREF=\"([^\"]+)\".*$name/i)) || return;
-
- return((($url =~ /\?id=(\d+)$/)[0]));
-}
-
-sub getnamefromid
-{
- my($id, $html);
- ($id) = @_;
-
- $html = get "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id";
-
- return(($html =~ /\<TITLE\>Anime News Network - ([^<]*)<\/TITLE>/)[0]);
-}
-
-GetOptions(\%options, ("l"));
+GetOptions(\%options, ("l=s", "b=s"));
if($options{"l"}) {
- @list = getlist $ARGV[0];
+ @list = Anime::ANN::getlist($options{"l"});
foreach $name (@list) {
print "$name\n";
}
exit 0;
}
-unless($test = getid $ARGV[0]) {
+if($options{"b"}) {
+ exec "htmlview", Anime::ANN::geturl(Anime::ANN::getid $options{"b"});
+}
+
+if(!defined($ARGV[0])) {
+ printf STDERR "usage: anndata NAME\n";
+ exit 1;
+}
+
+unless($id = Anime::ANN::getid $ARGV[0]) {
printf STDERR "could not find $ARGV[0]\n";
exit 1;
}
-print getnamefromid($test) . "\n";
+$info = Anime::ANN::getseries $id;
+
+sub refdump
+{
+ my($ref, $ind);
+ ($ref, $ind) = @_;
+ if(!defined($ind)) {
+ $ind = 0;
+ }
+
+ if(ref $ref eq "HASH") {
+ for $key (sort keys %{$ref}) {
+ print ((" " x $ind) . "$key: " . (" " x (20 - length $key)) . "(" . $ref->{$key} . ")\n");
+ refdump($ref->{$key}, $ind + 1) if ref $ref->{$key};
+ }
+ } elsif(ref $ref eq "ARRAY") {
+ for($i = 0; $i < @{$ref}; $i++) {
+ print ((" " x $ind) . "$i: " . $ref->[$i] . "\n");
+ refdump($ref->[$i], $ind + 1) if ref $ref->[$i];
+ }
+ } else {
+ print ((" " x $ind) . "Unknown ref: $ref\n");
+ }
+}
+binmode STDOUT, ":utf8";
+refdump $info;