|
@@ -7,64 +7,70 @@ if (empty($_GET['url'])) {
|
7
|
7
|
$url = $_GET['url'];
|
8
|
8
|
|
9
|
9
|
$matches = array();
|
10
|
|
-preg_match('/^https?:\/\/nhentai.net\/g\/(\d+)\/?$/', $url, $matches);
|
|
10
|
+preg_match('/^https?:\/\/g\.e.hentai\.org\/g\/(\d+)\/([\w\d]+)\/?$/', $url, $matches);
|
11
|
11
|
|
12
|
|
-$id = (isset($matches[1])) ? $matches[1] : '';
|
|
12
|
+$gid = $matches[1] ?? '';
|
|
13
|
+$token = $matches[2] ?? '';
|
13
|
14
|
|
14
|
|
-if (empty($id)) {
|
|
15
|
+if (empty($gid) || empty($token)) {
|
15
|
16
|
json_die("failure", "Invalid URL");
|
16
|
17
|
}
|
17
|
18
|
|
18
|
|
-if ($Cache->get_value('doujin_json_'.$id)) {
|
19
|
|
- json_die("success", $Cache->get_value('doujin_json_'.$id));
|
|
19
|
+if ($Cache->get_value('doujin_json_'.$gid) && false) {
|
|
20
|
+ json_die("success", $Cache->get_value('doujin_json_'.$gid));
|
20
|
21
|
} else {
|
21
|
22
|
|
22
|
|
- $url = 'http://nhentai.net/g/' . $id . '/json';
|
|
23
|
+ $data = json_encode(["method" => "gdata", "gidlist" => [[$gid, $token]], "namespace" => 1]);
|
|
24
|
+ $curl = curl_init('http://g.e-hentai.org/api.php');
|
|
25
|
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
|
26
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
27
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
28
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: '.strlen($data)]);
|
23
|
29
|
|
24
|
|
- $json = file_get_contents($url);
|
|
30
|
+ $json = curl_exec($curl);
|
25
|
31
|
|
26
|
32
|
if (empty($json)) {
|
27
|
33
|
json_die("failure", "Could not get page");
|
28
|
34
|
}
|
29
|
35
|
|
30
|
|
- $json = json_decode($json, true);
|
|
36
|
+ $json = json_decode($json, true)["gmetadata"][0];
|
31
|
37
|
|
32
|
38
|
$artists = array();
|
33
|
39
|
$tags = array();
|
34
|
40
|
$lang = NULL;
|
|
41
|
+ $circle = NULL;
|
35
|
42
|
foreach ($json["tags"] as $tag) {
|
36
|
|
- if ($tag[1] == "artist")
|
37
|
|
- array_push($artists, ucwords($tag[2]));
|
38
|
|
- elseif ($tag[1] == "tag")
|
39
|
|
- array_push($tags, str_replace(' ', '.', $tag[2]));
|
40
|
|
- elseif ($tag[1] == "language")
|
41
|
|
- $lang = ucfirst($tag[2]);
|
|
43
|
+ if (strpos($tag, ':') !== false) {
|
|
44
|
+ list($namespace, $tag) = explode(':', $tag);
|
|
45
|
+ } else { $namespace = ''; }
|
|
46
|
+
|
|
47
|
+ if ($namespace == "artist") {
|
|
48
|
+ array_push($artists, ucwords($tag));
|
|
49
|
+ } else if ($namespace == "language" && empty($lang)) {
|
|
50
|
+ $lang = ucfirst($tag);
|
|
51
|
+ } else if ($namespace == "group" && empty($circle)) {
|
|
52
|
+ $circle = ucfirst($tag);
|
|
53
|
+ } else {
|
|
54
|
+ if ($namespace) { $tag = $tag.':'.$namespace; }
|
|
55
|
+ array_push($tags, str_replace(' ', '.', $tag));
|
|
56
|
+ }
|
42
|
57
|
}
|
43
|
58
|
|
44
|
|
- switch($json['images']['cover']['t']) {
|
45
|
|
- case 'j':
|
46
|
|
- $covertype = "jpg";
|
47
|
|
- break;
|
48
|
|
- case 'p':
|
49
|
|
- $covertype = "png";
|
50
|
|
- break;
|
51
|
|
- }
|
52
|
|
- $cover = 'http://i.nhentai.net/galleries/'.$json['media_id'].'/1.'.$covertype;
|
53
|
|
-
|
54
|
59
|
$json_str = array(
|
55
|
|
- 'id' => $id,
|
56
|
|
- 'title' => $json['title']['english'],
|
57
|
|
- 'title_jp' => $json['title']['japanese'],
|
|
60
|
+ 'id' => $gid,
|
|
61
|
+ 'title' => $json['title'],
|
|
62
|
+ 'title_jp' => $json['title_jpn'],
|
58
|
63
|
'artists' => $artists,
|
|
64
|
+ 'circle' => $circle,
|
59
|
65
|
'year' => NULL,
|
60
|
66
|
'tags' => $tags,
|
61
|
67
|
'lang' => $lang,
|
62
|
|
- 'pages' => $json['num_pages'],
|
|
68
|
+ 'pages' => $json['filecount'],
|
63
|
69
|
'description' => '',
|
64
|
|
- 'cover' => $cover
|
|
70
|
+ 'cover' => $json['thumb']
|
65
|
71
|
);
|
66
|
72
|
|
67
|
|
- $Cache->cache_value('doujin_json_'.$id, $json_str, 86400);
|
|
73
|
+ $Cache->cache_value('doujin_json_'.$gid, $json_str, 86400);
|
68
|
74
|
|
69
|
75
|
json_die("success", $json_str);
|
70
|
76
|
}
|