diff --git a/lib/convert.js b/lib/convert.js index 5233518..4bfdb05 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -6,12 +6,12 @@ const serializeToXML = require("xmlserializer").serializeToString; const { JSDOM } = require("jsdom"); const substitutions = require("./substitutions.json"); -module.exports = async (cachePath, manifestPath, contentPath) => { +module.exports = async (cachePath, manifestPath, contentPath, concurrentJobs) => { const manifestContents = await fs.readFile(manifestPath, { encoding: "utf-8" }); const chapters = JSON.parse(manifestContents); console.log("All chapters downloaded; beginning conversion to EPUB chapters"); - const mapper = throat(10, chapter => convertChapter(chapter, cachePath, contentPath)); + const mapper = throat(concurrentJobs, chapter => convertChapter(chapter, cachePath, contentPath)); await Promise.all(chapters.map(mapper)); console.log("All chapters converted"); diff --git a/lib/worm-scraper.js b/lib/worm-scraper.js index a288d6d..95d2601 100644 --- a/lib/worm-scraper.js +++ b/lib/worm-scraper.js @@ -48,6 +48,13 @@ const argv = yargs requiresArg: true, global: true }) + .option("j", { + alias: "jobs", + default: 10, + describe: "Number of concurrent read/write jobs to run, for the convert command", + requiresArg: true, + global: true + }) .demandCommand(1) // TODO remove and allow all .recommendCommands() .help() @@ -72,7 +79,7 @@ if (argv._.includes("convert")) { commands.push(() => { return rimraf(chaptersPath) .then(() => mkdirp(chaptersPath)) - .then(() => convert(cachePath, manifestPath, chaptersPath)); + .then(() => convert(cachePath, manifestPath, chaptersPath, argv.jobs)); }); }