fix(nyaa): nyaa test fix
This commit is contained in:
parent
d522a53988
commit
f5bacca855
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
|
|
||||||
@ -14,24 +13,32 @@ module.exports = class Nyaa
|
|||||||
|
|
||||||
async parse()
|
async parse()
|
||||||
{
|
{
|
||||||
|
if(this.promise)
|
||||||
|
await this.promise
|
||||||
|
|
||||||
|
this.promise = new Promise(async (resolve) => {
|
||||||
let html;
|
let html;
|
||||||
try {
|
try {
|
||||||
html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
|
html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return
|
resolve()
|
||||||
}
|
}
|
||||||
if(!html)
|
if(!html)
|
||||||
return
|
resolve()
|
||||||
html = await html.textConverted()
|
html = await html.textConverted()
|
||||||
const $ = cheerio.load(html)
|
const $ = cheerio.load(html)
|
||||||
let topicTitle = $('.panel-title').first().text()
|
let topicTitle = $('.panel-title').first().text()
|
||||||
if(!topicTitle)
|
if(!topicTitle)
|
||||||
return
|
resolve()
|
||||||
|
|
||||||
topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '')
|
topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '')
|
||||||
return {
|
|
||||||
|
resolve({
|
||||||
name: topicTitle,
|
name: topicTitle,
|
||||||
description: $('#torrent-description').text(),
|
description: $('#torrent-description').text(),
|
||||||
}
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return await this.promise
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user