fix(nyaa): nyaa test fix

This commit is contained in:
Alexey Kasyanchuk 2018-08-18 08:37:57 +03:00
parent d522a53988
commit f5bacca855

View File

@ -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()
{ {
let html; if(this.promise)
try { await this.promise
html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
let topicTitle = $('.panel-title').first().text()
if(!topicTitle)
return
topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '') this.promise = new Promise(async (resolve) => {
return { let html;
name: topicTitle, try {
description: $('#torrent-description').text(), html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
} } catch(err) {
resolve()
}
if(!html)
resolve()
html = await html.textConverted()
const $ = cheerio.load(html)
let topicTitle = $('.panel-title').first().text()
if(!topicTitle)
resolve()
topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '')
resolve({
name: topicTitle,
description: $('#torrent-description').text(),
})
})
return await this.promise
} }
} }