mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
handles series type mismatch if is in movie category
This commit is contained in:
@@ -81,6 +81,10 @@ function getTorrent(torrent) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTorrentsBasedOnTitle(titleQuery, type) {
|
||||||
|
return Torrent.findAll({ where: { title: { [Op.regexp]: `${titleQuery}` }, type: type } });
|
||||||
|
}
|
||||||
|
|
||||||
function createTorrent(torrent) {
|
function createTorrent(torrent) {
|
||||||
return Torrent.upsert(torrent);
|
return Torrent.upsert(torrent);
|
||||||
}
|
}
|
||||||
@@ -133,8 +137,9 @@ module.exports = {
|
|||||||
connect,
|
connect,
|
||||||
getProvider,
|
getProvider,
|
||||||
updateProvider,
|
updateProvider,
|
||||||
getTorrent,
|
|
||||||
createTorrent,
|
createTorrent,
|
||||||
|
getTorrent,
|
||||||
|
getTorrentsBasedOnTitle,
|
||||||
createFile,
|
createFile,
|
||||||
getFiles,
|
getFiles,
|
||||||
getFilesBasedOnTitle,
|
getFilesBasedOnTitle,
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ async function createTorrentEntry(torrent) {
|
|||||||
const titleInfo = parse(torrent.title);
|
const titleInfo = parse(torrent.title);
|
||||||
const searchTitle = escapeTitle(titleInfo.title).toLowerCase();
|
const searchTitle = escapeTitle(titleInfo.title).toLowerCase();
|
||||||
|
|
||||||
|
if (titleInfo.seasons && torrent.type === Type.MOVIE) {
|
||||||
|
// sometimes series torrent might be put into movies category
|
||||||
|
torrent.type = Type.SERIES;
|
||||||
|
}
|
||||||
if (!torrent.imdbId && torrent.type !== Type.ANIME) {
|
if (!torrent.imdbId && torrent.type !== Type.ANIME) {
|
||||||
torrent.imdbId = await getImdbId({ name: searchTitle, year: titleInfo.year, type: torrent.type })
|
torrent.imdbId = await getImdbId({ name: searchTitle, year: titleInfo.year, type: torrent.type })
|
||||||
.catch(() => undefined);
|
.catch(() => undefined);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ async function parseTorrentFiles(torrent) {
|
|||||||
// throw new Error(`Mismatching entry type for ${torrent.name}: ${torrent.type}!=${metadata.type}`);
|
// throw new Error(`Mismatching entry type for ${torrent.name}: ${torrent.type}!=${metadata.type}`);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (torrent.type === Type.MOVIE) {
|
if (torrent.type === Type.MOVIE && !parsedTorrentName.seasons) {
|
||||||
if (parsedTorrentName.complete) {
|
if (parsedTorrentName.complete) {
|
||||||
return torrentFiles(torrent)
|
return torrentFiles(torrent)
|
||||||
.then(files => files.filter(file => file.size > MIN_SIZE))
|
.then(files => files.filter(file => file.size > MIN_SIZE))
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
const Bottleneck = require('bottleneck');
|
||||||
const { parse } = require('parse-torrent-title');
|
const { parse } = require('parse-torrent-title');
|
||||||
const repository = require('../lib/repository');
|
const repository = require('../lib/repository');
|
||||||
const { parseTorrentFiles } = require('../lib/torrentFiles');
|
const { parseTorrentFiles } = require('../lib/torrentFiles');
|
||||||
const { Type } = require('../lib/types');
|
const { Type } = require('../lib/types');
|
||||||
|
|
||||||
|
const limiter = new Bottleneck({ maxConcurrent: 40 });
|
||||||
|
|
||||||
async function addMissingEpisodes() {
|
async function addMissingEpisodes() {
|
||||||
const torrent = { infoHash: '0ec780c2c7f8d5b38e61827f0b53c77c3d22f955' };
|
const torrent = { infoHash: '0ec780c2c7f8d5b38e61827f0b53c77c3d22f955' };
|
||||||
const torrentFiles = await require('../lib/torrent').torrentFiles(torrent);
|
const torrentFiles = await require('../lib/torrent').torrentFiles(torrent);
|
||||||
@@ -48,27 +51,42 @@ async function updateMovieCollections() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reapplyEpisodeDecomposing() {
|
async function reapplySeriesSeasonsSavedAsMovies() {
|
||||||
const infoHash = '84fadd061f0d0bc356235b7fa6495a0f51fff311';
|
return repository.getTorrentsBasedOnTitle('(?:[^a-zA-Z0-9]|^)[Ss][012]?[0-9](?:[^0-9]|$)', Type.MOVIE)
|
||||||
const imdbId = 'tt0988824';
|
.then(torrents => Promise.all(torrents
|
||||||
|
.filter(torrent => parse(torrent.title).seasons)
|
||||||
|
.map(torrent => limiter.schedule(() => reapplyEpisodeDecomposing(torrent.infoHash, false)
|
||||||
|
.then(() => {
|
||||||
|
torrent.type = Type.SERIES;
|
||||||
|
return torrent.save();
|
||||||
|
})))))
|
||||||
|
.then(() => console.log('Finished updating multiple torrents'));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reapplyEpisodeDecomposing(infoHash, includeSourceFiles = true) {
|
||||||
const torrent = await repository.getTorrent({ infoHash });
|
const torrent = await repository.getTorrent({ infoHash });
|
||||||
const storedFiles = await repository.getFiles({ infoHash });
|
const storedFiles = await repository.getFiles({ infoHash });
|
||||||
const fileIndexMap = storedFiles
|
const fileIndexMap = storedFiles
|
||||||
.reduce((map, next) => (map[next.fileIndex] = (map[next.fileIndex] || []).concat(next), map), {});
|
.reduce((map, next) => (map[next.fileIndex] = (map[next.fileIndex] || []).concat(next), map), {});
|
||||||
const files = Object.values(fileIndexMap)
|
const files = includeSourceFiles && Object.values(fileIndexMap)
|
||||||
.map(sameIndexFiles => sameIndexFiles[0])
|
.map(sameIndexFiles => sameIndexFiles[0])
|
||||||
.map(file => ({ fileIndex: file.fileIndex, name: file.title, path: file.title, size: file.size }));
|
.map(file => ({ fileIndex: file.fileIndex, name: file.title, path: file.title, size: file.size }));
|
||||||
|
const imdbId = storedFiles[0].imdbId;
|
||||||
|
|
||||||
return parseTorrentFiles({ ...torrent, imdbId, files })
|
return parseTorrentFiles({ ...torrent, imdbId, files })
|
||||||
.then(newFiles => newFiles.map(file => {
|
.then(newFiles => newFiles.map(file => {
|
||||||
const originalFile = fileIndexMap[file.fileIndex].shift();
|
if (fileIndexMap[file.fileIndex]) {
|
||||||
originalFile.imdbSeason = file.imdbSeason;
|
const originalFile = fileIndexMap[file.fileIndex].shift();
|
||||||
originalFile.imdbEpisode = file.imdbEpisode;
|
originalFile.imdbSeason = file.imdbSeason;
|
||||||
originalFile.kitsuId = file.kitsuId;
|
originalFile.imdbEpisode = file.imdbEpisode;
|
||||||
originalFile.kitsuEpisode = file.kitsuEpisode;
|
originalFile.kitsuId = file.kitsuId;
|
||||||
return originalFile;
|
originalFile.kitsuEpisode = file.kitsuEpisode;
|
||||||
|
return originalFile;
|
||||||
|
}
|
||||||
|
return file;
|
||||||
}))
|
}))
|
||||||
.then(updatedFiles => Promise.all(updatedFiles.map(file => file.save())))
|
.then(updatedFiles => Promise.all(updatedFiles
|
||||||
|
.map(file => file.id ? file.save() : repository.createFile(file))))
|
||||||
.then(() => console.log(`Updated files for ${torrent.title}`));
|
.then(() => console.log(`Updated files for ${torrent.title}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,4 +166,5 @@ async function findAllFiles() {
|
|||||||
//addMissingEpisodes().then(() => console.log('Finished'));
|
//addMissingEpisodes().then(() => console.log('Finished'));
|
||||||
//findAllFiles().then(() => console.log('Finished'));
|
//findAllFiles().then(() => console.log('Finished'));
|
||||||
//updateMovieCollections().then(() => console.log('Finished'));
|
//updateMovieCollections().then(() => console.log('Finished'));
|
||||||
reapplyEpisodeDecomposing().then(() => console.log('Finished'));
|
//reapplyEpisodeDecomposing().then(() => console.log('Finished'));
|
||||||
|
reapplySeriesSeasonsSavedAsMovies().then(() => console.log('Finished'));
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1714,7 +1714,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"parse-torrent-title": {
|
"parse-torrent-title": {
|
||||||
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#d6b677ad5e576c9294de1de75c0fd1396bd1ab7b",
|
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#286c5f9b06a2ac38354ea249a1d96b17919ba930",
|
||||||
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#master"
|
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#master"
|
||||||
},
|
},
|
||||||
"parseurl": {
|
"parseurl": {
|
||||||
|
|||||||
Reference in New Issue
Block a user