[scraper] move is-video function to a file

This commit is contained in:
TheBeastLT
2020-03-17 19:28:43 +01:00
parent 78b3dda9e3
commit d26764fce9
2 changed files with 24 additions and 6 deletions

View File

@@ -4,11 +4,10 @@ const parseTorrent = require('parse-torrent');
const async = require('async');
const decode = require('magnet-uri');
const { retrieveTorrentFiles } = require('./cache');
const isVideo = require('./video');
const MAX_PEER_CONNECTIONS = process.env.MAX_PEER_CONNECTIONS || 20;
const SEEDS_CHECK_TIMEOUT = process.env.SEEDS_CHECK_TIMEOUT || 10 * 1000; // 10 secs
const EXTENSIONS = ["3g2", "3gp", "avi", "flv", "mkv", "mov", "mp2", "mp4", "mpe", "mpeg", "mpg", "mpv", "webm", "wmv",
"ogm"];
module.exports.updateCurrentSeeders = function (torrent) {
return new Promise((resolve) => {
@@ -110,10 +109,7 @@ async function filesFromTorrentStream(torrent) {
}
function filterVideos(files) {
return files.filter((file) => {
const match = file.path.match(/\.(\w{2,4})$/);
return match && EXTENSIONS.includes(match[1].toLowerCase());
});
return files.filter((file) => isVideo(file.path));
}
function filterSamples(files) {

22
scraper/lib/video.js Normal file
View File

@@ -0,0 +1,22 @@
const EXTENSIONS = [
"3g2",
"3gp",
"avi",
"flv",
"mkv",
"mov",
"mp2",
"mp4",
"mpe",
"mpeg",
"mpg",
"mpv",
"webm",
"wmv",
"ogm"
];
module.exports = (filename) => {
const extensionMatch = filename.match(/\.(\w{2,4})$/);
return extensionMatch && EXTENSIONS.includes(extensionMatch[1].toLowerCase());
};