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