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 cheerio = require('cheerio')
@ -14,24 +13,32 @@ module.exports = class Nyaa
async parse()
{
let html;
try {
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
if(this.promise)
await this.promise
topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '')
return {
name: topicTitle,
description: $('#torrent-description').text(),
}
this.promise = new Promise(async (resolve) => {
let html;
try {
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
}
}