-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideoIndexer.js
More file actions
42 lines (37 loc) · 1.07 KB
/
videoIndexer.js
File metadata and controls
42 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const path = require('path');
function indexVideos(folders) {
try {
console.log(folders);
let videos = [];
const videoExtensions = ['.mp4', '.webm', '.mkv', '.avi', '.mov', '.flv'];
folders.forEach(folder => {
const files = walkSync(folder);
files.forEach(file => {
if (videoExtensions.includes(path.extname(file).toLowerCase()) &&
fs.existsSync(file)) {
videos.push(file);
}
});
});
return videos;
} catch (error) {
console.error('Error in indexVideos:', error);
return [];
}
}
function walkSync(dir) {
let files = [];
const list = fs.readdirSync(dir);
list.forEach(file => {
file = path.join(dir, file);
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
files = files.concat(walkSync(file));
} else {
files.push(file);
}
});
return files;
}
module.exports = { indexVideos };