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 push @ret, $1 while $html =~ /<A\s.*CLASS=HOVERLINE\s.*>.*<FONT.*>([^<>]*$name[^<>]*)<\/FONT/ig;
67 my($name, $il, $html, $url);
70 $il = uc(($name =~ /^(.)/)[0]);
71 $il = "9" if (!($il =~ /[A-Z]/));
72 if(!($html = _get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il")) {
76 # The only way to recognize entries that seems sure is to look
77 # after the "HOVERLINE" class.
79 (($url) = ($html =~ /<A\s.*CLASS=HOVERLINE\s.*HREF=\"([^\"]+)\".*$name/i)) || return;
81 return ($url =~ /\?id=(\d+)$/)[0];
89 return "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id";
94 my($html, $kind, @ret);
97 if($html =~ /$kind theme:<\/b>\n/igc) {
98 my(@parts, $ct, $buf);
99 while($html =~ /\G\<br\> (([^<>]|\<i\>|<\/i>)+)/igc) {
101 # 0 1 2 3 4 5 6 7 8 9 10 11
102 if(@parts = ($buf =~ /(\#(\d+):)?\s*\"([^\"\(]+)(\s+\((\<i\>(.*)<\/i>(;\s*)?)?([^<>]+)?\))?\"\s+by\s+([^\(]*[^\(\s])(\s*\(eps (\d+)-(\d+)?\))?/i)) {
104 $ct->{"num"} = $parts[1] if defined $parts[1];
105 if(defined $parts[5]) {
106 $ct->{"tit"} = decode_entities($parts[5]);
107 $ct->{"jat"} = decode_entities($parts[2]) if defined $parts[2];
109 $ct->{"tit"} = decode_entities($parts[2]) if defined $parts[2];
111 $ct->{"ent"} = decode_entities($parts[7]) if defined $parts[7];
112 $ct->{"prf"} = decode_entities($parts[8]) if defined $parts[8];
113 $ct->{"fep"} = $parts[10] if defined $parts[10];
114 $ct->{"lep"} = $parts[11] if defined $parts[11];
125 my($id, $buf, $html, %ret, @cp);
128 if(!($html = _get geturl $id)) {
132 $ret{"url"} = geturl $id;
133 ($buf) = ($html =~ /\<TITLE\>Anime News Network - ([^<]*)<\/TITLE>/);
134 if($buf =~ /\([^\)]+\)$/) {
135 ($ret{"name"}, $ret{"type"}) = ($buf =~ /^(.*[^\s])\s*\(([^\)]+)\)$/);
139 if(($buf) = ($html =~ /vintage:<\/b>\n([^<]+)</is)) {
142 if(($buf) = ($html =~ /number of episodes:<\/b>\n([^<]+)</is)) {
145 if(($buf) = ($html =~ /genres:<\/b>\n([^<]+)</is)) {
146 @cp = split /,\s*/, $buf;
149 $buf = getthemes $html, "opening";
150 $ret{"op"} = $buf if(@{$buf});
151 $buf = getthemes $html, "ending";
152 $ret{"ed"} = $buf if(@{$buf});