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) {