mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] simplify update seeders query
This commit is contained in:
@@ -130,6 +130,13 @@ function createTorrent(torrent) {
|
|||||||
return Torrent.upsert(torrent);
|
return Torrent.upsert(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setTorrentSeeders(infoHash, seeders) {
|
||||||
|
return Torrent.update(
|
||||||
|
{ seeders: seeders },
|
||||||
|
{ where: { infoHash: infoHash } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function createFile(file) {
|
function createFile(file) {
|
||||||
return File.upsert(file);
|
return File.upsert(file);
|
||||||
}
|
}
|
||||||
@@ -164,6 +171,7 @@ module.exports = {
|
|||||||
connect,
|
connect,
|
||||||
getProvider,
|
getProvider,
|
||||||
createTorrent,
|
createTorrent,
|
||||||
|
setTorrentSeeders,
|
||||||
getTorrent,
|
getTorrent,
|
||||||
getTorrentsBasedOnTitle,
|
getTorrentsBasedOnTitle,
|
||||||
getUpdateSeedersTorrents,
|
getUpdateSeedersTorrents,
|
||||||
|
|||||||
@@ -84,19 +84,11 @@ async function getStoredTorrentEntry(torrent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateTorrentSeeders(torrent) {
|
async function updateTorrentSeeders(torrent) {
|
||||||
if (torrent.seeders === undefined) {
|
if (!torrent.infoHash || !Number.isInteger(torrent.seeders)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository.getTorrent(torrent)
|
return repository.setTorrentSeeders(torrent.infoHash, torrent.seeders)
|
||||||
.catch(() => undefined)
|
|
||||||
.then(stored => {
|
|
||||||
if (stored) {
|
|
||||||
stored.seeders = torrent.seeders;
|
|
||||||
stored.changed('updatedAt', true);
|
|
||||||
return stored.save()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.warn('Failed updating seeders:', error);
|
console.warn('Failed updating seeders:', error);
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ function scheduleUpdateSeeders() {
|
|||||||
return repository.getUpdateSeedersTorrents()
|
return repository.getUpdateSeedersTorrents()
|
||||||
.then(torrents => Promise.all(torrents.map(torrent => limiter.schedule(() => _updateSeeders(torrent)))))
|
.then(torrents => Promise.all(torrents.map(torrent => limiter.schedule(() => _updateSeeders(torrent)))))
|
||||||
.then(torrents => updateStatistics(torrents))
|
.then(torrents => updateStatistics(torrents))
|
||||||
.then(() => console.log('Finished seeders update: ', statistics))
|
.then(() => console.log('Finished seeders update:', statistics))
|
||||||
.catch(error => console.warn('Failed seeders update: ', error))
|
.catch(error => console.warn('Failed seeders update:', error))
|
||||||
.then(() => delay(DELAY))
|
.then(() => delay(DELAY))
|
||||||
.then(() => scheduleUpdateSeeders());
|
.then(() => scheduleUpdateSeeders());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ const Categories = {
|
|||||||
|
|
||||||
function torrent(torrentId, retries = 2) {
|
function torrent(torrentId, retries = 2) {
|
||||||
if (!torrentId) {
|
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}`)
|
return _request(`t.php?id=${torrentId}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user