]> git.lizzy.rs Git - local-nhentai.git/commitdiff
Add multiple tags selector and speed up doujin stats
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 9 May 2022 21:50:03 +0000 (23:50 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 9 May 2022 21:50:03 +0000 (23:50 +0200)
README.md
du.js
fzf.js
multiple-tags.js [new file with mode: 0644]
select.js
stats-doujins.js

index 385f365da069ed86ac15fde2fb9406d4b5032fdc..f195b54bcbc17afea1f4267f007d44bb4d36d3b3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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`.
diff --git a/du.js b/du.js
index 947fe81da7f470e8d3c37531f186bbecbb34f2eb..61cacbce73c7ddf7a65627b80f56ad8264299d55 100644 (file)
--- a/du.js
+++ b/du.js
@@ -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)
        })
diff --git a/fzf.js b/fzf.js
index 85f544c1ab4b176aa7b40bc94badf71185863b07..ce9c9b4ad17c1c94be726df4e71560ef26fc19c1 100644 (file)
--- a/fzf.js
+++ b/fzf.js
@@ -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 (file)
index 0000000..1e46899
--- /dev/null
@@ -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))
index 6938749cdaeb166e649688f1341f15eb6fe74635..f8ec511369957050978558b9b7204a6a9decd803 100644 (file)
--- a/select.js
+++ b/select.js
@@ -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()))
 })()
index 6d7b0e5f6495af939d91a392ef764411053e2698..943c17cf2a490bf94d4c6a2b7081ffacb5e4499d 100644 (file)
@@ -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))))