]> git.lizzy.rs Git - local-nhentai.git/blobdiff - scrape-links.js
Add scraping by tag,character,artist,group,parody
[local-nhentai.git] / scrape-links.js
diff --git a/scrape-links.js b/scrape-links.js
new file mode 100644 (file)
index 0000000..0b3f2b9
--- /dev/null
@@ -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
+}