summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2014-06-17 21:23:17 +0100
committerprzemyslawpluta <przemekpluta@hotmail.com>2014-06-17 21:23:17 +0100
commit41613273d989a75c73c14d8aab1de03482355bde (patch)
tree16f5da8d0bb4457153733a739a6709826a8b526a
parent46deff1d567dc357b5693650aed059852e204496 (diff)
downloadmongo-edu-41613273d989a75c73c14d8aab1de03482355bde.zip
update
add video files sequencing with --co instead of dump err handling with unzip fail cleanup and update subs version bump
-rw-r--r--README.md2
-rw-r--r--lib/videos.js64
-rw-r--r--mongo-edu.js2
-rw-r--r--package.json5
4 files changed, 52 insertions, 21 deletions
diff --git a/README.md b/README.md
index 15ebec3..1b2f1c8 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ Options:
--py pass switch to point to Python
--cw switch from wiki video lists (default) to courseware
--cwd same as --cw and dumps list of videos to file in -d
- --co dump course order list to file in -d
+ --co sequence video files in order of the course
--cc get closed captions
--hq get high quality videos
--ncc no check certificate for py3.x < py3.4.x
diff --git a/lib/videos.js b/lib/videos.js
index 9d2328b..b15d16e 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -15,12 +15,14 @@ var path = require('path'),
progress = require('request-progress'),
colors = require('colors'),
unzip = require('unzip'),
+ rimraf = require('rimraf'),
+ mv = require('mv'),
execFile = require('child_process').execFile,
_ = require('lodash');
var downloadPath = '', downloadList = [], co = false, ncc = false, handout = false, cc = false, uz = false, hq = false, isWin = /^win/.test(process.platform);
-var setOptions = function setOptions(argv) {
+function setOptions(argv) {
'use strict';
@@ -31,17 +33,35 @@ var setOptions = function setOptions(argv) {
if (argv.uz) { uz = true; }
if (argv.hq) { hq = true; }
if (argv.co) { co = true; }
-};
+}
-var handleList = function handleList(list) {
+function rename(downloadPath, item, id, count, pass) {
+
+ 'use strict';
+
+ var tag = (id + 1);
+
+ if (tag < 10) { tag = '00' + tag; }
+ if (tag >= 10 && tag < 100) { tag = '0' + tag; }
+
+ mv(downloadPath + item, downloadPath + tag + '_' + item, function move() {
+ if (cc && !pass) {
+ var subtitle = path.basename(item, path.extname(item)) + '.en.srt';
+ return rename(downloadPath, subtitle, id, count, true);
+ }
+ if (count === 0) { console.log('[ Finished ]'.green); }
+ });
+}
+
+var handleList = function handleList(list, tags) {
'use strict';
var currentList = list,
quality = (!hq) ? '18' : '22',
- opt = (!ncc) ? ['--max-quality=' + quality] : ['--max-quality=' + quality, '--no-check-certificate'];
+ opt = (!ncc) ? ['--max-quality=' + quality] : ['--max-quality=' + quality, '--no-check-certificate'], i, count;
- if (cc) { opt = opt.concat(['--write-srt', '--srt-lang=en']); }
+ if (cc) { opt = opt.concat(['--write-sub', '--srt-lang=en']); }
var getHandouts = function getHandouts(item) {
@@ -78,7 +98,8 @@ var handleList = function handleList(list) {
unzipFile = fs.createReadStream(downloadPath + name).pipe(unzip.Extract({ path: downloadPath + path.basename(name, extname) }));
unzipFile.on('error', function error() {
- console.log('[' + 'i'.red + '] Unable to unzip the: ' + name + '.');
+ console.log('[' + 'i'.red + '] Unable to unzip ' + name.red + ' try manually.');
+ rimraf(downloadPath + name.replace('.zip', ''), function rf() { nextItem(currentList); });
});
unzipFile.on('close', function close() {
@@ -125,7 +146,7 @@ var handleList = function handleList(list) {
var dl = youtubedl.download(item, downloadPath, opt), bar;
dl.on('download', function download(data) {
- if (co) { downloadList.push(path.basename(data.filename)); }
+ 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 });
});
@@ -149,19 +170,24 @@ var handleList = function handleList(list) {
} else {
console.log('[' + 'i'.red + '] Download Issues');
}
- handleList(currentList);
+ handleList(currentList, tags);
});
};
if (currentList.length) { return getVideos(currentList.shift()); }
if (co) {
- fs.writeFile(downloadPath + 'Course_Order.txt', downloadList.join((!isWin) ? '\n' : '\r\n'), function write(err) {
- if (err !== null) { console.log(err.stack); }
- console.log('[ Finished ]'.green);
- });
+
+ count = downloadList.length;
+
+ for (i = 0; i < downloadList.length; i++) {
+ count = count -1;
+ rename(downloadPath, downloadList[i].name, tags[downloadList[i].id], count);
+ }
+
} else {
console.log('[ Finished ]'.green);
+ process.exit(0);
}
};
@@ -232,19 +258,24 @@ module.exports = {
setOptions(argv);
- var options = opt.videos, fullList = [], selected = [];
+ var i, options = opt.videos, fullList = [], selected = [], tags = {};
+
+ for (i = 0; i < list.length; i++) {
+ tags[list[i].value] = list[i].id;
+ }
if (options.length === 1 && options[0] === 'cancel') { return console.log('Cancel'); }
if (options.length === 1 && options[0] === 'all') {
fullList = _.pull(_.map(list, function map(item) { return item.value; }), 'all', 'cancel');
- return handleList(fullList);
+
+ return handleList(fullList, tags);
}
if (options.length >= 1) {
selected = _.pull(options, 'all', 'cancel');
- if (selected.length) { return handleList(selected); }
+ if (selected.length) { return handleList(selected, tags); }
}
},
@@ -256,8 +287,7 @@ module.exports = {
var args = [opt.url, '--get-id', '--get-title'];
args = (!argv.ncc) ? args : args.concat(['--no-check-certificate']);
- var isWin = /^win/.test(process.platform),
- file = path.join(__dirname, '..', 'node_modules/youtube-dl/bin', 'youtube-dl'),
+ var file = path.join(__dirname, '..', 'node_modules/youtube-dl/bin', 'youtube-dl'),
options = [file, args];
setOptions(argv);
diff --git a/mongo-edu.js b/mongo-edu.js
index f3b8cea..e65e9f5 100644
--- a/mongo-edu.js
+++ b/mongo-edu.js
@@ -24,7 +24,7 @@ var mdbvideos = require('./lib/login'),
.describe('hq', 'get high quality videos').boolean('hq')
.describe('ncc', 'no check certificate').boolean('ncc')
.describe('uz', 'unzip handout files').boolean('uz')
- .describe('co', 'dump course order list').boolean('co')
+ .describe('co', 'sequence video files in order of the course').boolean('co')
.demand('d');
exports.create = function start() {
diff --git a/package.json b/package.json
index 5653622..3a68d69 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.1.22",
+ "version": "0.1.23",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",
@@ -40,9 +40,10 @@
"mkdirp": "~0.5.0",
"mv": "~2.0.0",
"optimist": "~0.6.1",
- "progress": "~1.1.3",
+ "progress": "~1.1.6",
"request": "~2.36.0",
"request-progress": "~0.3.1",
+ "rimraf": "~2.2.8",
"semver": "~2.3.0",
"unzip": "~0.1.9",
"which": "~1.0.5",