Closure-RI commited on
Commit
f932d3b
·
verified ·
1 Parent(s): 7e16c92

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +30 -4
index.js CHANGED
@@ -524,14 +524,28 @@ async function nhentai(url) {
524
  const jsonString = scriptContent.match(/JSON\.parse\("(.*)"\)/)[1];
525
  const decodedString = jsonString.replace(/\\u0022/g, '"').replace(/\\u005C/g, '\\');
526
  const jsonData = JSON.parse(decodedString);
 
527
  console.log(jsonData);
528
 
529
  const imgList = jsonData.images.pages.map((_, index) => ({
530
- path: `https://i5.nhentai.net/galleries/${jsonData.media_id}/${index + 1}.${jsonData.images.pages[index].t === "w" ? "webp" : jsonData.images.pages[index].t === "p" ? "png" : "jpg"}`
531
- }));
532
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
533
 
534
- const imagePaths = await downloadImageNhs(imgList, tempDir, instanceID);
535
  const pdfPath = await createPDF(imagePaths, instanceID, tempDir);
536
 
537
  console.log(`PDF berhasil dibuat: ${pdfPath}`);
@@ -548,6 +562,18 @@ async function nhentai(url) {
548
  }
549
  }
550
 
 
 
 
 
 
 
 
 
 
 
 
 
551
  async function downloadImageNh(image, tempDir, instanceID) {
552
  const servers = [
553
  "https://i1.nhentai.net",
 
524
  const jsonString = scriptContent.match(/JSON\.parse\("(.*)"\)/)[1];
525
  const decodedString = jsonString.replace(/\\u0022/g, '"').replace(/\\u005C/g, '\\');
526
  const jsonData = JSON.parse(decodedString);
527
+
528
  console.log(jsonData);
529
 
530
  const imgList = jsonData.images.pages.map((_, index) => ({
531
+ path: `https://i5.nhentai.net/galleries/${jsonData.media_id}/${index + 1}.${jsonData.images.pages[index].t === "w" ? "webp" : jsonData.images.pages[index].t === "p" ? "png" : "jpg"}`
532
+ }));
533
+
534
+ const imagePaths = [];
535
+ for (const img of imgList) {
536
+ const downloadedImagePath = await downloadImageNh(img, tempDir, instanceID);
537
+ const isWebp = path.extname(downloadedImagePath).toLowerCase() === '.webp';
538
+
539
+ if (isWebp) {
540
+ const convertedImagePath = downloadedImagePath.replace('.webp', '.jpg');
541
+ await convertImage(downloadedImagePath, convertedImagePath);
542
+ fs.unlinkSync(downloadedImagePath); // Hapus file asli (.webp)
543
+ imagePaths.push(convertedImagePath);
544
+ } else {
545
+ imagePaths.push(downloadedImagePath);
546
+ }
547
+ }
548
 
 
549
  const pdfPath = await createPDF(imagePaths, instanceID, tempDir);
550
 
551
  console.log(`PDF berhasil dibuat: ${pdfPath}`);
 
562
  }
563
  }
564
 
565
+
566
+ async function convertImage(inputPath, outputPath) {
567
+ try {
568
+ await execAsync(`ffmpeg -i "${inputPath}" -q:v 1 "${outputPath}"`);
569
+ console.log(`Converted ${inputPath} to ${outputPath}`);
570
+ } catch (error) {
571
+ console.error(`Error converting image: ${error.message}`);
572
+ throw new Error(`Failed to convert image ${inputPath} to JPG.`);
573
+ }
574
+ }
575
+
576
+
577
  async function downloadImageNh(image, tempDir, instanceID) {
578
  const servers = [
579
  "https://i1.nhentai.net",