-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
93 lines (83 loc) · 2.28 KB
/
helpers.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const fs = require('fs');
const videos = require('./videos');
const STD_MSG = '[MSG helpers] ';
const DEMUXER_LIST_PATH = '../bin/list.txt';
exports.DEF_VID_PATH = './bin/out0.mp4';
//replaces extra chars w/ underscore
exports.replace = function (link){
return link.replace(/[^a-z0-9\-]/gi, '_');
}
//clears out all files in bin folder
exports.cleanBin = function(){
}
//if a path exists, delete the file at the end of the path
exports.deleteIfExists = function(path){
try{
if(fs.existsSync(path)){
console.log(STD_MSG, `Deleting file at: ${path}`);
fs.unlinkSync(path);
console.log(STD_MSG, path + ' deleted')
}
}catch(err){
console.error('ERR - deleteIfExists: ' + err);
}
}
exports.exists = function(path){
try{
if(fs.existsSync(path))
return true;
else
return false;
}catch(err){
console.error('ERR - exists: ' + err);
}
}
//when a video is completely downloaded it's path will be entered
exports.waitTillAllDownloaded = async function(){
console.log('checking videos');
return new Promise(resolve => {
function checkAllDownloaded(){
if(videos.allDownloaded()){
console.log(STD_MSG, 'all downloaded');
resolve();
}else{
console.log(STD_MSG, 'still downloading');
setTimeout(checkAllDownloaded, 5000);
}
}
checkAllDownloaded();
});
/*for(var i=0; i<videos.count(); i++){
if(videos.getVideoPath(i) == false){
console.log(`video ${i} not ready`);
setTimeout(exports.waitTillAllDownloaded, 5000);
break;
}else{
console.log(`video ${i} ready: ${videos.getVideoPath(i)}`);
}
}*/
}
exports.waitTillReady = async function(){
return new Promise(resolve =>{
function checkVidPath(){
if(videos.allReady()==true){
console.log(STD_MSG, 'actually all ready!');
resolve();
}else{
console.log(STD_MSG, 'waiting a little longer for ready');
setTimeout(checkVidPath, 2000);
}
}
checkVidPath();
});
}
// Creating list of file paths for ffmpeg demuxer
// to put files together
exports.createDemuxerList = function (){
const v = videos.getAll();
let txt = '';
for(video in v){
txt += `file '${(v[video].clipPath).substring(1)}'\n`;
}
fs.writeFileSync(DEMUXER_LIST_PATH, txt);
}