summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2014-03-27 21:11:46 +0000
committerprzemyslawpluta <przemekpluta@hotmail.com>2014-03-27 21:11:46 +0000
commit858cf4041d8d5300d1c76a90a9d6f0b8d7954c38 (patch)
treee3b1a9106cc2705b5be00cff85951ebc20890a47
parenta0e8d0ec8aaab3b361a7d93c7eb5b1badaa2ab69 (diff)
downloadmongo-edu-858cf4041d8d5300d1c76a90a9d6f0b8d7954c38.zip
download handouts from syllabus table
-rw-r--r--lib/login.js47
-rw-r--r--lib/videos.js8
-rw-r--r--mongo-edu.js8
-rw-r--r--package.json2
4 files changed, 46 insertions, 19 deletions
diff --git a/lib/login.js b/lib/login.js
index 7223126..706eb5a 100644
--- a/lib/login.js
+++ b/lib/login.js
@@ -11,7 +11,7 @@ var request = require('request'),
ProgressBar = require('progress'),
_ = require('lodash');
-var jar = request.jar();
+var jar = request.jar(), host = 'https://education.mongodb.com';
function addCookies(cookies, url) {
_.each(cookies, function cookies(cookie) { jar.setCookie(cookie, url + '/login'); });
@@ -19,9 +19,9 @@ function addCookies(cookies, url) {
module.exports = {
- init: function init(opt, callback) {
+ init: function init(opt, argv, callback) {
- var url = 'https://education.mongodb.com',
+ var url = host,
bar = new ProgressBar('[' + '>'.magenta + '] Searching [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: 5 }),
CSRFTokenCookie = '',
@@ -70,7 +70,7 @@ module.exports = {
bar.tick();
$(link).each(function each(i, item) {
- list.push({ name: $(item).text(), value: url + $(item).attr('href').replace(/about|info|syllabus/g, '') + 'course_wiki' });
+ list.push({ name: $(item).text(), value: url + $(item).attr('href').replace(/about|info|syllabus/g, '') + ((!argv.h) ? 'course_wiki' : 'syllabus') });
});
bar.tick();
@@ -108,18 +108,37 @@ module.exports = {
var list = [], getCourses = [], $ = cheerio.load(body), tag = opt.url.replace('course_', ''), options = (!argv.h)? 'Video' : 'Handout';
- $('div.wiki-article p').children().filter('a').map(function map(i, item) {
- var current = $(item);
- if (current.text().indexOf(options) !== -1) {
- list.push({ href: current.attr('href'), text: current.text() });
- }
- });
+ if (!argv.h) {
- getCourses = _.filter(list, function map(item) {
- if (item.href.match(/(wiki\/M101|wiki\/M102|wiki\/C100|wiki\/M202|wiki\/list-youtube-links)/)) { return item; }
- });
+ $('div.wiki-article p').children().filter('a').map(function map(i, item) {
+ var current = $(item);
+ if (current.text().indexOf(options) !== -1) {
+ list.push({ href: current.attr('href'), text: current.text() });
+ }
+ });
+
+ getCourses = _.filter(list, function map(item) {
+ if (item.href.match(/(wiki\/M101|wiki\/M102|wiki\/C100|wiki\/M202|wiki\/list-youtube-links)/)) { return item; }
+ });
+
+ return callback(null, _.map(getCourses, function map(item) { return { name: !item.href.match(/wiki\/list-youtube-links/) ? item.href.replace(tag, '').slice(0, -1).slice(1).replace(/-/g, ' ').replace(/\//g, ': ') : item.text, value: item.href }; }));
+
+ } else {
+
+
+ $('div.syllabus tbody tr').map(function map(i, item) {
+ var current = $(item), text = current.children().first().text(), href = $(current.find('a')).attr('href');
+ if (href) {
+ list.push({ name: text, value: host + $(current.find('a')).attr('href') });
+ }
+ });
+
+ if (list.length) { list.unshift({name: 'All', value: 'all', checked: true}, {name: 'Cancel', value: 'cancel'}); }
+
+ return callback(null, list, true);
+
+ }
- callback(null, _.map(getCourses, function map(item) { return { name: !item.href.match(/wiki\/list-youtube-links/) ? item.href.replace(tag, '').slice(0, -1).slice(1).replace(/-/g, ' ').replace(/\//g, ': ') : item.text, value: item.href }; }));
}
});
diff --git a/lib/videos.js b/lib/videos.js
index 2ddeb7b..4b8b700 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -56,6 +56,7 @@ var handleList = function handleList(list) {
});
};
+
fs.exists(downloadPath + name, function (exists) {
left = (currentList.length)? ' ' + currentList.length + ' left ...' : '';
@@ -170,7 +171,12 @@ module.exports = {
}
},
- download: function download(opt, list) {
+ download: function download(opt, list, argv) {
+
+ if (argv.h) {
+ handout = true;
+ downloadPath = argv.d;
+ }
var options = opt.videos, fullList = [], selected = [];
diff --git a/mongo-edu.js b/mongo-edu.js
index e35640e..67a8676 100644
--- a/mongo-edu.js
+++ b/mongo-edu.js
@@ -40,7 +40,7 @@ exports.create = function start() {
}
}];
- mdbvideos.init(answers, function get(err, data) {
+ mdbvideos.init(answers, argv, function get(err, data) {
if (err !== null) { throw err; }
if (data.length) {
@@ -55,11 +55,13 @@ exports.create = function start() {
function currentList() {
inquirer.prompt(classes, function prompt(answers) {
- mdbvideos.getList(answers, argv, function get(err, data) {
+ mdbvideos.getList(answers, argv, function get(err, data, pass) {
if (err !== null) { throw err; }
if (data.length) {
+ if (pass) { return showDetails(err, data); }
+
list[0].message = 'Found ' + data.length + ' List'+ ((data.length > 1)? 's' : '') + '. Select:';
list[0].choices = data;
@@ -94,7 +96,7 @@ exports.create = function start() {
check[0].choices = data;
return inquirer.prompt(check, function prompt(answers) {
- videoHandler.download(answers, data);
+ videoHandler.download(answers, data, argv);
});
}
diff --git a/package.json b/package.json
index ddd6154..8fe461d 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.1.7",
+ "version": "0.1.8",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from education.mongodb.com courses",
"main": "./mongo-edu",