video-compressor
Version:
This package is used to reduce the size of the videos in your project. After including this package to the project, you must provide the input and output file paths as parameter of compress method. Later, when you upload video to the path you specified as
38 lines (28 loc) • 979 B
JavaScript
const watch = require('node-watch');
const path = require('path');
const fs = require('fs');
const {input, output} = require('./res/paths');
const getVideosFromFolder = (folder) => {
const files = fs.readdirSync(path.resolve(folder));
return files.filter(founded => founded.match(/.*\.(mp4|avi)/gi));
};
const sync = () => {
const origin = getVideosFromFolder(input);
const dest = getVideosFromFolder(output);
const missingVideos = [];
origin.forEach((v, i) => {
if (!dest.includes(v)) {
missingVideos.push(v);
}
});
return missingVideos;
};
const watchFiles = (call, notify) => {
watch(path.resolve(input), {recursive: false}, function (evt, name) {
if (evt === 'update' && name.match(/.*\.(mp4|avi)/gi)) {
const video = name.split('\\');
call(video[video.length - 1], notify);
}
});
};
module.exports = {watchFiles, sync};