diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/courseware.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/courseware.js b/lib/courseware.js index 2431284..08ad194 100644 --- a/lib/courseware.js +++ b/lib/courseware.js @@ -10,20 +10,31 @@ var fs = require('fs'), request = require('request'), cheerio = require('cheerio'), ProgressBar = require('progress'), + inquirer = require('inquirer'), colors = require('colors'), _ = require('lodash'); var isWin = /^win/.test(process.platform), camo = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36' }; -function saveData(argv, details, data) { +function saveData(argv, details, data, callback) { 'use strict'; 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) { if (err !== null) { return console.log(err.stack); } + + console.log('[' + '>'.magenta + '] Video list generated with ' + data.length + ' item' + ((data.length > 1)? 's.' : '.')); + + inquirer.prompt({type: 'confirm', name: 'download', message: 'Select and download?'}, function prompt(answers) { + if (answers.download) { return callback(null, data); } + console.log('[ Finished ]'.green); + process.exit(0); + }); + }); } @@ -63,8 +74,11 @@ function getDetails(jar, count, bar, head, argv, callback) { bar.tick(); if (count === 0) { out = _.map(_.sortBy(_.flatten(list), 'id'), function map(item) { return item.video; }); - if (argv.cwd) { saveData(argv, head, out); } - return callback(null, out); + if (argv.cwd) { + saveData(argv, head, out, callback); + } else { + callback(null, out); + } } }); } |