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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?
  2. if (empty($_GET['url'])) {
  3. json_die();
  4. }
  5. $url = $_GET['url'];
  6. $matches = array();
  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) && false) {
  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://g.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 = array();
  28. $tags = array();
  29. $lang = NULL;
  30. $circle = NULL;
  31. foreach ($json["tags"] as $tag) {
  32. if (strpos($tag, ':') !== false) {
  33. list($namespace, $tag) = explode(':', $tag);
  34. } else { $namespace = ''; }
  35. if ($namespace == "artist") {
  36. array_push($artists, ucwords($tag));
  37. } else if ($namespace == "language") {
  38. $lang = empty($lang) ? ucfirst($tag) : $lang;
  39. } else if ($namespace == "group") {
  40. $circle = empty($circle) ? ucfirst($tag) : $circle;
  41. } else {
  42. if ($namespace) { $tag = $tag.':'.$namespace; }
  43. array_push($tags, str_replace(' ', '.', $tag));
  44. }
  45. }
  46. $json_str = array(
  47. 'id' => $gid,
  48. 'title' => $json['title'],
  49. 'title_jp' => $json['title_jpn'],
  50. 'artists' => $artists,
  51. 'circle' => $circle,
  52. 'year' => NULL,
  53. 'tags' => $tags,
  54. 'lang' => $lang,
  55. 'pages' => $json['filecount'],
  56. 'description' => '',
  57. 'cover' => $json['thumb']
  58. );
  59. $Cache->cache_value('doujin_json_'.$gid, $json_str, 86400);
  60. json_die("success", $json_str);
  61. }
  62. ?>