mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] rework scraper scheduling and added seeders updating
This commit is contained in:
@@ -18,8 +18,9 @@ module.exports.updateCurrentSeeders = function (torrent) {
|
||||
const Tracker = require("peer-search/tracker");
|
||||
|
||||
const seeders = {};
|
||||
const decodedMagnetLink = torrent.magnetLink && decode(torrent.magnetLink);
|
||||
const trackers = decodedMagnetLink && decodedMagnetLink.tr || torrent.trackers || await getDefaultTrackers();
|
||||
const magnetTrackers = torrent.magnetLink && decode(torrent.magnetLink).tr;
|
||||
const torrentTrackers = torrent.trackers && torrent.trackers.split(',');
|
||||
const trackers = magnetTrackers || torrentTrackers || await getDefaultTrackers();
|
||||
const callback = () => resolve(Math.max(...Object.values(seeders).map(values => values[0]).concat(0)));
|
||||
setTimeout(callback, SEEDS_CHECK_TIMEOUT);
|
||||
|
||||
|
||||
@@ -29,20 +29,20 @@ async function createTorrentEntry(torrent, overwrite = false) {
|
||||
}
|
||||
|
||||
if (!torrent.imdbId && !torrent.kitsuId && !titleInfo.complete && typeof titleInfo.year !== 'string') {
|
||||
console.log(`imdbId or kitsuId not found: ${torrent.title}`);
|
||||
console.log(`imdbId or kitsuId not found: ${torrent.provider} ${torrent.title}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const files = await parseTorrentFiles(torrent)
|
||||
.then(files => overwrite ? overwriteExistingFiles(torrent, files) : files);
|
||||
if (!files || !files.length) {
|
||||
console.log(`no video files found for [${torrent.infoHash}] ${torrent.title}`);
|
||||
console.log(`no video files found for ${torrent.provider} [${torrent.infoHash}] ${torrent.title}`);
|
||||
return;
|
||||
}
|
||||
|
||||
return repository.createTorrent(torrent)
|
||||
.then(() => Promise.all(files.map(file => repository.createFile(file))))
|
||||
.then(() => console.log(`Created entry for [${torrent.infoHash}] ${torrent.title}`));
|
||||
.then(() => console.log(`Created ${torrent.provider} entry for [${torrent.infoHash}] ${torrent.title}`));
|
||||
}
|
||||
|
||||
async function overwriteExistingFiles(torrent, files) {
|
||||
|
||||
Reference in New Issue
Block a user