summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2014-07-31 22:59:08 +0100
committerprzemyslawpluta <przemekpluta@hotmail.com>2014-07-31 22:59:08 +0100
commit28a807a7c1da7d6bf38dd8d4c8aa5c568767b123 (patch)
tree4204819850c49e9235fcbf588f27ba0a0829f895
parentc3af0ab36fd0aa379f106a9b27f7f1b0e3231672 (diff)
downloadmongo-edu-28a807a7c1da7d6bf38dd8d4c8aa5c568767b123.zip
update
upgrade to youtube-dl 1.5.8 cleanup
-rw-r--r--lib/videos.js71
-rw-r--r--package.json5
2 files changed, 34 insertions, 42 deletions
diff --git a/lib/videos.js b/lib/videos.js
index b15d16e..56ebbaf 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -139,37 +139,40 @@ var handleList = function handleList(list, tags) {
},
- getVideos = function getVideos(item) {
+ getVideos = function getVideos(item, nocc) {
if (handout) { return getHandouts(item); }
- var dl = youtubedl.download(item, downloadPath, opt), bar;
+ var dl = youtubedl(item, nocc || opt, { cwd: downloadPath }), size = 0, pos = 0, stash = {}, bar;
- dl.on('download', function download(data) {
- if (co) { downloadList.push({id: item, name: path.basename(data.filename)}); }
- console.log('[' + 'i'.magenta + '] Downloading: ' + data.filename.cyan + ' > ' + item);
- bar = new ProgressBar('[' + '>'.green + '] ' + data.size + ' [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: 100.0 });
+ 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 });
+ console.time('[' + 'i'.magenta + '] Done in');
+ dl.pipe(fs.createWriteStream(downloadPath + info.filename));
});
- dl.on('progress', function progress(data) {
- if (!bar.complete) { bar.tick(parseInt(data.percent, 10)); }
+ dl.on('data', function(data) {
+ pos += data.length;
+ var percent = (pos / size * 100).toFixed(2);
+ if (!bar.complete) { bar.tick(parseInt(percent, 10)); }
});
dl.on('error', function error(err) {
- return console.log(err.stack);
+ if (err.message.indexOf('video doesn\'t have subtitles') !== -1) {
+ console.log('[' + 'i'.magenta + '] No Closed Captions Available For: ' + stash.filename.cyan + ' > ' + item);
+ return getVideos(item, _.without(opt, '--write-sub', '--srt-lang=en'));
+ }
+ console.log(err.stack);
});
- dl.on('end', function end(data) {
+ dl.on('end', function end() {
var left = (currentList.length)? ' ' + currentList.length + ' left ...' : '';
- if (data.filename) {
- if (data.filename.indexOf('has already been downloaded') !== -1) {
- console.log('[' + '>'.magenta + '] ' + data.filename + '.' + left);
- } else {
- console.log('[' + 'i'.green + '] Done in ' + data.timeTakenms + 'ms.' + left);
- }
- } else {
- console.log('[' + 'i'.red + '] Download Issues');
- }
+ console.log('[' + '>'.magenta + '] ' + stash.filename + '.' + left);
+ console.timeEnd('[' + 'i'.magenta + '] Done in');
handleList(currentList, tags);
});
};
@@ -284,34 +287,24 @@ module.exports = {
'use strict';
- var args = [opt.url, '--get-id', '--get-title'];
- args = (!argv.ncc) ? args : args.concat(['--no-check-certificate']);
-
- var file = path.join(__dirname, '..', 'node_modules/youtube-dl/bin', 'youtube-dl'),
- options = [file, args];
-
setOptions(argv);
- if (isWin) { options = [process.env.PYTHON, [file].concat(args)]; }
+ var options = (!ncc) ? [] : ['--no-check-certificate'], items = [], i, item;
- execFile(options[0], options[1], function(err, stdout, stderr) {
- if (err !== null) { return callback(err); }
- if (stderr) { return callback(new Error(stderr.slice(7))); }
+ youtubedl.getInfo(opt.url, options, function(err, info) {
- var data = stdout.trim().split(/\r?\n/);
- var out = [], total = data.length, count = 0, i;
-
- if (data.length) {
-
- for (i = 0; i < total / 2; i++) {
- count = count + 1;
- out.push({ name: data.shift(), value: 'https://www.youtube.com/watch?v=' + data.shift(), id: count});
+ if (info.length) {
+ for (i = 0; i < info.length; i++) {
+ item = 'https://www.youtube.com/watch?v=' + info[i].id;
+ items.push((!err)?{name: info[i].title + ' - ' + info[i].resolution, value: item, id: i}:{name: 'No info: ' + item, value: item, id: i});
}
- out.unshift({name: 'All', value: 'all', checked: true}, {name: 'Cancel', value: 'cancel'});
+ items.unshift({name: 'All', value: 'all', checked: true}, {name: 'Cancel', value: 'cancel'});
}
- callback(null, out, true);
+ callback(null, items, true);
+
});
+
}
};
diff --git a/package.json b/package.json
index adffbb3..28c8965 100644
--- a/package.json
+++ b/package.json
@@ -6,8 +6,7 @@
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",
"scripts": {
- "start": "node ./bin/mongo-edu",
- "install": "node ./scripts/winpy3fix.js"
+ "start": "node ./bin/mongo-edu"
},
"bin": {
"mongo-edu": "./bin/mongo-edu"
@@ -46,7 +45,7 @@
"rimraf": "~2.2.8",
"unzip": "~0.1.9",
"which": "~1.0.5",
- "youtube-dl": "~1.3.6"
+ "youtube-dl": "~1.5.8"
},
"engines": {
"node": ">= 0.8.x"