-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnhentai.js
43 lines (40 loc) · 1.38 KB
/
nhentai.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const request = require('superagent')
const cheerio = require('cheerio')
class nHentai {
static getTags(id) {
return new Promise((resolve, reject) => {
request
.get('https://nhentai.net/g/' + id)
.then(res => {
const $ = cheerio.load(res.text)
const tags = $("a[href^='/tag/']")
var tagArr = []
for (var key in tags){
if(!isNaN(key)){
var children = tags[key].children
if(typeof children == 'object'){
var tag = children[0].data.trim()
var count = children[1].children[0].data.trim()
var tagobj = {tag, count}
tagArr.push(tagobj)
}
}
}
resolve(tagArr)
})
.catch(reject)
})
}
static exists(id) {
return new Promise((resolve, reject) => {
request
.head('https://nhentai.net/g/' + id + '/')
.then(res => resolve(true))
.catch(err => {
resolve(false)
return
})
})
}
}
module.exports = nHentai