feat(rutracker): rutracker basic integratioin

This commit is contained in:
Alexey Kasyanchuk
2018-07-30 11:59:38 +03:00
parent 1cec380202
commit bf23587211
5 changed files with 248 additions and 28 deletions

View File

@ -0,0 +1,7 @@
const google = require('google')
module.exports = (search) => new Promise((resolve) => {
google(search, (err, res) => {
resolve(res.links)
})
})

View File

@ -0,0 +1,29 @@
const fetch = require('node-fetch')
const cheerio = require('cheerio')
module.exports = class Rutracker
{
async findHash(hash)
{
this.hash = hash
return await this.parse()
}
async parse()
{
let html = await fetch('https://rutracker.org/forum/viewtopic.php?' + (this.threadId ? `t=${this.threadId}` : (this.hash ? `h=${this.hash}` : '')))
if(!html)
return
html = await html.text()
const $ = cheerio.load(html)
const topicTitle = $('#topic-title').text()
if(!topicTitle)
return
return {
name: topicTitle,
poster: $('.post_body .postImgAligned').attr('title'),
description: $('.post_body').text(),
}
}
}