feat(strategies): 1337 strategie
This commit is contained in:
parent
9453ab8ba8
commit
44a800dbbb
@ -32,6 +32,11 @@ export default (props) => {
|
|||||||
&&
|
&&
|
||||||
<a href={`http://www.rutor.is/torrent/${info.rutorThreadId}`}><img src={RutorIcon} style={{height: 32}} /></a>
|
<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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -144,7 +144,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
{
|
{
|
||||||
for(const tracker of this.trackers)
|
for(const tracker of this.trackers)
|
||||||
if(tracker.findHash)
|
if(tracker.findHash)
|
||||||
tracker.findHash(hash).then(data => callback(tracker.name(), data))
|
tracker.findHash(hash).then(data => callback(tracker.name, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
async close()
|
async close()
|
||||||
|
59
src/background/strategies/1337x.js
Normal file
59
src/background/strategies/1337x.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ const cheerio = require('cheerio')
|
|||||||
|
|
||||||
module.exports = class Nyaa
|
module.exports = class Nyaa
|
||||||
{
|
{
|
||||||
name() { return 'nyaa' }
|
get name() { return 'nyaa' }
|
||||||
|
|
||||||
async findHash(hash)
|
async findHash(hash)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ module.exports = class Rutor
|
|||||||
t.unref()
|
t.unref()
|
||||||
}
|
}
|
||||||
|
|
||||||
name() { return 'rutor' }
|
get name() { return 'rutor' }
|
||||||
|
|
||||||
async findHash(hash)
|
async findHash(hash)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ const cheerio = require('cheerio')
|
|||||||
|
|
||||||
module.exports = class Rutracker
|
module.exports = class Rutracker
|
||||||
{
|
{
|
||||||
name() { return 'rutracker' }
|
get name() { return 'rutracker' }
|
||||||
|
|
||||||
async findHash(hash)
|
async findHash(hash)
|
||||||
{
|
{
|
||||||
|
19
tests/strategies/1337x.test.js
Normal file
19
tests/strategies/1337x.test.js
Normal 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'))
|
||||||
|
})
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user