summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2016-01-07 20:03:05 +0000
committerprzemyslawpluta <przemekpluta@hotmail.com>2016-01-07 20:03:05 +0000
commitdd2cf8bd5e90a01466a5934017e2129aeb2b0f51 (patch)
tree3759a0e9994d86eb301904e1bd93b5d5dac0dc78
parent617c52ba5f06bcb3f9a5100347253c7969317101 (diff)
downloadmongo-edu-dd2cf8bd5e90a01466a5934017e2129aeb2b0f51.zip
resume downlod
-rw-r--r--.resume/resume.js15
-rw-r--r--lib/videos.js13
2 files changed, 19 insertions, 9 deletions
diff --git a/.resume/resume.js b/.resume/resume.js
index 5d92f51..385e356 100644
--- a/.resume/resume.js
+++ b/.resume/resume.js
@@ -60,9 +60,15 @@ var ytdl = module.exports = function(videoUrl, args, options) {
});
req.on('response', function(res) {
- if (options && options.start > 0 && res.statusCode == 416) {
+
+ var size = parseInt(res.headers['content-length'], 10);
+ if (size) {
+ item.size = size;
+ }
+
+ if (options && options.start > 0 && res.statusCode === 416) {
// the file that is being resumed is complete.
- stream.emit('end');
+ stream.emit('complete', item);
return;
}
@@ -71,11 +77,8 @@ var ytdl = module.exports = function(videoUrl, args, options) {
return;
}
- var size = parseInt(res.headers['content-length'], 10);
- if (size) {
- item.size = size;
- }
stream.emit('info', item);
+
});
stream.resolve(req);
});
diff --git a/lib/videos.js b/lib/videos.js
index 0f58523..1dde7e1 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -177,12 +177,19 @@ var handleList = function handleList(list, tags) {
stash = info;
if (co) { downloadList.push({id: item, name: path.basename(info._filename)}); }
if (notAvailable) { console.log('i'.magenta + ' No HQ video available for ' + info.fulltitle.white.bold + ' trying default quality ...'); }
- console.log('i'.magenta + ((downloaded > 0) ? ' Resuming download: ' : ' Downloading: ') + info._filename.cyan + ' > ' + item);
- bar = new ProgressBar('>'.green + ' ' + filesize(info.size) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: parseInt(info.size, 10) });
+ console.log('i'.magenta + ((downloaded > 0) ? ' ' + 'Resuming download'.underline + ': ': ' Downloading: ') + info._filename.cyan + ' > ' + item);
+ bar = new ProgressBar('>'.green + ' ' + ((downloaded > 0) ? '[' + filesize(downloaded) + '] ' + filesize(info.size) : filesize(info.size)) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: parseInt(info.size, 10) });
console.time('i'.magenta + ' ' + info._filename + '. Done in');
dl.pipe(fs.createWriteStream(downloadPath + info._filename, {flags: 'a'}));
});
+ dl.on('complete', function(info) {
+ size = info.size + downloaded;
+ stash = info;
+ console.log('i'.magenta + ' File ' + stash._filename.green + ' already downloaded.');
+ console.time('i'.magenta + ' ' + info._filename + '. Done in');
+ });
+
dl.on('data', function(data) {
if (!bar.complete) { bar.tick(data.length); }
});
@@ -201,7 +208,7 @@ var handleList = function handleList(list, tags) {
});
dl.on('end', function end() {
- var left = (currentList.length)? currentList.length + ' left ...' : '';
+ var left = (currentList.length) ? currentList.length + ' left ...' : '';
console.timeEnd('i'.magenta + ' ' + stash._filename + '. Done in');
getSubtitles(item, left, currentList, tags);
});