diff options
-rw-r--r-- | lib/courseware.js | 3 | ||||
-rw-r--r-- | lib/videos.js | 14 | ||||
-rw-r--r-- | mongo-edu.js | 8 | ||||
-rw-r--r-- | package.json | 6 |
4 files changed, 18 insertions, 13 deletions
diff --git a/lib/courseware.js b/lib/courseware.js index 08ad194..1a8c0fb 100644 --- a/lib/courseware.js +++ b/lib/courseware.js @@ -23,8 +23,7 @@ function saveData(argv, details, data, callback) { details = details.map(function items(item) { return item.replace(/[^a-z0-9]/gi, '_').replace(/(_){2,}/g, '_'); }); - - fs.writeFile(argv.d + details[0] + '-' + details[1] + '.txt', data.join((!isWin) ? '\n' : '\r\n'), function (err) { + fs.writeFile(argv.d + details[0] + '-' + details[1] + '.txt', data.join((!isWin) ? '\n' : '\r\n'), function write(err) { if (err !== null) { return console.log(err.stack); } console.log('[' + '>'.magenta + '] Video list generated with ' + data.length + ' item' + ((data.length > 1)? 's.' : '.')); diff --git a/lib/videos.js b/lib/videos.js index 48327ac..f64d330 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -18,7 +18,7 @@ var path = require('path'), execFile = require('child_process').execFile, _ = require('lodash'); -var downloadPath = '', ncc = false, handout = false, cc = false, uz = false, hq = false; +var downloadPath = '', downloadList = [], ncc = false, handout = false, cc = false, uz = false, hq = false, isWin = /^win/.test(process.platform); var setOptions = function setOptions(argv) { @@ -124,6 +124,7 @@ var handleList = function handleList(list) { var dl = youtubedl.download(item, downloadPath, opt), bar; dl.on('download', function download(data) { + downloadList.push(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 }); }); @@ -143,7 +144,6 @@ var handleList = function handleList(list) { console.log('[' + '>'.magenta + '] ' + data.filename + '.' + left); } else { console.log('[' + 'i'.green + '] Done in ' + data.timeTakenms + 'ms.' + left); - } } else { console.log('[' + 'i'.red + '] Download Issues'); @@ -153,7 +153,11 @@ var handleList = function handleList(list) { }; if (currentList.length) { return getVideos(currentList.shift()); } - console.log('[ Finished ]'.green); + + 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); + }); }; @@ -260,11 +264,11 @@ module.exports = { if (stderr) { return callback(new Error(stderr.slice(7))); } var data = stdout.trim().split(/\r?\n/); - var out = [], total = data.length, count = 0; + var out = [], total = data.length, count = 0, i; if (data.length) { - for (var i = 0; i < total / 2; i++) { + 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}); } diff --git a/mongo-edu.js b/mongo-edu.js index 68ff39d..5afe4f4 100644 --- a/mongo-edu.js +++ b/mongo-edu.js @@ -77,7 +77,7 @@ exports.create = function start() { if (pass) { return showDetails(err, data); } - list[0].message = 'Found ' + data.length + ' List'+ ((data.length > 1)? 's' : '') + '. Select:'; + list[0].message = 'Found ' + data.length + ' List' + ((data.length > 1)? 's' : '') + '. Select:'; list[0].choices = data; return currentVideos(); @@ -87,9 +87,9 @@ exports.create = function start() { lookFor + ' list is not available.\n\nCheck the start/end date for selected course.\n'); } } - return console.log('[' + 'i'.red + '] Unable to locate any ' + lookFor.toLowerCase() + ' lists in the wiki. Is ' + + return console.log('[' + 'i'.red + '] Unable to locate any ' + lookFor.toLowerCase() + ' lists in the wiki. Are ' + lookFor.toLowerCase() + ' list present in the wiki?' + - (lookFor === 'Videos') ? ' Try to add ' + '--cw'.green + ' to switch and search on courseware instead.' : ''); + ((lookFor === 'Videos') ? ' Try to add ' + '--cw'.green + ' to switch and search on courseware instead.' : '')); }); }); @@ -116,7 +116,9 @@ exports.create = function start() { check[0].choices = data; return inquirer.prompt(check, function prompt(answers) { + videoHandler.download(answers, data, argv); + }); } diff --git a/package.json b/package.json index 6c68336..a00269f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongo-edu", "preferGlobal": true, - "version": "0.1.19", + "version": "0.1.20", "author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)", "description": "Select and download videos and handouts from university.mongodb.com courses", "main": "./mongo-edu", @@ -35,8 +35,8 @@ "youtube-dl": "~1.3.6", "colors": "~0.6.2", "lodash": "~2.4.1", - "cheerio": "~0.16.0", - "inquirer": "~0.5.0", + "cheerio": "~0.17.0", + "inquirer": "~0.5.1", "progress": "~1.1.3", "mkdirp": "~0.5.0", "optimist": "~0.6.1", |