From a21a4b3a7c2ef621899ff10f88cfcc50644a1514 Mon Sep 17 00:00:00 2001 From: przemyslawpluta Date: Thu, 11 Sep 2014 21:03:45 +0100 Subject: update progress bar fix version bump --- lib/videos.js | 19 ++++++++++--------- package.json | 4 ++-- 2 files changed, 12 insertions(+), 11 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) { diff --git a/package.json b/package.json index 00812e1..c645ae0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongo-edu", "preferGlobal": true, - "version": "0.1.34", + "version": "0.1.35", "author": "Przemyslaw Pluta (http://przemyslawpluta.com)", "description": "Select and download videos and handouts from university.mongodb.com courses", "main": "./mongo-edu", @@ -43,7 +43,7 @@ "request": "~2.42.0", "request-progress": "~0.3.1", "rimraf": "~2.2.8", - "unzip": "~0.1.9", + "unzip": "^0.1.11", "which": "~1.0.5", "youtube-dl": "~1.5.13" }, -- cgit v1.2.3