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->content;
42 return undef unless $res->is_success;
48 my($name, $il, $html, @ret);
51 $il = uc(($name =~ /^(.)/)[0]);
52 $il = "9" if (!($il =~ /[A-Z]/));
53 if(!($html = _get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il")) {
57 # The only way to recognize entries that seems sure is to look
58 # after the "HOVERLINE" class.
60 while($html =~ /<A\s.*CLASS=HOVERLINE\s.*HREF=\"([^\"]+)\".*>([^<]+)<\//ig) {
61 if((substr "" . lc $2 , 0, length $name) eq lc $name) {
65 # push @ret, $1 while $html =~ /<A\s.*CLASS=HOVERLINE\s.*>.*<FONT.*>([^<>]*$name[^<>]*)<\/FONT/ig;
72 my($name, $il, $html, $url);
75 $il = uc(($name =~ /^(.)/)[0]);
76 $il = "9" if (!($il =~ /[A-Z]/));
77 if(!($html = _get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il")) {
81 # The only way to recognize entries that seems sure is to look
82 # after the "HOVERLINE" class.
84 while($html =~ /<A\s.*CLASS=HOVERLINE\s.*HREF=\"([^\"]+)\".*>([^<]+)<\//ig) {
85 if((substr "" . lc $2 , 0, length $name) eq lc $name) {
86 return ($1 =~ /id=(\d+)$/)[0];
98 return "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id";
103 my($html, $kind, @ret);
106 if($html =~ /$kind theme:<\/b>\n/igc) {
107 my(@parts, $ct, $buf);
108 while($html =~ /\G\<br\> (([^<>]|\<i\>|<\/i>)+)/igc) {
110 # 0 1 2 3 4 5 6 7 8 9 10 11
111 if(@parts = ($buf =~ /(\#(\d+):)?\s*\"([^\"\(]+\S)(\s*\((\<i\>(.*)<\/i>(;\s*)?)?([^<>]+)?\))?\"\s+by\s+([^\(]*[^\(\s])(\s*\(eps (\d+)-(\d+)?\))?/i)) {
113 $ct->{"num"} = $parts[1] if defined $parts[1];
114 if(defined $parts[5]) {
115 $ct->{"tit"} = decode_entities($parts[5]);
116 $ct->{"jat"} = decode_entities($parts[2]) if defined $parts[2];
118 $ct->{"tit"} = decode_entities($parts[2]) if defined $parts[2];
120 $ct->{"ent"} = decode_entities($parts[7]) if defined $parts[7];
121 $ct->{"prf"} = decode_entities($parts[8]) if defined $parts[8];
122 $ct->{"fep"} = $parts[10] if defined $parts[10];
123 $ct->{"lep"} = $parts[11] if defined $parts[11];
134 my($id, $buf, $html, %ret);
137 if(!($html = _get geturl $id)) {
141 $ret{"url"} = geturl $id;
142 ($buf) = ($html =~ /\<TITLE\>Anime News Network - ([^<]*)<\/TITLE>/);
143 if($buf =~ /\([^\)]+\)$/) {
144 ($ret{"name"}, $ret{"type"}) = ($buf =~ /^(.*[^\s])\s*\(([^\)]+)\)$/);
148 if(($buf) = ($html =~ /vintage:<\/b>\n([^<]+)</is)) {
151 if(($buf) = ($html =~ /number of episodes:<\/b>\n([^<]+)</is)) {
154 if(($buf) = ($html =~ /genres:<\/b>\n([^<]+)</is)) {
155 $ret{"gnr"} = [split /, /, $buf];
157 $buf = getthemes $html, "opening";
158 $ret{"op"} = $buf if(@{$buf});
159 $buf = getthemes $html, "ending";
160 $ret{"ed"} = $buf if(@{$buf});