Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -279,14 +279,34 @@ async function downloadFromUrl(url, filePath) {
|
|
| 279 |
});
|
| 280 |
}
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
async function Rules34(url_r34) {
|
| 283 |
try {
|
| 284 |
const browser = await puppeteer.launch();
|
| 285 |
const page = await browser.newPage();
|
| 286 |
|
| 287 |
await page.setExtraHTTPHeaders({
|
| 288 |
-
'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',
|
| 289 |
-
'Referer': url_r34
|
|
|
|
| 290 |
});
|
| 291 |
await page.goto(url_r34, { referer: url_r34 });
|
| 292 |
|
|
@@ -324,14 +344,11 @@ async function Rules34(url_r34) {
|
|
| 324 |
|
| 325 |
// Mendownload dari URL terakhir di array download
|
| 326 |
const lastDownloadUrl = result.download[result.download.length - 1].url;
|
| 327 |
-
const downloadPath = path.resolve(os.tmpdir())
|
| 328 |
-
let filenem = `${Date.now()}_file.mp4`
|
| 329 |
-
const filePath = path.join(downloadPath, filenem)
|
| 330 |
|
| 331 |
-
await downloadFromUrl(lastDownloadUrl,
|
| 332 |
|
| 333 |
-
result.downloadPath =
|
| 334 |
-
result.downloadUrl = "https://arashicode-komik.hf.space/static/" + filenem; // Menambahkan path file yang telah di-download ke dalam objek result
|
| 335 |
}
|
| 336 |
|
| 337 |
if (videoInfo.length > 0) {
|
|
@@ -362,25 +379,105 @@ async function Rules34(url_r34) {
|
|
| 362 |
}
|
| 363 |
}
|
| 364 |
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
const { url } = req.query;
|
| 367 |
if (!url) {
|
| 368 |
return res.status(400).send('URL is required');
|
| 369 |
}
|
| 370 |
try {
|
| 371 |
-
const result = await
|
| 372 |
res.json(result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
const filePath = result.downloadPath;
|
| 374 |
-
|
| 375 |
-
setTimeout(() => {
|
| 376 |
-
fs.unlink(filePath, (err) => {
|
| 377 |
if (err) {
|
| 378 |
-
|
|
|
|
| 379 |
} else {
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
}
|
| 382 |
-
|
| 383 |
-
}, 480000);
|
| 384 |
} catch (error) {
|
| 385 |
res.status(500).send('Error processing request');
|
| 386 |
}
|
|
|
|
| 279 |
});
|
| 280 |
}
|
| 281 |
|
| 282 |
+
|
| 283 |
+
// Fungsi untuk mendownload dari URL
|
| 284 |
+
async function downloadFromUrl(url, filePath) {
|
| 285 |
+
const writer = fs.createWriteStream(filePath);
|
| 286 |
+
|
| 287 |
+
const response = await axios({
|
| 288 |
+
url,
|
| 289 |
+
method: 'GET',
|
| 290 |
+
responseType: 'stream'
|
| 291 |
+
});
|
| 292 |
+
|
| 293 |
+
response.data.pipe(writer);
|
| 294 |
+
|
| 295 |
+
return new Promise((resolve, reject) => {
|
| 296 |
+
writer.on('finish', resolve);
|
| 297 |
+
writer.on('error', reject);
|
| 298 |
+
});
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
async function Rules34(url_r34) {
|
| 302 |
try {
|
| 303 |
const browser = await puppeteer.launch();
|
| 304 |
const page = await browser.newPage();
|
| 305 |
|
| 306 |
await page.setExtraHTTPHeaders({
|
| 307 |
+
'User-Agent': getRandomUserAgent() || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
| 308 |
+
'Referer': url_r34,
|
| 309 |
+
'X-Forwarded-For': generateRandomIP()
|
| 310 |
});
|
| 311 |
await page.goto(url_r34, { referer: url_r34 });
|
| 312 |
|
|
|
|
| 344 |
|
| 345 |
// Mendownload dari URL terakhir di array download
|
| 346 |
const lastDownloadUrl = result.download[result.download.length - 1].url;
|
| 347 |
+
const downloadPath = path.resolve(os.tmpdir(), `${Date.now()}_file.mp4`);
|
|
|
|
|
|
|
| 348 |
|
| 349 |
+
await downloadFromUrl(lastDownloadUrl, downloadPath);
|
| 350 |
|
| 351 |
+
result.downloadPath = downloadPath; // Menyimpan path file yang telah di-download ke dalam objek result
|
|
|
|
| 352 |
}
|
| 353 |
|
| 354 |
if (videoInfo.length > 0) {
|
|
|
|
| 379 |
}
|
| 380 |
}
|
| 381 |
|
| 382 |
+
async function Rules34info(url_r34) {
|
| 383 |
+
try {
|
| 384 |
+
// Mengambil halaman HTML dengan Axios
|
| 385 |
+
const response = await axios.get(url_r34, {
|
| 386 |
+
headers: {
|
| 387 |
+
'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',
|
| 388 |
+
'Referer': url_r34
|
| 389 |
+
}
|
| 390 |
+
});
|
| 391 |
+
|
| 392 |
+
const htmlContent = response.data;
|
| 393 |
+
const $ = cheerio.load(htmlContent);
|
| 394 |
+
|
| 395 |
+
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];
|
| 396 |
+
|
| 397 |
+
const infoElements = $("#tab_video_info > div");
|
| 398 |
+
const result = {
|
| 399 |
+
title: title,
|
| 400 |
+
artist: [],
|
| 401 |
+
uploader: [],
|
| 402 |
+
tags: [],
|
| 403 |
+
category: []
|
| 404 |
+
};
|
| 405 |
+
|
| 406 |
+
if (infoElements.length > 0) {
|
| 407 |
+
const tags = infoElements.eq(infoElements.length - 2);
|
| 408 |
+
const videoInfo = infoElements.eq(infoElements.length - 3);
|
| 409 |
+
|
| 410 |
+
if (tags.length > 0) {
|
| 411 |
+
tags.find("div.wrap > a").each((index, element) => {
|
| 412 |
+
result.tags.push({ title: $(element).text().trim(), url: $(element).attr('href') });
|
| 413 |
+
});
|
| 414 |
+
result.tags.pop(); // Menghapus elemen terakhir dari tags
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
if (videoInfo.length > 0) {
|
| 418 |
+
videoInfo.find("div.cols > div").each((index, col) => {
|
| 419 |
+
const categoryLinks = $(col).find("div.col:nth-child(1) > a");
|
| 420 |
+
categoryLinks.each((index, link) => {
|
| 421 |
+
result.category.push({ title: $(link).text().trim(), url: $(link).attr('href') });
|
| 422 |
+
});
|
| 423 |
+
|
| 424 |
+
const artistLinks = $(col).find("div.col:nth-child(2) > a");
|
| 425 |
+
artistLinks.each((index, link) => {
|
| 426 |
+
result.artist.push({ title: $(link).text().trim(), url: $(link).attr('href') });
|
| 427 |
+
});
|
| 428 |
+
|
| 429 |
+
const uploaderLinks = $(col).find("div.col:nth-child(3) > a");
|
| 430 |
+
uploaderLinks.each((index, link) => {
|
| 431 |
+
result.uploader.push({ title: $(link).text().trim(), url: $(link).attr('href') });
|
| 432 |
+
});
|
| 433 |
+
});
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
return result;
|
| 438 |
+
} catch (error) {
|
| 439 |
+
console.error('Error fetching data:', error);
|
| 440 |
+
throw error; // Rethrow error to handle it upstream
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
// Endpoint untuk info
|
| 445 |
+
app.get('/r34/info', async (req, res) => {
|
| 446 |
const { url } = req.query;
|
| 447 |
if (!url) {
|
| 448 |
return res.status(400).send('URL is required');
|
| 449 |
}
|
| 450 |
try {
|
| 451 |
+
const result = await Rules34info(url);
|
| 452 |
res.json(result);
|
| 453 |
+
} catch (error) {
|
| 454 |
+
res.status(500).send('Error processing request');
|
| 455 |
+
}
|
| 456 |
+
});
|
| 457 |
+
|
| 458 |
+
// Endpoint untuk download
|
| 459 |
+
app.get('/r34/download', async (req, res) => {
|
| 460 |
+
const { url } = req.query;
|
| 461 |
+
if (!url) {
|
| 462 |
+
return res.status(400).send('URL is required');
|
| 463 |
+
}
|
| 464 |
+
try {
|
| 465 |
+
const result = await Rules34(url);
|
| 466 |
const filePath = result.downloadPath;
|
| 467 |
+
res.download(filePath, (err) => {
|
|
|
|
|
|
|
| 468 |
if (err) {
|
| 469 |
+
console.error('Gagal mengirim file:', err);
|
| 470 |
+
res.status(500).send('Gagal mengirim file: \n' + err);
|
| 471 |
} else {
|
| 472 |
+
fs.unlink(filePath, (err) => {
|
| 473 |
+
if (err) {
|
| 474 |
+
console.error(`Error deleting file: ${err.message}`);
|
| 475 |
+
} else {
|
| 476 |
+
console.log(`File deleted: ${filePath}`);
|
| 477 |
+
}
|
| 478 |
+
});
|
| 479 |
}
|
| 480 |
+
});
|
|
|
|
| 481 |
} catch (error) {
|
| 482 |
res.status(500).send('Error processing request');
|
| 483 |
}
|