feat(strategies): 1337 strategie

This commit is contained in:
Alexey Kasyanchuk 2018-12-23 00:24:05 +03:00
parent 9453ab8ba8
commit 44a800dbbb
7 changed files with 87 additions and 4 deletions

View File

@ -32,6 +32,11 @@ export default (props) => {
&&
<a href={`http://www.rutor.is/torrent/${info.rutorThreadId}`}><img src={RutorIcon} style={{height: 32}} /></a>
}
{
info.trackers.includes('1337x')
&&
<a href={`https://1337x.to${info.x1337Href}`}><img src='https://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/1337X_logo.svg/1200px-1337X_logo.svg.png' style={{height: 32}} /></a>
}
</div>
)
}

View File

@ -144,7 +144,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
{
for(const tracker of this.trackers)
if(tracker.findHash)
tracker.findHash(hash).then(data => callback(tracker.name(), data))
tracker.findHash(hash).then(data => callback(tracker.name, data))
}
async close()

View File

@ -0,0 +1,59 @@
const fetch = require('node-fetch')
const cheerio = require('cheerio')
module.exports = class Stragegie
{
get name() { return '1337x' }
async findHash(hash)
{
let html;
try {
html = await fetch(`https://1337x.to/srch?search=${hash}`)
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
this.href = $($('.table-list tr td a').get(1)).attr('href')
if(this.href)
this.id = this.href.match(/\/torrent\/([0-9]+)\//)[1];
return await this.parse();
}
async parse()
{
let html;
try {
html = await fetch('https://1337x.to' + this.href)
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
const topicTitle = $('h1').text()
if(!topicTitle)
return
let contentCategory;
try {
contentCategory = $('.torrent-category-detail .list li').first().find('span').text()
} catch(er) {}
return {
name: topicTitle.trim(),
poster: $('#description img').attr('data-original'),
description: $('#description').text(),
x1337ThreadId: parseInt(this.id),
x1337Href: this.href,
contentCategory
}
}
}

View File

@ -3,7 +3,7 @@ const cheerio = require('cheerio')
module.exports = class Nyaa
{
name() { return 'nyaa' }
get name() { return 'nyaa' }
async findHash(hash)
{

View File

@ -18,7 +18,7 @@ module.exports = class Rutor
t.unref()
}
name() { return 'rutor' }
get name() { return 'rutor' }
async findHash(hash)
{

View File

@ -4,7 +4,7 @@ const cheerio = require('cheerio')
module.exports = class Rutracker
{
name() { return 'rutracker' }
get name() { return 'rutracker' }
async findHash(hash)
{

View File

@ -0,0 +1,19 @@
const { assert } = require('chai')
const Strategy = require('../../src/background/strategies/1337x.js')
describe("1337x", () => {
let strategy = new Strategy();
it("findHash", async function() {
const data = await strategy.findHash('1734BCCAA7B05BD4D77B86E17820C840BF0C2EF5')
assert.equal(data.name, 'DEgITx - Discography (01.10.2016) FLAC')
assert.equal(data.poster, 'http://i58.fastpic.ru/big/2014/0224/62/eec1c9dc98892d5a88b46ade2edc7662.jpg')
assert.equal(data.x1337ThreadId, 1821018)
assert(data.description.includes('licensed under Creative Commons'))
assert.equal(data.contentCategory, 'Music')
})
it("notFound", async function() {
assert(!await strategy.findHash('1734BCCAA7B05BD4D77B86E17820C840BF0C2EF6'))
})
});