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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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("/\(([^()]*+|(?R))*\)/","", $title);
  68. $title = trim(preg_replace("/\[([^\[\]]*+|(?R))*\]/","", $title));
  69. $title_jp = html_entity_decode($json['title_jpn'], ENT_QUOTES);
  70. $title_jp = preg_replace("/\(([^()]*+|(?R))*\)/","", $title_jp);
  71. $title_jp = trim(preg_replace("/\[([^\[\]]*+|(?R))*\]/","", $title_jp));
  72. $json_str = [
  73. 'id' => $gid,
  74. 'title' => $title,
  75. 'title_jp' => $title_jp,
  76. 'artists' => $artists,
  77. 'circle' => $circle,
  78. 'censored' => $censored,
  79. 'year' => NULL,
  80. 'tags' => $tags,
  81. 'lang' => $lang ?? 'Japanese',
  82. 'pages' => $json['filecount'],
  83. 'description' => '',
  84. 'cover' => $cover
  85. ];
  86. $Cache->cache_value('manga_fill_json_'.$gid, $json_str, 86400);
  87. json_die("success", $json_str);
  88. }
  89. ?>