feat(rutracker): rutracker basic integratioin
This commit is contained in:
7
src/background/strategies/google.js
Normal file
7
src/background/strategies/google.js
Normal file
@ -0,0 +1,7 @@
|
||||
const google = require('google')
|
||||
|
||||
module.exports = (search) => new Promise((resolve) => {
|
||||
google(search, (err, res) => {
|
||||
resolve(res.links)
|
||||
})
|
||||
})
|
29
src/background/strategies/rutracker.js
Normal file
29
src/background/strategies/rutracker.js
Normal 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(),
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user