diff --git a/lib/torrent.js b/lib/torrent.js index a7e8bee..e0bf46b 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -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) { diff --git a/manual/manual.js b/manual/manual.js index b1ef44b..d5a9220 100644 --- a/manual/manual.js +++ b/manual/manual.js @@ -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')); \ No newline at end of file +findAllFiles().then(() => console.log('Finished')); +//updateMovieCollections().then(() => console.log('Finished')); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 82c3672..108b348 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": {