-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexts.js
71 lines (63 loc) · 1.56 KB
/
exts.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var fs = require('fs');
var path = require('path');
var ext = {
video : [
".mpg",
".mpeg",
".avi",
".wmv",
".mov",
".flv",
".ogg",
".webm",
".mp4"
],
audio : [
".mid",
".midi",
".wma",
".aac",
".wav",
".ogg",
".mp3",
]
}
var bannedDirs = [
];
var fromDir = function(startPath, callback){
//console.log('Starting from dir '+startPath+'/');
if (!fs.existsSync(startPath)){
console.log("no dir ",startPath);
return;
}
var files=fs.readdirSync(startPath);
for(var i=0;i<files.length;i++){
try{
var filename=path.join(startPath,files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory() && bannedDirs.indexOf(filename) === -1 && bannedDirs.indexOf(files[i]) === -1&& files[i][0] !="."){
// console.log(filename + bannedDirs.indexOf(filename));
fromDir(filename, callback); //recurse
}
else if (ext.video.indexOf(path.extname(filename))>-1) {
console.log('-- found video: ',filename);
callback("video", filename, files[i]);
}
else if (ext.audio.indexOf(path.extname(filename))>-1) {
console.log('-- found music: ',filename);
// console.log(typeof(callback));
// console.log(callback);
callback("audio", filename, files[i]);
};
}
catch(err){
// console.log(err);
}
};
};
var getAsync = function(startPath, callback){
setTimeout(function(){
fromDir(startPath, callback);
}, -1);
};
exports.find = getAsync;