From 23d4abb2e29634e8d2e11879be91cec9cfd6ad13 Mon Sep 17 00:00:00 2001 From: fredrik Date: Fri, 5 Aug 2005 00:18:12 +0000 Subject: [PATCH] Initial import. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@303 959494ce-11ee-0310-bf91-de5d638817bd --- ANN.pm | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 ANN.pm diff --git a/ANN.pm b/ANN.pm new file mode 100644 index 0000000..fbf08e5 --- /dev/null +++ b/ANN.pm @@ -0,0 +1,108 @@ +package Anime::ANN; + +use LWP::UserAgent; +use HTML::Entities; + +$ver = "0.1"; + +sub _get +{ + my($uri, $ua, $res); + ($uri) = @_; + + $ua = LWP::UserAgent->new; + $ua->agent("ANNData/$ver "); + + $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 =~ /\n/igc) { + my(@parts, $ct, $buf); + while($html =~ /\G\    (([^<>]|\|<\/i>)+)/igc) { + $buf = $1; + # 0 1 2 3 4 5 6 7 8 9 10 11 + if(@parts = ($buf =~ /(\#(\d+):)?\s*\"([^\"\(]+)(\s+\((\(.*)<\/i>(;\s*)?)?([^<>]+)?\))?\"\s+by\s+([^\(]*[^\(\s])(\s*\(eps (\d+)-(\d+)?\))?/i)) { + $ct = {}; + $ct->{"num"} = $parts[1] if defined $parts[1]; + if(defined $parts[5]) { + $ct->{"tit"} = $parts[5]; + $ct->{"jat"} = decode_entities($parts[2]) if defined $parts[2]; + } else { + $ct->{"tit"} = $parts[2] if defined $parts[2]; + } + $ct->{"ent"} = $parts[7] if defined $parts[7]; + $ct->{"prf"} = $parts[8] if defined $parts[8]; + $ct->{"fep"} = $parts[10] if defined $parts[10]; + $ct->{"lep"} = $parts[11] if defined $parts[11]; + push @ret, $ct; + } + } + } + + return \@ret; +} + +sub getseries +{ + my($id, $buf, $html, %ret); + ($id) = @_; + + $html = _get "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id"; + + $ret{"url"} = "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id"; + ($ret{"name"}) = ($html =~ /\Anime News Network - ([^<]*)<\/TITLE>/); + if(($buf) = ($html =~ /vintage:<\/b>\n([^<]+)\n([^<]+)