]> git.lizzy.rs Git - local-nhentai.git/blob - info.js
Add scraping by tag,character,artist,group,parody
[local-nhentai.git] / info.js
1 const fs = require("fs").promises
2
3 module.exports.doujins = shortNames => fs.readdir(".", {encoding: "utf8", withFileTypes: true})
4         .then(doujins => doujins
5                 .map(dirent => fs.readFile(`${dirent.name}/metadata.json`)
6                         .then(data => JSON.parse(data.toString()))
7                         .then(data => [dirent.name, data])
8                         .catch(_ => [])))
9         .then(promises => Promise.all(promises))
10         .then(doujins => doujins
11                 .filter(([title, data]) => title && data)
12                 .filter(([title, data]) => (title == data.title) == !shortNames))
13         .then(doujins => Object.fromEntries(doujins))
14
15 module.exports.tags = _ => {
16         const tags = {"*": []}
17
18         return module.exports.doujins()
19                 .then(doujins => Object.values(doujins))
20                 .then(doujins => doujins
21                         .forEach(doujin => {
22                                 tags["*"].push(doujin.title)    
23
24                                 doujin.tag && doujin.tag.forEach(tag => {
25                                         tags[tag] = tags[tag] || []
26                                         tags[tag].push(doujin.title)
27                                 })
28                         }))
29                 .then(_ => tags)
30 }