mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] assign subtitles to videos
This commit is contained in:
@@ -204,6 +204,9 @@ function createFile(file) {
|
||||
if (file.id) {
|
||||
return File.upsert(file).then(() => upsertSubtitles(file.id, file.subtitles));
|
||||
}
|
||||
if (file.subtitles && file.subtitles.length) {
|
||||
file.subtitles = file.subtitles.map(subtitle => ({ infoHash: file.infoHash, title: subtitle.path, ...subtitle }));
|
||||
}
|
||||
return File.create(file, { include: [Subtitle] });
|
||||
}
|
||||
|
||||
@@ -229,8 +232,13 @@ function createSubtitles(infoHash, subtitles) {
|
||||
function upsertSubtitles(file, subtitles) {
|
||||
if (file.id && subtitles && subtitles.length) {
|
||||
return Promises.sequence(subtitles
|
||||
.map(subtitle => ({ fileId: file.id, infoHash: file.infoHash, title: subtitle.path, ...subtitle }))
|
||||
.map(subtitle => () => Subtitle.upsert(subtitle)));
|
||||
.map(subtitle => {
|
||||
subtitle.fileId = file.id;
|
||||
subtitle.infoHash = subtitle.infoHash || file.infoHash;
|
||||
subtitle.title = subtitle.title || subtitle.path;
|
||||
return subtitle;
|
||||
})
|
||||
.map(subtitle => () => subtitle.dataValues ? subtitle.save() : Subtitle.upsert(subtitle)));
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
@@ -239,6 +247,10 @@ function getSubtitles(torrent) {
|
||||
return Subtitle.findAll({ where: { infoHash: torrent.infoHash } });
|
||||
}
|
||||
|
||||
function getUnassignedSubtitles() {
|
||||
return Subtitle.findAll({ where: { fileId: null } });
|
||||
}
|
||||
|
||||
function createContents(infoHash, contents) {
|
||||
if (contents && contents.length) {
|
||||
return Content.bulkCreate(contents.map(content => ({ infoHash, ...content })))
|
||||
@@ -278,7 +290,9 @@ module.exports = {
|
||||
getFilesBasedOnTitle,
|
||||
deleteFile,
|
||||
createSubtitles,
|
||||
upsertSubtitles,
|
||||
getSubtitles,
|
||||
getUnassignedSubtitles,
|
||||
createContents,
|
||||
getContents,
|
||||
getSkipTorrent,
|
||||
|
||||
Reference in New Issue
Block a user