adds sample and extras file filter

This commit is contained in:
TheBeastLT
2020-02-24 22:36:46 +01:00
parent dc65ac62f4
commit 9aad6a5148
3 changed files with 29 additions and 7 deletions

View File

@@ -38,7 +38,9 @@ module.exports.torrentFiles = function (torrent) {
return filesFromTorrentFile(torrent)
.catch(() => filesFromTorrentStream(torrent))
.catch(() => filesFromCache(torrent.infoHash))
.then((files) => files.filter((file) => isVideo(file)));
.then((files) => filterVideos(files))
.then((files) => filterSamples(files))
.then((files) => filterExtras(files));
};
function filesFromCache(infoHash) {
@@ -101,9 +103,22 @@ async function filesFromTorrentStream(torrent) {
});
}
function isVideo(title) {
const match = title.path.match(/\.(\w{2,4})$/);
return match && EXTENSIONS.includes(match[1]);
function filterVideos(files) {
return files.filter((file) => {
const match = file.path.match(/\.(\w{2,4})$/);
return match && EXTENSIONS.includes(match[1]);
});
}
function filterSamples(files) {
const maxSize = Math.max(...files.map(file => file.size));
const isSample = file => file.name.match(/sample/i) && maxSize / file.size < 10;
return files.filter(file => !isSample(file));
}
function filterExtras(files) {
const isSample = file => file.path.match(/extras?\//i);
return files.filter(file => !isSample(file));
}
function dynamicTimeout(torrent) {

View File

@@ -109,11 +109,18 @@ async function findAllFiles() {
// type: Type.SERIES,
// imdbId: 'tt0320037'
// };
/* With extras exceeding season episode count */
// const torrent = {
// infoHash: '2af56a80357b61d839328b986d1165ea8395bbc0',
// title: 'Tim and Eric - Complete',
// type: Type.SERIES,
// imdbId: 'tt0912343'
// };
return parseTorrentFiles(torrent)
.then((files) => console.log(files));
}
//addMissingEpisodes().then(() => console.log('Finished'));
//findAllFiles().then(() => console.log('Finished'));
updateMovieCollections().then(() => console.log('Finished'));
findAllFiles().then(() => console.log('Finished'));
//updateMovieCollections().then(() => console.log('Finished'));

2
package-lock.json generated
View File

@@ -1714,7 +1714,7 @@
}
},
"parse-torrent-title": {
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#0da8a2caeeadb7e20317cd33ad2fc647e4e53d70",
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#91d711a5c3558baced7d20cb5a5458a859ddede6",
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#master"
},
"parseurl": {