[scraper] checks for torrent contents when updating existing torrent

This commit is contained in:
TheBeastLT
2020-05-06 11:59:53 +02:00
parent 0ad7324a6a
commit 9ce3f72e5d
12 changed files with 125 additions and 35 deletions

View File

@@ -198,6 +198,17 @@ function getUpdateSeedersTorrents() {
});
}
function getNoContentsTorrents() {
return Torrent.findAll({
where: { opened: false },
limit: 500,
order: [
['seeders', 'DESC'],
['uploadDate', 'DESC']
]
});
}
function createTorrent(torrent) {
return Torrent.upsert(torrent)
.then(() => createContents(torrent.infoHash, torrent.contents))
@@ -213,7 +224,8 @@ function setTorrentSeeders(infoHash, seeders) {
function createFile(file) {
if (file.id) {
return File.upsert(file).then(() => upsertSubtitles(file.id, file.subtitles));
return (file.dataValues ? file.save() : File.upsert(file))
.then(() => upsertSubtitles(file, file.subtitles));
}
if (file.subtitles && file.subtitles.length) {
file.subtitles = file.subtitles.map(subtitle => ({ infoHash: file.infoHash, title: subtitle.path, ...subtitle }));
@@ -249,7 +261,7 @@ function upsertSubtitles(file, subtitles) {
subtitle.title = subtitle.title || subtitle.path;
return subtitle;
})
.map(subtitle => () => subtitle.dataValues ? subtitle.save() : Subtitle.upsert(subtitle)));
.map(subtitle => () => subtitle.dataValues ? subtitle.save() : Subtitle.create(subtitle)));
}
return Promise.resolve();
}
@@ -296,6 +308,7 @@ module.exports = {
getTorrent,
getTorrentsBasedOnTitle,
getUpdateSeedersTorrents,
getNoContentsTorrents,
createFile,
getFiles,
getFilesBasedOnTitle,