#!/usr/bin/perl -w use LWP::UserAgent; use Getopt::Long; 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 =~ /.*([^<>]*$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 =~ /Anime News Network - ([^<]*)<\/TITLE>/)[0]); } GetOptions(\%options, ("l")); if($options{"l"}) { @list = getlist $ARGV[0]; foreach $name (@list) { print "$name\n"; } exit 0; } unless($test = getid $ARGV[0]) { printf STDERR "could not find $ARGV[0]\n"; exit 1; } print getnamefromid($test) . "\n";