summaryrefslogtreecommitdiff
path: root/lib/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/videos.js')
-rw-r--r--lib/videos.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/videos.js b/lib/videos.js
index b7480fe..0f58523 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -19,7 +19,7 @@ var path = require('path'),
mv = require('mv'),
_ = require('lodash');
-var isDebug = /[debug]/, downloadPath = '', proxy = '', downloadList = [],
+var isDebug = /[debug]/, downloadPath = '', proxy = '', downloadList = [], hash = {},
co = false, ncc = false, handout = false, cc = false, uz = false, hq = false, verbose = false;
function setOptions(argv) {
@@ -164,17 +164,23 @@ var handleList = function handleList(list, tags) {
if (handout) { return getHandouts(item); }
- var dl = youtubedl(item, nocc || opt, { cwd: downloadPath }), size = 0, stash = {}, bar;
+ var downloaded = 0, size = 0, stash = {}, bar;
+
+ if (fs.existsSync(downloadPath + hash[item])) {
+ downloaded = fs.statSync(downloadPath + hash[item]).size;
+ }
+
+ var dl = youtubedl(item, nocc || opt, {start: downloaded, cwd: downloadPath});
dl.on('info', function(info) {
- size = info.size;
+ size = info.size + downloaded;
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 + ' Downloading: ' + info._filename.cyan + ' > ' + item);
- bar = new ProgressBar('>'.green + ' ' + filesize(size) + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: parseInt(size, 10) });
+ 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.time('i'.magenta + ' ' + info._filename + '. Done in');
- dl.pipe(fs.createWriteStream(downloadPath + info._filename));
+ dl.pipe(fs.createWriteStream(downloadPath + info._filename, {flags: 'a'}));
});
dl.on('data', function(data) {
@@ -201,7 +207,9 @@ var handleList = function handleList(list, tags) {
});
};
- if (currentList.length) { return getVideos(currentList.shift()); }
+ if (currentList.length) {
+ return getVideos(currentList.shift());
+ }
if (co) {
@@ -259,6 +267,8 @@ module.exports = {
if (verbose && isDebug.test(err)) { console.log(err); }
+ hash[item] = info._filename;
+
items.push((!err)?{name: info.fulltitle + ' - ' + info.width + 'x' + info.height, value: item, id: i}:{name: 'No info: ' + item, value: item, id: i});
count = count - 1;