diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | lib/login.js | 3 | ||||
-rw-r--r-- | lib/options.js | 40 | ||||
-rw-r--r-- | lib/videos.js | 3 | ||||
-rw-r--r-- | mongo-edu.js | 41 |
5 files changed, 61 insertions, 27 deletions
@@ -19,3 +19,4 @@ mongo-edu.wiki .DS_Store node_modules +bin/*.json diff --git a/lib/login.js b/lib/login.js index 01ecd6d..9194dba 100644 --- a/lib/login.js +++ b/lib/login.js @@ -196,6 +196,9 @@ module.exports = { }, checkProxy: function checkProxy(target, callback) { + + 'use strict'; + request(target, function get(err, response) { if (err !== null) { return callback(err); } if (response.statusCode === 200) { diff --git a/lib/options.js b/lib/options.js new file mode 100644 index 0000000..42e2616 --- /dev/null +++ b/lib/options.js @@ -0,0 +1,40 @@ +/* + * mongo-edu + * + * Copyright (c) 2014 Przemyslaw Pluta + * Licensed under the MIT license. + * https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE + */ + +var yargs = require('yargs') + .usage('Usage: $0 [options]') + .describe('d', 'download path').describe('u', 'email address') + .describe('h', 'switch from videos (default) to handouts').boolean('h') + .describe('py', 'py switch').describe('py', 'switch to point to Python') + .describe('proxy', 'pass proxy').describe('proxy', 'pass proxy switch for video download') + .describe('test', 'proxy test').describe('test', 'use with --proxy to test if usable') + .describe('cw', 'switch from wiki\'s video lists (default) to courseware').boolean('cw') + .describe('cwd', 'same as --cw and dumps list of videos to file in -d').boolean('cwd') + .describe('cc', 'get closed captions').boolean('cc') + .describe('hq', 'get high quality videos').boolean('hq') + .describe('ncc', 'no check certificate').boolean('ncc') + .describe('uz', 'unzip handout files').boolean('uz') + .describe('co', 'sequence video files in order of the courseware').boolean('co') + .describe('verbose', 'print debug information').boolean('verbose') + .example('$0 -d your_download_path', 'download videos from wiki') + .example('$0 -d your_download_path -u your_user_name --cw --hq --cc', 'download high quality videos from courseware with closed captions') + .example('$0 -d your_download_path -h --uz', 'download and unzip handouts') + .example('$0 -d your_download_path --cw --verbose', 'download videos from courseware and print debug info') + .example('$0 -d your_download_path --cw --proxy http://proxy_ip_address:proxy_port_number', 'download videos from courseware via proxy tunnel') + .example('$0 -d your_download_path --proxy http://proxy_ip_address:proxy_port_number --test', 'test proxy and download video via proxy tunnel') + .demand('d'); + +module.exports = (function init() { + + 'use strict'; + + return { + build: function build() { return yargs; }, + }; + +}()); diff --git a/lib/videos.js b/lib/videos.js index bf8973e..c5d4806 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -328,6 +328,9 @@ module.exports = { }, checkProxyDownload: function checkProxyDownload(argv) { + + 'use strict'; + setOptions(argv); var video = 'https://youtu.be/nm20j_x9Ol8', opt = { all: undefined, cancel: undefined }; if (typeof argv.test === 'string') { video = argv.test; } diff --git a/mongo-edu.js b/mongo-edu.js index 33d8802..fcee4ef 100644 --- a/mongo-edu.js +++ b/mongo-edu.js @@ -6,42 +6,25 @@ * https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE */ -var mdbvideos = require('./lib/login'), +var pkg = require('./package'), + mdbvideos = require('./lib/login'), videoHandler = require('./lib/videos'), validate = require('./lib/validate'), configure = require('./lib/configure'), + optArgs = require('./lib/options'), + yargs = optArgs.build(), url = require('url'), path = require('path'), colors = require('colors'), - inquirer = require('inquirer'), - yargs = require('yargs') - .usage('Usage: $0 [options]') - .describe('d', 'download path').describe('u', 'email address') - .describe('h', 'switch from videos (default) to handouts').boolean('h') - .describe('py', 'py switch').describe('py', 'switch to point to Python') - .describe('proxy', 'pass proxy').describe('proxy', 'pass proxy switch for video download') - .describe('test', 'proxy test').describe('test', 'use with --proxy to test if usable') - .describe('cw', 'switch from wiki\'s video lists (default) to courseware').boolean('cw') - .describe('cwd', 'same as --cw and dumps list of videos to file in -d').boolean('cwd') - .describe('cc', 'get closed captions').boolean('cc') - .describe('hq', 'get high quality videos').boolean('hq') - .describe('ncc', 'no check certificate').boolean('ncc') - .describe('uz', 'unzip handout files').boolean('uz') - .describe('co', 'sequence video files in order of the courseware').boolean('co') - .describe('verbose', 'print debug information').boolean('verbose') - .example('$0 -d your_download_path', 'download videos from wiki') - .example('$0 -d your_download_path -u your_user_name --cw --hq --cc', 'download high quality videos from courseware with closed captions') - .example('$0 -d your_download_path -h --uz', 'download and unzip handouts') - .example('$0 -d your_download_path --cw --verbose', 'download videos from courseware and print debug info') - .example('$0 -d your_download_path --cw --proxy http://proxy_ip_address:proxy_port_number', 'download videos from courseware via proxy tunnel') - .example('$0 -d your_download_path --proxy http://proxy_ip_address:proxy_port_number --test', 'test proxy and download video via proxy tunnel') - .demand('d'); + inquirer = require('inquirer'); exports.create = function start() { 'use strict'; - process.title = 'mongo-edu'; + process.title = pkg.name; + + console.log('\n[ ' + pkg.name.toUpperCase() + ' ' + pkg.version + ' ]\n'); var argv = yargs.argv, proxyDetails = {}, lookFor = ((!argv.h)? 'Videos' : 'Handouts'), isWin = /^win/.test(process.platform), slash = (isWin) ? '\\' : '/'; @@ -57,7 +40,7 @@ exports.create = function start() { configure(argv, function conf(err) { if (err !== null) { throw err; } - if (!argv.proxy) { return run(profile); } + if (!argv.proxy || argv.h) { return run(profile); } proxyDetails = url.parse(argv.proxy); @@ -65,7 +48,11 @@ exports.create = function start() { mdbvideos.checkProxy(argv.proxy, function get(err, data) { if (err !== null) { - (argv.verbose) ? console.log('i'.red + ' Proxy Error: '.red + err.stack) : console.log('i'.red + ' Proxy Might By Unusable.'.red); + if (argv.verbose) { + console.log('i'.red + ' Proxy Error: '.red + err.stack); + } else { + console.log('i'.red + ' Proxy Might By Unusable.'.red); + } } if (data) { console.log('i'.magenta + ' ' + data); } |