aboutsummaryrefslogtreecommitdiff
path: root/scrape-links.js
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-14 21:21:59 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-14 21:21:59 +0200
commit8a0a187b31a3e0e9b9faed1369441576a2b1d103 (patch)
tree842401b73c051439926b139657310cd9719af310 /scrape-links.js
parente9c34b2a539052ca82eebc6c1d474d59c6ec6690 (diff)
downloadlocal-nhentai-8a0a187b31a3e0e9b9faed1369441576a2b1d103.tar.xz
Add scraping by tag,character,artist,group,parody
Diffstat (limited to 'scrape-links.js')
-rw-r--r--scrape-links.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/scrape-links.js b/scrape-links.js
new file mode 100644
index 0000000..0b3f2b9
--- /dev/null
+++ b/scrape-links.js
@@ -0,0 +1,33 @@
+const fetch = require("node-fetch")
+const child = require("child_process")
+
+module.exports = async (page, link) => {
+ let data
+
+ try {
+ data = await (await fetch(page)).text()
+ } catch {}
+
+ if (!data)
+ return false
+
+ const ids = []
+
+ while (true) {
+ const pos = data.search(link)
+
+ if (pos == -1)
+ break;
+
+ data = data.slice(pos + link.length)
+ const id = parseInt(data)
+ if (id)
+ ids.push(id)
+ }
+
+ if (ids.length < 1)
+ return false
+
+ child.spawnSync("nhentai", ["--id", ids.join(",")], { stdio: "inherit" })
+ return true
+}