diff options
author | przemyslawpluta <przemekpluta@hotmail.com> | 2014-09-11 21:03:45 +0100 |
---|---|---|
committer | przemyslawpluta <przemekpluta@hotmail.com> | 2014-09-11 21:03:45 +0100 |
commit | a21a4b3a7c2ef621899ff10f88cfcc50644a1514 (patch) | |
tree | 54ba0bb7953e715152df40591c4fa57971d7f27b /lib | |
parent | a758fb345b3f4ce4e231f8ed2ddd4d9b5f5fef3a (diff) | |
download | mongo-edu-a21a4b3a7c2ef621899ff10f88cfcc50644a1514.zip |
update
progress bar fix
version bump
Diffstat (limited to 'lib')
-rw-r--r-- | lib/videos.js | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/videos.js b/lib/videos.js index 0980e36..19f1730 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -64,7 +64,7 @@ var handleList = function handleList(list, tags) { var getHandouts = function getHandouts(item) { - var name = path.basename(item), bar, dounloadFile, dlh, left, extname, unzipFile, + var name = path.basename(item), bar, dounloadFile, dlh, left, extname, unzipFile, progressSoFar = -1, hold = 0, downloadItem = function downloadItem() { @@ -73,10 +73,13 @@ var handleList = function handleList(list, tags) { console.log('[' + 'i'.magenta + '] Downloading: ' + name.cyan); dlh.on('progress', function(state) { - if (!bar) { - bar = new ProgressBar('[' + '>'.green + '] ' + filesize(state.total) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: 100.0 }); + if (!bar) { bar = new ProgressBar('[' + '>'.green + '] ' + filesize(state.total) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: 100 }); } + if (!bar.complete && progressSoFar !== state.percent) { + var i; + for (i = 0; i < (state.percent - hold); i++) { bar.tick(); } + hold = state.percent; } - if (!bar.complete) { bar.tick(parseInt(state.percent, 10)); } + progressSoFar = state.percent; }); dlh.on('error', function error(err) { @@ -142,22 +145,20 @@ var handleList = function handleList(list, tags) { if (handout) { return getHandouts(item); } - var dl = youtubedl(item, nocc || opt, { cwd: downloadPath }), size = 0, pos = 0, stash = {}, bar; + var dl = youtubedl(item, nocc || opt, { cwd: downloadPath }), size = 0, stash = {}, bar; dl.on('info', function(info) { size = info.size; stash = info; if (co) { downloadList.push({id: item, name: path.basename(info.filename)}); } console.log('[' + 'i'.magenta + '] Downloading: ' + info.filename.cyan + ' > ' + item); - bar = new ProgressBar('[' + '>'.green + '] ' + filesize(size) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: 100.0 }); + bar = new ProgressBar('[' + '>'.green + '] ' + filesize(size) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: parseInt(size, 10) }); console.time('[' + 'i'.magenta + '] ' + info.filename + '. Done in'); dl.pipe(fs.createWriteStream(downloadPath + info.filename)); }); dl.on('data', function(data) { - pos += data.length; - var percent = (pos / size * 100).toFixed(2); - if (!bar.complete) { bar.tick(parseInt(percent, 10)); } + if (!bar.complete) { bar.tick(data.length); } }); dl.on('error', function error(err) { |