1 const fs = require("fs")
2 const download = require("download")
3 const cliProgress = require("cli-progress")
4 const unzipper = require("unzipper")
5 const pdfkit = require("pdfkit")
7 const url = "http://images.mangafreak.net/downloads/Horimiya_"
10 const bar = new cliProgress.SingleBar({}, cliProgress.Presets.legacy)
11 bar.start(chapters, 0, {speed: "N/A"})
13 const doc = new pdfkit({autoFirstPage: false})
14 doc.pipe(fs.createWriteStream("Horimiya.pdf"))
16 fs.promises.rm("pages", {recursive: true, force: true})
17 .then(_ => fs.promises.mkdir("pages"))
18 .then(_ => Promise.all(new Array(chapters)
21 .map(n => download(url + n)
22 .pipe(unzipper.Extract({path: "pages"}))
24 .then(_ => bar.increment())
27 .then(_ => bar.stop())
28 .then(_ => fs.promises.readdir("pages"))
30 .sort(new Intl.Collator(undefined, {numeric: true}).compare)
31 .map(file => "pages/" + file)
32 .map(file => doc.openImage(file))
33 .forEach(img => doc.addPage({size: [img.width, img.height]}).image(img, 0, 0))