summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--lib/login.js15
-rw-r--r--lib/videos.js8
-rw-r--r--mongo-edu.js27
-rw-r--r--package.json2
5 files changed, 51 insertions, 6 deletions
diff --git a/README.md b/README.md
index 019bb14..b98e9a1 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,6 @@ Options:
-u email address
--py pass switch to point to Python
--ncc no check certificate for py3.x < py3.4.x
- --proxy pass proxy switch
--verbose print debug info
Videos:
@@ -46,6 +45,10 @@ Handouts:
-h switch from videos (default) to handouts
--uz unzip handout files
+Proxy:
+ --proxy pass proxy switch
+ --test use with --proxy to test if usable
+
```
## Select and download
diff --git a/lib/login.js b/lib/login.js
index d7f3fdf..01ecd6d 100644
--- a/lib/login.js
+++ b/lib/login.js
@@ -193,5 +193,20 @@ module.exports = {
callback(new Error(res.statusCode));
});
+ },
+
+ checkProxy: function checkProxy(target, callback) {
+ request(target, function get(err, response) {
+ if (err !== null) { return callback(err); }
+ if (response.statusCode === 200) {
+ var stack = '';
+ if (response.headers.server) { stack = 'Proxy Server: '.bold + response.headers.server.cyan + ' '; }
+ if (response.headers['x-powered-by']) { stack += 'Powered-by: '.bold + response.headers['x-powered-by'].cyan + ' '; }
+ stack.trim();
+ if (stack === '') { stack = target; }
+ return callback(null, stack);
+ }
+ callback(new Error('Server Response: '.red + response.statusCode));
+ });
}
};
diff --git a/lib/videos.js b/lib/videos.js
index a71d4e3..bf8973e 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -325,5 +325,13 @@ module.exports = {
});
+ },
+
+ checkProxyDownload: function checkProxyDownload(argv) {
+ setOptions(argv);
+ var video = 'https://youtu.be/nm20j_x9Ol8', opt = { all: undefined, cancel: undefined };
+ if (typeof argv.test === 'string') { video = argv.test; }
+ opt[video] = 0;
+ handleList([video], opt);
}
};
diff --git a/mongo-edu.js b/mongo-edu.js
index eb49c8b..49f9b24 100644
--- a/mongo-edu.js
+++ b/mongo-edu.js
@@ -10,6 +10,7 @@ var mdbvideos = require('./lib/login'),
videoHandler = require('./lib/videos'),
validate = require('./lib/validate'),
configure = require('./lib/configure'),
+ url = require('url'),
path = require('path'),
colors = require('colors'),
inquirer = require('inquirer'),
@@ -19,6 +20,7 @@ var mdbvideos = require('./lib/login'),
.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', 'proxy address')
+ .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')
@@ -33,7 +35,9 @@ exports.create = function start() {
'use strict';
- var argv = yargs.argv, lookFor = ((!argv.h)? 'Videos' : 'Handouts'), isWin = /^win/.test(process.platform), slash = (isWin) ? '\\' : '/';
+ process.title = 'mongo-edu';
+
+ var argv = yargs.argv, proxyDetails = {}, lookFor = ((!argv.h)? 'Videos' : 'Handouts'), isWin = /^win/.test(process.platform), slash = (isWin) ? '\\' : '/';
if (argv.help) { return yargs.showHelp(); }
@@ -41,14 +45,29 @@ exports.create = function start() {
if (argv.d.substr(-1) !== slash) { argv.d += slash; }
- if (argv.proxy) { console.log('i'.magenta + ' Proxy Video Download: '.bold + argv.proxy.green); }
-
validate.init(argv, function init(err, profile) {
if (err !== null) { throw err; }
configure(argv, function conf(err) {
if (err !== null) { throw err; }
- run(profile);
+
+ if (!argv.proxy) { return run(profile); }
+
+ proxyDetails = url.parse(argv.proxy);
+
+ console.log('i'.magenta + ' Proxy Host: '.bold + proxyDetails.hostname.cyan + ' Port: '.bold + proxyDetails.port.cyan + ' Protocol: '.bold + proxyDetails.protocol.replace(':', '').toUpperCase().cyan);
+
+ 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 (data) { console.log('i'.magenta + ' ' + data); }
+ if (argv.test) { return videoHandler.checkProxyDownload(argv); }
+
+ run(profile);
+ });
+
});
});
diff --git a/package.json b/package.json
index fd90e2f..0bca5d4 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.1.38",
+ "version": "0.1.40",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",