| 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | use Getopt::Long; |
| 4 | use Anime::ANN; |
| 5 | |
| 6 | GetOptions(\%options, "l=s", "b=s") || exit 1; |
| 7 | |
| 8 | if($options{"l"}) { |
| 9 | @list = Anime::ANN::getlist($options{"l"}); |
| 10 | foreach $name (@list) { |
| 11 | print "$name\n"; |
| 12 | } |
| 13 | exit 0; |
| 14 | } |
| 15 | |
| 16 | if($options{"b"}) { |
| 17 | $id = Anime::ANN::getid $options{"b"}; |
| 18 | if(defined($id)) { |
| 19 | exec "htmlview", Anime::ANN::geturl($id); |
| 20 | } else { |
| 21 | printf STDERR "could not find " . $options{"b"} . "\n"; |
| 22 | exit 1; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | if(!defined($ARGV[0])) { |
| 27 | printf STDERR "usage: anndata NAME\n"; |
| 28 | exit 1; |
| 29 | } |
| 30 | |
| 31 | unless($id = Anime::ANN::getid $ARGV[0]) { |
| 32 | printf STDERR "could not find $ARGV[0]\n"; |
| 33 | exit 1; |
| 34 | } |
| 35 | |
| 36 | $info = Anime::ANN::getseries $id; |
| 37 | |
| 38 | sub refdump |
| 39 | { |
| 40 | my($ref, $ind); |
| 41 | ($ref, $ind) = @_; |
| 42 | if(!defined($ind)) { |
| 43 | $ind = 0; |
| 44 | } |
| 45 | |
| 46 | if(ref $ref eq "HASH") { |
| 47 | for $key (sort keys %{$ref}) { |
| 48 | print ((" " x $ind) . "$key: " . (" " x (20 - length $key)) . "(" . $ref->{$key} . ")\n"); |
| 49 | refdump($ref->{$key}, $ind + 1) if ref $ref->{$key}; |
| 50 | } |
| 51 | } elsif(ref $ref eq "ARRAY") { |
| 52 | for($i = 0; $i < @{$ref}; $i++) { |
| 53 | print ((" " x $ind) . "$i: " . $ref->[$i] . "\n"); |
| 54 | refdump($ref->[$i], $ind + 1) if ref $ref->[$i]; |
| 55 | } |
| 56 | } elsif(ref $ref eq "SCALAR") { |
| 57 | print ((" " x $ind) . $$ref . "\n"); |
| 58 | } else { |
| 59 | print ((" " x $ind) . "Unknown ref: $ref\n"); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | binmode STDOUT, ":utf8"; |
| 64 | refdump $info; |