diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-05-09 23:50:03 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-05-09 23:50:03 +0200 |
commit | e9c34b2a539052ca82eebc6c1d474d59c6ec6690 (patch) | |
tree | 0c831c24f25f6accbb7a046d15a4b8f190a71389 | |
parent | f2b0c6787996f205bc71c4e059a69b9427672b1d (diff) | |
download | local-nhentai-e9c34b2a539052ca82eebc6c1d474d59c6ec6690.tar.xz |
Add multiple tags selector and speed up doujin stats
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | du.js | 6 | ||||
-rw-r--r-- | fzf.js | 6 | ||||
-rw-r--r-- | multiple-tags.js | 11 | ||||
-rw-r--r-- | select.js | 16 | ||||
-rw-r--r-- | stats-doujins.js | 6 |
6 files changed, 30 insertions, 17 deletions
@@ -20,6 +20,8 @@ Remember to install NPM deps: `npm install` `node select.js`: Open fzf/überzug menu to select a doujin. Shows a list of tags first. When a tag is selected, shows all doujins with that tag and lets the user select one, displaying the thumbnails of the doujins at the side. The "\*" tag can be used to search/select from all doujins. +`node multiple-tags.js <tag1> <tag2> ...`: Open fzf/überzug menu with doujins that match all given tags (tags separated by whitespace). + `node stats-doujins.js`: Displays number of downloaded doujins, total size and average size per doujin `node stats-tags.js`: Displays tags sorted by how many doujins are available for each tag. May produce long output, you might want to pipe it into `head`, `grep` or `less`. @@ -1,10 +1,10 @@ const child = require("child_process") -module.exports = dir => { +module.exports = dirs => { let res, rej const prom = new Promise((rs, rj) => [res, rej] = [rs, rj]) - const proc = child.spawn("du", ["-b", "-L", dir]) + const proc = child.spawn("du", ["-b", "-L", "-c", ...dirs]) let data = "" proc.stdout.on("data", chunk => { @@ -13,7 +13,7 @@ module.exports = dir => { proc.on("close", code => { if (code == 0) - res(parseInt(data)) + res(parseInt(data.split("\n").at(-2))) else rej(code) }) @@ -1,6 +1,6 @@ const child = require("child_process") -module.exports = (options, binary = "fzf") => { +module.exports.fzf = (options, binary = "fzf") => { let res, rej const prom = new Promise((rs, rj) => [res, rej] = [rs, rj]) @@ -22,3 +22,7 @@ module.exports = (options, binary = "fzf") => { return prom } + +module.exports.doujin = doujins => module.exports.fzf(doujins.sort(), __dirname + "/fzf-previews") + .then(doujin => child.spawn("firefox", [`file://${process.cwd()}/${doujin}/index.html`])) + .catch(_ => {}) diff --git a/multiple-tags.js b/multiple-tags.js new file mode 100644 index 0000000..1e46899 --- /dev/null +++ b/multiple-tags.js @@ -0,0 +1,11 @@ +const fzf = require("./fzf") +const info = require("./info") + +const tags = process.argv.slice(2) + +info.doujins() + .then(doujins => Object.values(doujins)) + .then(doujins => doujins.filter(doujin => + tags.every(tag => doujin.tag && doujin.tag.includes(tag)))) + .then(doujins => doujins.map(doujin => doujin.title)) + .then(doujins => fzf.doujin(doujins)) @@ -1,16 +1,14 @@ -const child = require("child_process") const fzf = require("./fzf") const info = require("./info") ;(async _ => { - const doujins = await info.doujins() const tags = await info.tags() - let doujin, tag - while (!doujin) { - try { tag = await fzf(Object.keys(tags).sort()) } catch { return } - try { doujin = await fzf(Object.values(tags[tag]).sort(), __dirname + "/fzf-previews") } catch {} - } - - child.spawn("firefox", [`file://${process.cwd()}/${doujin}/index.html`]) + do { + try { + tag = await fzf.fzf(Object.keys(tags).sort()) + } catch { + return + } + } while (!await fzf.doujin(Object.values(tags[tag]).sort())) })() diff --git a/stats-doujins.js b/stats-doujins.js index 6d7b0e5..943c17c 100644 --- a/stats-doujins.js +++ b/stats-doujins.js @@ -8,7 +8,5 @@ Average size per doujin: ${(size / num / 1e6).toFixed(2)}MB` info.doujins() .then(doujins => Object.keys(doujins)) - .then(doujins => Promise.all(doujins.map(du)) - .then(sizes => sizes.reduce((a, b) => a + b, 0)) - .then(total => console.log(fmt(doujins.length, total))) - ) + .then(doujins => du(doujins) + .then(total => console.log(fmt(doujins.length, total)))) |