remove the variable "files" and use "mp4" instead

Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
loicbersier 2020-07-19 11:56:33 +02:00
parent 6da1ba9cfb
commit 4891189daf

View file

@ -186,18 +186,18 @@ class ytpCommand extends Command {
// Read userVid folder and select random vid and only take .mp4
let mp4 = [];
let asset = [];
let files = fs.readdirSync('./asset/ytp/userVid/');
// Count number of total vid
files.forEach(file => {
fs.readdirSync('./asset/ytp/userVid/').forEach(file => {
if (file.endsWith('mp4')) {
mp4.push(file);
}
});
// Select random vid depending on the amount of MAX_CLIPS
for (let i = 0; i < MAX_CLIPS; i++) {
let random = Math.floor(Math.random() * files.length);
let vid = `./asset/ytp/userVid/${files[random]}`;
if (files[random].endsWith('mp4')) {
let random = Math.floor(Math.random() * mp4.length);
let vid = `./asset/ytp/userVid/${mp4[random]}`;
if (mp4[random].endsWith('mp4')) {
if (!asset.includes(vid)) {
asset.push(vid);
}