Files

65 lines
2.0 KiB
JavaScript

const https = require('https');
async function postJson(url, data) {
return new Promise((resolve, reject) => {
const body = JSON.stringify(data);
const req = https.request(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body)
}
}, (res) => {
let resData = '';
res.on('data', chunk => resData += chunk);
res.on('end', () => resolve(JSON.parse(resData)));
});
req.on('error', reject);
req.write(body);
req.end();
});
}
async function run() {
const gid = 4159771;
const token = "95d2fa13bd";
// 1. Get gdata
const gdataRes = await postJson("https://api.e-hentai.org/api.php", {
method: "gdata",
gidlist: [[gid, token]],
namespace: 1
});
console.log("Gallery Title:", gdataRes.gmetadata[0].title);
console.log("File Count:", gdataRes.gmetadata[0].filecount);
// 2. Fetch page 1 html to get showkey and first image
const htmlRes = await new Promise((resolve, reject) => {
https.get("https://e-hentai.org/s/b9679c8353/4159771-1", {
headers: { 'User-Agent': 'Mozilla/5.0' }
}, (res) => {
let data = '';
res.on('data', c => data += c);
res.on('end', () => resolve(data));
}).on('error', reject);
});
const showkeyMatch = htmlRes.match(/var showkey="([^"]+)";/);
const showkey = showkeyMatch ? showkeyMatch[1] : null;
console.log("Showkey:", showkey);
// 3. Test showpage API for page 2, 3, 4
const p2Res = await postJson("https://api.e-hentai.org/api.php", {
method: "showpage",
gid: gid,
page: 2,
imgkey: "d433c8c0f0",
showkey: showkey
});
const imgMatch = p2Res.i3.match(/<img id="img" src="([^"]+)"/);
console.log("Page 2 Image URL:", imgMatch ? imgMatch[1] : "not found");
}
run().catch(console.error);