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.

manga.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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('manga_fill_json_'.$gid)) {
  14. json_die("success", $Cache->get_value('manga_fill_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_TIMEOUT, 10);
  20. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  21. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  22. curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: '.strlen($data)]);
  23. $json = curl_exec($curl);
  24. if (empty($json)) {
  25. json_die("failure", "Could not get page");
  26. }
  27. $json = json_decode($json, true)["gmetadata"][0];
  28. $artists = [];
  29. $tags = [];
  30. $lang = NULL;
  31. $circle = NULL;
  32. $censored = true;
  33. foreach ($json["tags"] as $tag) {
  34. if (strpos($tag, ':') !== false) {
  35. list($namespace, $tag) = explode(':', $tag);
  36. } else { $namespace = ''; }
  37. if ($namespace == "artist") {
  38. array_push($artists, ucwords($tag));
  39. } else if ($namespace == "language") {
  40. $lang = empty($lang) ? ucfirst($tag) : $lang;
  41. } else if ($namespace == "group") {
  42. $circle = empty($circle) ? ucfirst($tag) : $circle;
  43. } else if ($tag == "uncensored") {
  44. $censored = false;
  45. } else {
  46. if ($namespace) { $tag = $tag.':'.$namespace; }
  47. array_push($tags, str_replace(' ', '.', $tag));
  48. }
  49. }
  50. // get the cover for ants
  51. $cover = $json['thumb'];
  52. // and let's see if we can replace it with something better
  53. $gallery_page = file_get_contents($url);
  54. $re = '/'.preg_quote('-0px 0 no-repeat"><a href="').'(.*)'.preg_quote('"><img alt="01"').'/';
  55. preg_match($re, $gallery_page, $galmatch);
  56. // were we able to find the first page of the gallery?
  57. if ($galmatch[1]) {
  58. $image_page = file_get_contents($galmatch[1]);
  59. $re = '/'.preg_quote('"><img id="img" src="').'([^<]*)'.preg_quote('" style=').'/';
  60. preg_match($re, $image_page, $imgmatch);
  61. // were we able to find the image url?
  62. if ($imgmatch[1]) {
  63. $cover = $imgmatch[1];
  64. }
  65. }
  66. $title = html_entity_decode($json['title'], ENT_QUOTES);
  67. $title = preg_replace("/^((?: ?\(.*?\) ?| ?\[.*?\] ?)*)?(.*?)((?: ?\(.*?\)| ?\[.*?\]).*)?$/", "$2", $title);
  68. $title = trim(str_replace("’", "'", $title), " ");
  69. $title_rj = "";
  70. $title_jp = html_entity_decode($json['title_jpn'], ENT_QUOTES);
  71. $title_jp = preg_replace("/^((?: ?\(.*?\) ?| ?\[.*?\] ?)*)?(.*?)((?: ?\(.*?\)| ?\[.*?\]).*)?$/", "$2", $title_jp);
  72. $title_jp = trim($titljp, " ");
  73. if(strpos($title, "|") !== false) {
  74. $titles = explode("|", $title);
  75. $title_rj = trim($titles[0], " ");
  76. $title = trim($titles[1], " ");
  77. }
  78. if($title_rj == "" && trim(preg_replace("/xxx|sex|circle|dol|[bghkmnprjcl]{1,2}([auoei]|y[auo])|[sz]{1,2}[auoe]|[dft]{1,2}[aeo]|[vw]{1,2}[ao]|([fv]{1,2}|ts|t)u|(j{1,2}|[cs]h)(i|y[auo])|y{1,2}[auo]|[auoien]|cc|s[ht]|ssh/i", "", str_replace("vol", "", preg_replace("/[^A-Za-z]/", "", strtolower($title))))) == "") {
  79. $title_rj = $title;
  80. $title = "";
  81. }
  82. $json_str = [
  83. 'id' => $gid,
  84. 'title' => $title,
  85. 'title_rj' => $title_rj,
  86. 'title_jp' => $title_jp,
  87. 'artists' => $artists,
  88. 'circle' => $circle,
  89. 'censored' => $censored,
  90. 'year' => NULL,
  91. 'tags' => $tags,
  92. 'lang' => $lang ?? 'Japanese',
  93. 'pages' => $json['filecount'],
  94. 'description' => '',
  95. 'cover' => $cover
  96. ];
  97. $Cache->cache_value('manga_fill_json_'.$gid, $json_str, 86400);
  98. json_die("success", $json_str);
  99. }
  100. ?>