]> git.lizzy.rs Git - local-nhentai.git/blob - scrape-links.js
Generic stats and select
[local-nhentai.git] / scrape-links.js
1 const fetch = require("node-fetch")
2 const child = require("child_process")
3
4 module.exports = async (page, link) => {
5         let data
6
7         try {
8                 data = await (await fetch(page)).text()
9         } catch {}
10
11         if (!data)
12                 return false
13
14         const ids = []
15
16         while (true) {
17                 const pos = data.search(link)
18
19                 if (pos == -1)
20                         break;
21
22                 data = data.slice(pos + link.length)
23                 const id = parseInt(data)
24                 if (id)
25                         ids.push(id)
26         }
27
28         if (ids.length < 1)
29                 return false
30
31         child.spawnSync("nhentai", ["--id", ids.join(",")], { stdio: "inherit" })
32         return true
33 }