mirror of
https://github.com/TheBeastLT/torrentio-scraper.git
synced 2026-04-20 22:32:05 +00:00
[scraper] simplify update seeders query
This commit is contained in:
parent
95c2893523
commit
529f5ba76c
4 changed files with 13 additions and 13 deletions
|
|
@ -130,6 +130,13 @@ function createTorrent(torrent) {
|
|||
return Torrent.upsert(torrent);
|
||||
}
|
||||
|
||||
function setTorrentSeeders(infoHash, seeders) {
|
||||
return Torrent.update(
|
||||
{ seeders: seeders },
|
||||
{ where: { infoHash: infoHash } }
|
||||
);
|
||||
}
|
||||
|
||||
function createFile(file) {
|
||||
return File.upsert(file);
|
||||
}
|
||||
|
|
@ -164,6 +171,7 @@ module.exports = {
|
|||
connect,
|
||||
getProvider,
|
||||
createTorrent,
|
||||
setTorrentSeeders,
|
||||
getTorrent,
|
||||
getTorrentsBasedOnTitle,
|
||||
getUpdateSeedersTorrents,
|
||||
|
|
|
|||
|
|
@ -84,19 +84,11 @@ async function getStoredTorrentEntry(torrent) {
|
|||
}
|
||||
|
||||
async function updateTorrentSeeders(torrent) {
|
||||
if (torrent.seeders === undefined) {
|
||||
if (!torrent.infoHash || !Number.isInteger(torrent.seeders)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return repository.getTorrent(torrent)
|
||||
.catch(() => undefined)
|
||||
.then(stored => {
|
||||
if (stored) {
|
||||
stored.seeders = torrent.seeders;
|
||||
stored.changed('updatedAt', true);
|
||||
return stored.save()
|
||||
}
|
||||
})
|
||||
return repository.setTorrentSeeders(torrent.infoHash, torrent.seeders)
|
||||
.catch(error => {
|
||||
console.warn('Failed updating seeders:', error);
|
||||
return undefined;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ function scheduleUpdateSeeders() {
|
|||
return repository.getUpdateSeedersTorrents()
|
||||
.then(torrents => Promise.all(torrents.map(torrent => limiter.schedule(() => _updateSeeders(torrent)))))
|
||||
.then(torrents => updateStatistics(torrents))
|
||||
.then(() => console.log('Finished seeders update: ', statistics))
|
||||
.catch(error => console.warn('Failed seeders update: ', error))
|
||||
.then(() => console.log('Finished seeders update:', statistics))
|
||||
.catch(error => console.warn('Failed seeders update:', error))
|
||||
.then(() => delay(DELAY))
|
||||
.then(() => scheduleUpdateSeeders());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ const Categories = {
|
|||
|
||||
function torrent(torrentId, retries = 2) {
|
||||
if (!torrentId) {
|
||||
return Promise.reject(new Error('No valid torrentId provider'));
|
||||
return Promise.reject(new Error('No valid torrentId provided'));
|
||||
}
|
||||
|
||||
return _request(`t.php?id=${torrentId}`)
|
||||
|
|
|
|||
Loading…
Reference in a new issue