mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] fixes update seeders method
This commit is contained in:
@@ -83,7 +83,7 @@ function escapeTitle(title) {
|
||||
.normalize('NFKD') // normalize non-ASCII characters
|
||||
.replace(/[\u0300-\u036F]/g, '')
|
||||
.replace(/&/g, 'and')
|
||||
.replace(/[;, ~]+/g, ' ') // replace dots, commas or underscores with spaces
|
||||
.replace(/[;, ~.]+/g, ' ') // replace dots, commas or underscores with spaces
|
||||
.replace(/[^\w \-()+#@!']+/g, '') // remove all non-alphanumeric chars
|
||||
.trim();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ function getTorrent(torrent) {
|
||||
if (!result) {
|
||||
throw new Error(`torrent not found: ${torrent.infoHash}`);
|
||||
}
|
||||
return result.dataValues;
|
||||
return result;
|
||||
})
|
||||
}
|
||||
|
||||
@@ -115,6 +115,14 @@ function getTorrentsBasedOnTitle(titleQuery, type) {
|
||||
return Torrent.findAll({ where: { title: { [Op.regexp]: `${titleQuery}` }, type: type } });
|
||||
}
|
||||
|
||||
function getTorrentsWithoutId(provider) {
|
||||
return Torrent.findAll({ where: { provider: provider, torrentId: { [Op.is]: null } }, limit: 100 });
|
||||
}
|
||||
|
||||
function getTorrentsUpdatedBetween(provider, startDate, endDate) {
|
||||
return Torrent.findAll({ where: { provider: provider, updatedAt: { [Op.gte]: startDate, [Op.lte]: endDate } } });
|
||||
}
|
||||
|
||||
function createTorrent(torrent) {
|
||||
return Torrent.upsert(torrent);
|
||||
}
|
||||
@@ -176,5 +184,7 @@ module.exports = {
|
||||
deleteFile,
|
||||
getSkipTorrent,
|
||||
createSkipTorrent,
|
||||
createFailedImdbTorrent
|
||||
createFailedImdbTorrent,
|
||||
getTorrentsWithoutId,
|
||||
getTorrentsUpdatedBetween
|
||||
};
|
||||
@@ -60,10 +60,21 @@ async function updateTorrentSeeders(torrent) {
|
||||
}
|
||||
|
||||
return repository.getTorrent(torrent)
|
||||
.catch(() => undefined)
|
||||
.then(stored => {
|
||||
stored.seeders = torrent.seeders;
|
||||
return stored.save();
|
||||
}).catch(() => undefined);
|
||||
if (stored && stored.seeders !== torrent.seeders) {
|
||||
stored.seeders = torrent.seeders;
|
||||
return stored.save()
|
||||
}
|
||||
})
|
||||
.then(updated => {
|
||||
console.log(`Updated [${torrent.infoHash}] ${torrent.name || torrent.title} to ${torrent.seeders} seeders`);
|
||||
return updated;
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Failed updating seeders:', error);
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { createTorrentEntry, createSkipTorrentEntry, getStoredTorrentEntry, updateTorrentSeeders };
|
||||
|
||||
Reference in New Issue
Block a user