9 $ua = LWP::UserAgent->new;
10 $ua->agent("ANNData/$ver ");
15 my($uri, $cname, $res);
18 $cname = $ENV{"HOME"} . "/.ann/";
19 mkdir $cname unless -e $cname;
21 mkdir $cname unless -e $cname;
22 $cname .= Digest::MD5::md5_hex $uri;
23 if($usecache && -e $cname) {
26 if((time - $s[9]) < 86400) {
28 open CACHE, "<:utf8", $cname;
29 $res .= $buf while read CACHE, $buf, 1024;
35 $res = $ua->request(HTTP::Request->new("GET", "$uri"));
37 if(open CACHE, ">:utf8", $cname) {
38 print CACHE $res->decoded_content;
42 return undef unless $res->is_success;
43 return $res->decoded_content;
48 my($name, $il, $html, @ret);
51 $name = ($name =~ /^(the\s+)?(.*)$/i)[1];
52 $il = uc(($name =~ /^\W*(.)/)[0]);
53 $il = "9" if (!($il =~ /[A-Z]/));
54 if(!($html = _get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il")) {
58 # The only way to recognize entries that seems sure is to look
59 # after the "HOVERLINE" class.
61 while($html =~ /<A\s+CLASS="HOVERLINE"\s+HREF="([^"]+)"[^>]*>(<FONT[^>]*>)?(<small>[^<]*<\/small>)?\s*([^<]+)<\//ig) {
62 if((substr "" . lc $4 , 0, length $name) eq lc $name) {
66 # push @ret, $1 while $html =~ /<A\s.*CLASS=HOVERLINE\s.*>.*<FONT.*>([^<>]*$name[^<>]*)<\/FONT/ig;
73 my($name, $il, $html, $url);
76 $name = ($name =~ /^(the\s+)?(.*)$/i)[1];
77 $il = uc(($name =~ /^\W*(.)/)[0]);
78 $il = "9" if (!($il =~ /[A-Z]/));
79 if(!($html = _get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il")) {
83 # The only way to recognize entries that seems sure is to look
84 # after the "HOVERLINE" class.
86 while($html =~ /<A\s+CLASS="HOVERLINE"\s+HREF="([^"]+)"[^>]*>(<FONT[^>]*>)?(<small>[^<]*<\/small>)?\s*([^<]+)<\//ig) {
87 if((substr "" . lc $4 , 0, length $name) eq lc $name) {
88 return ($1 =~ /id=(\d+)$/)[0];
100 return "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id";
105 my($html, $kind, @ret);
108 if($html =~ /$kind theme:<\/strong>\s*\n/igc) {
109 my(@parts, $ct, $buf);
110 while($html =~ /\G\s*\<div class=\"tab\"\>(([^<>]|\<i\>|<\/i>)+)(<span[^<>]*>[^<>]*<img[^<>]*>[^<>]*<\/span>)?<\/div>/igc) {
112 # 0 1 2 3 4 5 6 7 8 9 10 1112
113 if(@parts = ($buf =~ /(\#(\d+):)?\s*\"([^\"\(]+\S)(\s*\((\<i\>(.*)<\/i>( - \s*)?)?([^<>]+)?\))?\"\s+by\s+([^\(]*[^\(\s])(\s*\(eps? (\d+)(-(\d+))?\))?/i)) {
115 $ct->{"num"} = $parts[1] if defined $parts[1];
116 if(defined $parts[5]) {
117 $ct->{"tit"} = decode_entities($parts[5]);
118 $ct->{"jat"} = decode_entities($parts[2]) if defined $parts[2];
120 $ct->{"tit"} = decode_entities($parts[2]) if defined $parts[2];
122 $ct->{"ent"} = decode_entities($parts[7]) if defined $parts[7];
123 $ct->{"prf"} = decode_entities($parts[8]) if defined $parts[8];
124 $ct->{"fep"} = $parts[10] if defined $parts[10];
125 $ct->{"lep"} = $parts[12] if defined $parts[12];
136 my($id, $buf, $html, %ret);
139 if(!($html = _get geturl $id)) {
143 $ret{"url"} = geturl $id;
144 ($buf) = ($html =~ /\<title\>([^<]*) - Anime News Network<\/title>/);
145 if($buf =~ /\([^\)]+\)$/) {
146 ($ret{"name"}, $ret{"type"}) = ($buf =~ /^(.*[^\s])\s*\(([^\)]+)\)$/);
150 if(($buf) = ($html =~ /vintage:<\/strong>\s*\n\s*<span>([^<]+)</is)) {
153 if(($buf) = ($html =~ /number of episodes:<\/strong>\s*\n\s*<span>([^<]+)</is)) {
156 if(($buf) = ($html =~ /genres:<\/strong>\s*\n\s*([^<]+)</is)) {
157 $ret{"gnr"} = [split /, /, $buf];
159 $buf = getthemes $html, "opening";
160 $ret{"op"} = $buf if(@{$buf});
161 $buf = getthemes $html, "ending";
162 $ret{"ed"} = $buf if(@{$buf});