-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConverti.js
37 lines (29 loc) · 938 Bytes
/
Converti.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fs from "fs-extra";
import path from "path";
const ChapterDir = "./Parse";
const OutputDir = "./Output";
const allChapterList = await fs.readdir(ChapterDir);
let counter = 0;
if (await fs.pathExists(OutputDir)) {
await fs.rm(OutputDir, { recursive: true, force: true });
}
await fs.mkdir(OutputDir);
for (const chapterFolder of allChapterList) {
const pageList = await fs.readdir(path.join(ChapterDir, chapterFolder));
console.log("Processing Chapter => " + path.join(ChapterDir, chapterFolder));
for (const page of pageList) {
if (page === ".nomedia") continue;
console.log("Now Moving Page => " + path.join(chapterFolder, page));
const fileBuffer = await fs.readFile(
path.join(ChapterDir, chapterFolder, page)
);
await fs.writeFile(
path.join(
OutputDir,
"page_" + counter.toString().padStart(3, "0") + ".jpg"
),
fileBuffer
);
counter++;
}
}