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.

doujin.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?
  2. if (empty($_GET['url'])) {
  3. json_die();
  4. }
  5. $url = $_GET['url'];
  6. $matches = array();
  7. preg_match('/^https?:\/\/nhentai.net\/g\/(\d+)\/?$/', $url, $matches);
  8. $id = (isset($matches[1])) ? $matches[1] : '';
  9. if (empty($id)) {
  10. json_die("failure", "Invalid URL");
  11. }
  12. if ($Cache->get_value('doujin_json_'.$id)) {
  13. json_die("success", $Cache->get_value('doujin_json_'.$id));
  14. } else {
  15. $url = 'http://nhentai.net/g/' . $id . '/json';
  16. $json = file_get_contents($url);
  17. if (empty($json)) {
  18. json_die("failure", "Could not get page");
  19. }
  20. $json = json_decode($json, true);
  21. $artists = array();
  22. $tags = array();
  23. $lang = NULL;
  24. foreach ($json["tags"] as $tag) {
  25. if ($tag[1] == "artist")
  26. array_push($artists, ucwords($tag[2]));
  27. elseif ($tag[1] == "tag")
  28. array_push($tags, str_replace(' ', '.', $tag[2]));
  29. elseif ($tag[1] == "language")
  30. $lang = ucfirst($tag[2]);
  31. }
  32. switch($json['images']['cover']['t']) {
  33. case 'j':
  34. $covertype = "jpg";
  35. break;
  36. case 'p':
  37. $covertype = "png";
  38. break;
  39. }
  40. $cover = 'http://i.nhentai.net/galleries/'.$json['media_id'].'/1.'.$covertype;
  41. $json_str = array(
  42. 'id' => $id,
  43. 'title' => $json['title']['english'],
  44. 'title_jp' => $json['title']['japanese'],
  45. 'artists' => $artists,
  46. 'year' => NULL,
  47. 'tags' => $tags,
  48. 'lang' => $lang,
  49. 'pages' => $json['num_pages'],
  50. 'description' => '',
  51. 'cover' => $cover
  52. );
  53. $Cache->cache_value('doujin_json_'.$id, $json_str, 86400);
  54. json_die("success", $json_str);
  55. }
  56. ?>