mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
adds sample and extras file filter
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user