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.

anime.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?
  2. if (empty($_GET['aid'])) {
  3. json_die();
  4. }
  5. $aid = $_GET['aid'];
  6. if ($Cache->get_value('anime_fill_json_'.$aid)) {
  7. json_die("success", $Cache->get_value('anime_fill_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[@xml:lang = "en" and @type = "official"]')[0].'';
  21. $title = (empty($title))?$anidb_xml->xpath('//titles/title[@xml:lang = "en"]')[0].'':$title;
  22. $title = (empty($title))?$anidb_xml->xpath('//titles/title[@type = "main"]')[0].'':$title;
  23. $title_rj = $anidb_xml->xpath('//titles/title[@xml:lang = "x-jat" and @type = "official"]')[0].'';
  24. $title_rj = (empty($title_rj))?$anidb_xml->xpath('//titles/title[@xml:lang = "x-jat"]')[0].'':$title_rj;
  25. $title_jp = $anidb_xml->xpath('//titles/title[@xml:lang = "ja" and @type = "official"]')[0].'';
  26. $title_jp = (empty($title_jp))?$anidb_xml->xpath('//titles/title[@xml:lang = "ja"]')[0].'':$title_jp;
  27. $artist = $anidb_xml->xpath('//creators/name[@type = "Animation Work"]')[0].'';
  28. $year = substr($anidb_xml->startdate, 0, 4);
  29. $desc = preg_replace('/http:\/\/anidb.net\S+ \[(.*?)\]/', '$1', ($anidb_xml->description).'');
  30. $json_str = array(
  31. 'id' => $aid,
  32. 'title' => $title,
  33. 'title_rj' => $title_rj,
  34. 'title_jp' => $title_jp,
  35. 'artist' => $artist,
  36. 'year' => $year,
  37. 'description' => $desc
  38. );
  39. $Cache->cache_value('anime_fill_json_'.$aid, $json_str, 86400);
  40. json_die("success", $json_str);
  41. }
  42. ?>