Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

anidb.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?
  2. if (empty($_GET['aid'])) {
  3. json_die();
  4. }
  5. $aid = $_GET['aid'];
  6. if ($Cache->get_value('anidb_json_'.$aid)) {
  7. json_die("success", $Cache->get_value('anidb_json_'.$aid));
  8. } else {
  9. $anidb_url = 'http://api.anidb.net:9001/httpapi?request=anime&client='.API_KEYS['ANIDB'].'&clientver=1&protover=1&aid='.$aid;
  10. $crl = curl_init();
  11. curl_setopt($crl, CURLOPT_URL, $anidb_url);
  12. curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
  13. curl_setopt($crl, CURLOPT_CONNEECTTIMEOUT, 5);
  14. $ret = curl_exec($crl);
  15. curl_close($curl);
  16. $anidb_xml = new SimpleXMLElement(zlib_decode($ret));
  17. if ($anidb_xml->xpath('/error')) {
  18. json_die("failure", $anidb_xml->xpath('/error')[0]."");
  19. }
  20. $title = $anidb_xml->xpath('//titles/title[@type = "main"]')[0].'';
  21. $title = (empty($title))?$anidb_xml->xpath('//titles/title[@xml:lang = "en" and @type = "official"]')[0].'':$title;
  22. $title_jp = $anidb_xml->xpath('//titles/title[@xml:lang = "ja" and @type = "official"]')[0].'';
  23. $artist = $anidb_xml->xpath('//creators/name[@type = "Animation Work"]')[0].'';
  24. $year = substr($anidb_xml->startdate, 0, 4);
  25. $desc = preg_replace('/http:\/\/anidb.net\S+ \[(.*?)\]/', '$1', ($anidb_xml->description).'');
  26. $json_str = array(
  27. 'id' => $aid,
  28. 'title' => $title,
  29. 'title_jp' => $title_jp,
  30. 'artist' => $artist,
  31. 'year' => $year,
  32. 'description' => $desc
  33. );
  34. $Cache->cache_value('anidb_json_'.$aid, $json_str, 86400);
  35. json_die("success", $json_str);
  36. }
  37. ?>