const { exec } = require('child_process'); var install = {}; install.init = (cb) => { var url = [ ['ffmpeg', 'https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz'], ['youtube-dl', 'https://yt-dl.org/downloads/latest/youtube-dl'] ] var download = (i) => { install.download(url[i], function(path) { switch (i) { case 0: shell. break; default: } if (i < url.length - 1) { download(i++); } else { cb(); } }) }; download(0) } install.download = (url, cb) => { var r = request(url); var actual = 1; var full = 100; var perc = 0; r.on('data', function(chunk) { actual += chunk.length; perc = actual / full * 100; console.log(perc); libs.listen.sender.send('progress', { percent: Math.floor(perc) }); }); r.on('response', function(res) { var path = global.dir + '/tmp/' + url.split('/')[url.split('/').length - 1]; res.pipe(fs.createWriteStream(path)); full = res.headers['content-length']; res.on('end', function() { cb(path); }) }); }