mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] uses bittorrent-tracker for force update seeders
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const torrentStream = require('torrent-stream');
|
||||
const needle = require('needle');
|
||||
const parseTorrent = require('parse-torrent');
|
||||
const BTClient = require('bittorrent-tracker')
|
||||
const async = require('async');
|
||||
const decode = require('magnet-uri');
|
||||
const isVideo = require('./video');
|
||||
@@ -15,7 +16,6 @@ module.exports.updateCurrentSeeders = function (torrent) {
|
||||
if (!torrent.magnetLink && !torrent.infoHash) {
|
||||
return resolve(0);
|
||||
}
|
||||
const Tracker = require("peer-search/tracker");
|
||||
|
||||
const seeders = {};
|
||||
const magnetTrackers = torrent.magnetLink && decode(torrent.magnetLink).tr;
|
||||
@@ -25,13 +25,12 @@ module.exports.updateCurrentSeeders = function (torrent) {
|
||||
setTimeout(callback, SEEDS_CHECK_TIMEOUT);
|
||||
|
||||
async.each(trackers, function (tracker, ready) {
|
||||
const t = new Tracker(tracker, {}, torrent.infoHash);
|
||||
console.error = () => 0; // do nothing
|
||||
t.run();
|
||||
t.on("info", function (inf) {
|
||||
seeders[tracker] = [inf.seeders, inf.leechers];
|
||||
BTClient.scrape({ infoHash: torrent.infoHash, announce: tracker }, (_, results) => {
|
||||
if (results) {
|
||||
seeders[tracker] = [results.complete, results.incomplete];
|
||||
}
|
||||
ready();
|
||||
});
|
||||
})
|
||||
}, callback);
|
||||
}).then(seeders => {
|
||||
torrent.seeders = seeders;
|
||||
@@ -125,7 +124,7 @@ function filterVideos(files) {
|
||||
|
||||
function filterSamples(files) {
|
||||
const maxSize = Math.max(...files.map(file => file.size));
|
||||
const isSample = file => file.name.match(/sample/i) && maxSize / file.size < 10;
|
||||
const isSample = file => file.name.match(/sample/i) && maxSize / parseInt(file.size) > 10;
|
||||
return files.filter(file => !isSample(file));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ async function _updateSeeders(torrent) {
|
||||
return []
|
||||
});
|
||||
|
||||
// if (!updatedTorrents.find(updated => updated.infoHash === torrent.infoHash)) {
|
||||
// await forceSeedersLimiter.schedule(() => updateCurrentSeeders(torrent))
|
||||
// .then(updated => updatedTorrents.push(updated));
|
||||
// }
|
||||
if (!updatedTorrents.find(updated => updated.infoHash === torrent.infoHash)) {
|
||||
await forceSeedersLimiter.schedule(() => updateCurrentSeeders(torrent))
|
||||
.then(updated => updatedTorrents.push(updated));
|
||||
}
|
||||
|
||||
return Promise.all(updatedTorrents.map(updated => updateLimiter.schedule(() => updateTorrentSeeders(updated))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user