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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?
  2. if (empty($_GET['url'])) {
  3. json_die();
  4. }
  5. $url = str_replace('exhentai','e-hentai',$_GET['url']);
  6. $matches = [];
  7. preg_match('/^https?:\/\/g?\.?e.hentai\.org\/g\/(\d+)\/([\w\d]+)\/?$/', $url, $matches);
  8. $gid = $matches[1] ?? '';
  9. $token = $matches[2] ?? '';
  10. if (empty($gid) || empty($token)) {
  11. json_die("failure", "Invalid URL");
  12. }
  13. if ($Cache->get_value('doujin_json_'.$gid)) {
  14. json_die("success", $Cache->get_value('doujin_json_'.$gid));
  15. } else {
  16. $data = json_encode(["method" => "gdata", "gidlist" => [[$gid, $token]], "namespace" => 1]);
  17. $curl = curl_init('http://api.e-hentai.org/api.php');
  18. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
  19. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  20. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  21. curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: '.strlen($data)]);
  22. $json = curl_exec($curl);
  23. if (empty($json)) {
  24. json_die("failure", "Could not get page");
  25. }
  26. $json = json_decode($json, true)["gmetadata"][0];
  27. $artists = [];
  28. $tags = [];
  29. $lang = NULL;
  30. $circle = NULL;
  31. $censored = true;
  32. foreach ($json["tags"] as $tag) {
  33. if (strpos($tag, ':') !== false) {
  34. list($namespace, $tag) = explode(':', $tag);
  35. } else { $namespace = ''; }
  36. if ($namespace == "artist") {
  37. array_push($artists, ucwords($tag));
  38. } else if ($namespace == "language") {
  39. $lang = empty($lang) ? ucfirst($tag) : $lang;
  40. } else if ($namespace == "group") {
  41. $circle = empty($circle) ? ucfirst($tag) : $circle;
  42. } else if ($tag == "uncensored") {
  43. $censored = false;
  44. } else {
  45. if ($namespace) { $tag = $tag.':'.$namespace; }
  46. array_push($tags, str_replace(' ', '.', $tag));
  47. }
  48. }
  49. // get the cover for ants
  50. $cover = $json['thumb'];
  51. // and let's see if we can replace it with something better
  52. $gallery_page = file_get_contents($url);
  53. $re = '/'.preg_quote('-0px 0 no-repeat"><a href="').'(.*)'.preg_quote('"><img alt="01"').'/';
  54. preg_match($re, $gallery_page, $galmatch);
  55. // were we able to find the first page of the gallery?
  56. if ($galmatch[1]) {
  57. $image_page = file_get_contents($galmatch[1]);
  58. $re = '/'.preg_quote('"><img id="img" src="').'([^<]*)'.preg_quote('" style=').'/';
  59. preg_match($re, $image_page, $imgmatch);
  60. // were we able to find the image url?
  61. if ($imgmatch[1]) {
  62. $cover = $imgmatch[1];
  63. }
  64. }
  65. $json_str = array(
  66. 'id' => $gid,
  67. 'title' => html_entity_decode($json['title'], ENT_QUOTES),
  68. 'title_jp' => html_entity_decode($json['title_jpn'], ENT_QUOTES),
  69. 'artists' => $artists,
  70. 'circle' => $circle,
  71. 'censored' => $censored,
  72. 'year' => NULL,
  73. 'tags' => $tags,
  74. 'lang' => $lang,
  75. 'pages' => $json['filecount'],
  76. 'description' => '',
  77. 'cover' => $cover
  78. );
  79. $Cache->cache_value('doujin_json_'.$gid, $json_str, 86400);
  80. json_die("success", $json_str);
  81. }
  82. ?>