]> git.lizzy.rs Git - horimiya-dl.git/blob - init.js
Style fixes
[horimiya-dl.git] / init.js
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")
6
7 const url = "http://images.mangafreak.net/downloads/Horimiya_"
8 const chapters = 124
9
10 const bar = new cliProgress.SingleBar({}, cliProgress.Presets.legacy)
11 bar.start(chapters, 0, {speed: "N/A"})
12
13 const doc = new pdfkit({autoFirstPage: false})
14 doc.pipe(fs.createWriteStream("Horimiya.pdf"))
15
16 fs.promises.rm("pages", {recursive: true, force: true})
17         .then(_ => fs.promises.mkdir("pages"))
18         .then(_ => Promise.all(new Array(chapters)
19                 .fill(null)
20                 .map((_, i) => i + 1)
21                 .map(n => download(url + n)
22                         .pipe(unzipper.Extract({path: "pages"}))
23                         .promise()
24                         .then(_ => bar.increment())     
25                 )
26         ))
27         .then(_ => bar.stop())
28         .then(_ => fs.promises.readdir("pages"))
29         .then(files => files
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))
34         )
35         .then(_ => doc.end())