BioTorrents.de’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.4KB

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