feat(trackers): basic trackers integration

This commit is contained in:
Alexey Kasyanchuk 2018-08-15 08:22:27 +03:00
parent cff0f11c79
commit 317cfdd3fb
6 changed files with 48 additions and 4 deletions

View File

@ -24,7 +24,8 @@ module.exports = async ({
checkTorrent,
setupTorrentRecord,
p2pStore,
feed
feed,
remoteTrackers
}) => {
let torrentClientHashMap = {}

View File

@ -155,7 +155,7 @@ const expand = (sphinx) => {
queryCall(`SELECT * from ${table} WHERE \`${key}\` = ${sphinx.escape(values[key])}`, (err, row) => {
if(err || row.length == 0)
{
logTE('sql', 'error on sql replace request', row)
logTE('sql', 'error on sql replace request', err)
resolve(undefined)
callback(undefined)
return

View File

@ -52,6 +52,7 @@ const writeSphinxConfig = async (path, dbPath) => {
rt_attr_timestamp = trackersChecked
rt_attr_uint = good
rt_attr_uint = bad
rt_attr_json = info
ngram_len = 1
ngram_chars = U+3000..U+2FA1F

View File

@ -39,6 +39,11 @@ const mime = require('mime');
//server.listen(config.httpPort);
//console.log('Listening web server on', config.httpPort, 'port')
const Rutracker = require('./strategies/rutracker')
const Nyaa = require('./strategies/nyaa')
module.exports = function (send, recive, dataDirectory, version, env)
{
this.initialized = (async () =>
@ -86,6 +91,37 @@ module.exports = function (send, recive, dataDirectory, version, env)
const sphinxSingleAlternative = await single().waitConnection()
class RemoteTrackers
{
constructor(sphinx)
{
this.sphinx = sphinx
this.trackers = [
new Rutracker,
new Nyaa
]
}
findHash(hash, callback)
{
for(const tracker of this.trackers)
if(tracker.findHash)
tracker.findHash(hash).then(data => callback(tracker.name(), data))
}
update({hash, name})
{
this.findHash(hash, (tracker, data) => {
if(!data)
return
logT('tracker', 'found', name, 'on', tracker)
this.sphinx.replaceValues('torrents', {hash, info: data}, true, 'hash')
})
}
}
const remoteTrackers = new RemoteTrackers(sphinxSingle)
// start
function baseRowData(row)
{
@ -462,6 +498,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
contentCategory: torrent.contentCategory,
});
updateTorrentTrackers(torrent.hash);
remoteTrackers.update(torrent)
}
else
{
@ -729,7 +766,8 @@ module.exports = function (send, recive, dataDirectory, version, env)
checkTorrent,
setupTorrentRecord,
p2pStore,
feed
feed,
remoteTrackers
})
if(config.indexer) {

View File

@ -4,6 +4,8 @@ const cheerio = require('cheerio')
module.exports = class Nyaa
{
name() { return 'nyaa' }
async findHash(hash)
{
this.hash = hash

View File

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