Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -252,65 +252,104 @@ app.get('/nhentai', async (req, res) => {
|
|
| 252 |
});
|
| 253 |
|
| 254 |
|
| 255 |
-
async function
|
| 256 |
-
const
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
| 259 |
});
|
| 260 |
-
const page = await browser.newPage();
|
| 261 |
-
const downloadPath = path.resolve(os.tmpdir());
|
| 262 |
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
'
|
|
|
|
| 267 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
-
await page.goto(url, { waitUntil: 'networkidle0' });
|
| 270 |
-
|
| 271 |
-
const downloadLink = await page.evaluate(() => {
|
| 272 |
-
const infoElements = document.querySelectorAll("#tab_video_info > div");
|
| 273 |
if (infoElements.length > 0) {
|
| 274 |
-
const
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
}
|
| 279 |
-
}
|
| 280 |
-
return null;
|
| 281 |
-
});
|
| 282 |
-
|
| 283 |
-
let filePath = null;
|
| 284 |
-
let title;
|
| 285 |
-
|
| 286 |
-
if (downloadLink) {
|
| 287 |
-
const response = await axios({
|
| 288 |
-
method: 'GET',
|
| 289 |
-
url: downloadLink,
|
| 290 |
-
responseType: 'stream'
|
| 291 |
-
});
|
| 292 |
-
title = url.match(/video\/(\d+)\/([a-zA-Z0-9-]+)\//)[2];
|
| 293 |
-
|
| 294 |
-
filePath = path.join(downloadPath, `/${title}.mp4`);
|
| 295 |
-
const writer = fs.createWriteStream(filePath);
|
| 296 |
-
|
| 297 |
-
response.data.pipe(writer);
|
| 298 |
-
|
| 299 |
-
await new Promise((resolve, reject) => {
|
| 300 |
-
writer.on('finish', resolve);
|
| 301 |
-
writer.on('error', reject);
|
| 302 |
-
});
|
| 303 |
-
|
| 304 |
-
} else {
|
| 305 |
-
console.error('Download link not found.');
|
| 306 |
-
}
|
| 307 |
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
|
| 316 |
app.get('/r34', async (req, res) => {
|
|
@@ -319,7 +358,7 @@ app.get('/r34', async (req, res) => {
|
|
| 319 |
return res.status(400).send('URL is required');
|
| 320 |
}
|
| 321 |
try {
|
| 322 |
-
const result = await
|
| 323 |
res.json(result);
|
| 324 |
} catch (error) {
|
| 325 |
res.status(500).send('Error processing request');
|
|
|
|
| 252 |
});
|
| 253 |
|
| 254 |
|
| 255 |
+
async function downloadFromUrl(url, filePath) {
|
| 256 |
+
const writer = fs.createWriteStream(filePath);
|
| 257 |
+
|
| 258 |
+
const response = await axios({
|
| 259 |
+
url,
|
| 260 |
+
method: 'GET',
|
| 261 |
+
responseType: 'stream'
|
| 262 |
});
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
response.data.pipe(writer);
|
| 265 |
+
|
| 266 |
+
return new Promise((resolve, reject) => {
|
| 267 |
+
writer.on('finish', resolve);
|
| 268 |
+
writer.on('error', reject);
|
| 269 |
});
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
async function Rules34(url_r34) {
|
| 273 |
+
try {
|
| 274 |
+
const browser = await puppeteer.launch();
|
| 275 |
+
const page = await browser.newPage();
|
| 276 |
+
|
| 277 |
+
await page.setExtraHTTPHeaders({
|
| 278 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
| 279 |
+
'Referer': url_r34
|
| 280 |
+
});
|
| 281 |
+
await page.goto(url_r34, { referer: url_r34 });
|
| 282 |
+
|
| 283 |
+
const htmlContent = await page.content();
|
| 284 |
+
const $ = cheerio.load(htmlContent);
|
| 285 |
+
|
| 286 |
+
const title = $("body > div > div.wrapper > div.main > div.container > div > div > div:nth-child(1) > div.heading > h1").text().trim() || url_r34.match(/\/video\/\d+\/(.*)\//)?.[1];
|
| 287 |
+
|
| 288 |
+
const infoElements = $("#tab_video_info > div");
|
| 289 |
+
const result = {
|
| 290 |
+
title: title,
|
| 291 |
+
artist: [],
|
| 292 |
+
uploader: [],
|
| 293 |
+
tags: [],
|
| 294 |
+
download: [],
|
| 295 |
+
category: []
|
| 296 |
+
};
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
if (infoElements.length > 0) {
|
| 299 |
+
const tags = infoElements.eq(infoElements.length - 2);
|
| 300 |
+
const download = infoElements.eq(infoElements.length - 1);
|
| 301 |
+
const videoInfo = infoElements.eq(infoElements.length - 3);
|
| 302 |
+
|
| 303 |
+
if (tags.length > 0) {
|
| 304 |
+
tags.find("div.wrap > a").each((index, element) => {
|
| 305 |
+
result.tags.push({ title: $(element).text().trim(), url: $(element).attr('href') });
|
| 306 |
+
});
|
| 307 |
+
result.tags.pop(); // Menghapus elemen terakhir dari tags
|
| 308 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
+
if (download.length > 0) {
|
| 311 |
+
download.find("div.wrap > a").each((index, element) => {
|
| 312 |
+
result.download.push({ quality: $(element).text().trim(), url: $(element).attr('href') });
|
| 313 |
+
});
|
| 314 |
+
|
| 315 |
+
// Mendownload dari URL terakhir di array download
|
| 316 |
+
const lastDownloadUrl = result.download[result.download.length - 1].url;
|
| 317 |
+
const downloadPath = path.resolve(os.tmpdir())
|
| 318 |
+
let filenem = `/${Date.now()}_file.mp4`
|
| 319 |
+
const filePath = path.join(downloadPath, filenem)
|
| 320 |
+
|
| 321 |
+
await downloadFromUrl(lastDownloadUrl, filePath);
|
| 322 |
|
| 323 |
+
result.downloadPath = filePath; // Menambahkan path file yang telah di-download ke dalam objek result
|
| 324 |
+
result.downloadUrl = "https://arashicode-komik.hf.space/static/" + filenem; // Menambahkan path file yang telah di-download ke dalam objek result
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
if (videoInfo.length > 0) {
|
| 328 |
+
videoInfo.find("div.cols > div").each((index, col) => {
|
| 329 |
+
const categoryLinks = $(col).find("div.col:nth-child(1) > a");
|
| 330 |
+
categoryLinks.each((index, link) => {
|
| 331 |
+
result.category.push({ title: $(link).text().trim(), url: $(link).attr('href') });
|
| 332 |
+
});
|
| 333 |
+
|
| 334 |
+
const artistLinks = $(col).find("div.col:nth-child(2) > a");
|
| 335 |
+
artistLinks.each((index, link) => {
|
| 336 |
+
result.artist.push({ title: $(link).text().trim(), url: $(link).attr('href') });
|
| 337 |
+
});
|
| 338 |
+
|
| 339 |
+
const uploaderLinks = $(col).find("div.col:nth-child(3) > a");
|
| 340 |
+
uploaderLinks.each((index, link) => {
|
| 341 |
+
result.uploader.push({ title: $(link).text().trim(), url: $(link).attr('href') });
|
| 342 |
+
});
|
| 343 |
+
});
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
await browser.close();
|
| 348 |
+
return result;
|
| 349 |
+
} catch (error) {
|
| 350 |
+
console.error('Error fetching data:', error);
|
| 351 |
+
throw error; // Rethrow error to handle it upstream
|
| 352 |
+
}
|
| 353 |
}
|
| 354 |
|
| 355 |
app.get('/r34', async (req, res) => {
|
|
|
|
| 358 |
return res.status(400).send('URL is required');
|
| 359 |
}
|
| 360 |
try {
|
| 361 |
+
const result = await Rules34(url);
|
| 362 |
res.json(result);
|
| 363 |
} catch (error) {
|
| 364 |
res.status(500).send('Error processing request');
|