forked from cbmsc-diti/mogi-server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
correctVideoDuration.js
42 lines (38 loc) · 1.06 KB
/
correctVideoDuration.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
var
db = require('./lib/db'),
storage = require('./lib/videos/storage');
//search for all videos which have 0 or 1 as duration.
console.log('will start looking for videos');
db.video.findAll({where: {$or: [{duration: 0}, {duration: 1}]}}).then(function(videos){
//find the mp4 files
i = videos.length-1;
console.log(".");
correct(videos, i);
});
function correct(videos, i){
if (i == 0){
console.log('finalized');
return;
}
var video = videos[i];
//check if the file exists
if (!storage.exists(video)) {
//if it doesn't, mark the video as deleted
console.log("video does not exists");
correct(videos, i-1);
} else {
//if it does, check the metadata.
storage.getTotalDuration(video, function(duration){
console.log("new duration for video: "+duration+" - "+this.id);
//include the metadata in the
if (Math.ceil(duration) == 0){
this.isValid = false;
} else {
this.duration = Math.ceil(duration);
this.isValid = true;
}
this.save();
correct(videos, i-1);
});
}
}