summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2015-08-14 14:54:23 +0100
committerprzemyslawpluta <przemekpluta@hotmail.com>2015-08-14 14:54:23 +0100
commitebf010cee4a45d14b8890b73d5ab0e06f99c718c (patch)
tree316e5700adfd0b2909cc9564e6d2650c25d63df8
parentfd4a50826c7ca3c33339699084bb0e8e968770e1 (diff)
downloadmongo-edu-ebf010cee4a45d14b8890b73d5ab0e06f99c718c.zip
switch to courseware search if wiki returns no results
-rw-r--r--LICENSE2
-rw-r--r--lib/initialize.js89
-rw-r--r--package.json4
3 files changed, 59 insertions, 36 deletions
diff --git a/LICENSE b/LICENSE
index 70bfbc7..04ebf1d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014 Przemyslaw Pluta <przemyslawplutadev@gmail.com>
+Copyright (c) 2014 - 2015 Przemyslaw Pluta <przemyslawplutadev@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/lib/initialize.js b/lib/initialize.js
index 451c734..a134ed9 100644
--- a/lib/initialize.js
+++ b/lib/initialize.js
@@ -34,15 +34,23 @@ module.exports = function run(profile, argv) {
var list = prompts.list, classes = list, check = prompts.check, confirm = prompts.confirm;
- mdbvideos.init(answers, argv, function get(err, data, profile) {
+ function init(answers) {
- if (err !== null) { throw err; }
+ mdbvideos.init(answers, argv, function get(err, data, profile) {
+
+ if (err !== null) { throw err; }
+
+ if (profile.preset.video[1] === videoPreference || argv.h) { return processList(data, profile); }
- if (profile.preset.video[1] === videoPreference || argv.h) { return processList(data, profile); }
+ confirm[0].message = 'Your current video preference is set to ' + profile.preset.video[1].underline + '. Switch to: ' + videoPreference.green;
- confirm[0].message = 'Your current video preference is set to ' + profile.preset.video[1].underline + '. Switch to: ' + videoPreference.green;
+ profileAssesment(confirm, data);
+
+ });
+ }
- return inquirer.prompt(confirm, function prompt(answers) {
+ function profileAssesment(confirm, data) {
+ inquirer.prompt(confirm, function prompt(answers) {
if (!answers.confirm) { return console.log('i'.red + ' ' + pkg.name + ' requires video preferences set to ' + videoPreference + '.\n'); }
mdbvideos.updateProfile({
@@ -54,50 +62,63 @@ module.exports = function run(profile, argv) {
});
});
+ }
- });
+ function getClassContent(content) {
+ mdbvideos.getList(content, argv, function get(err, data, pass) {
+ if (err !== null) { throw err; }
- function processList(data, profile) {
-
- if (!data.length) {
- if (profile.noCourses) { return console.log('i'.red + ' ' + checkName(profile) + ' ' + profile.noCourses); }
- return console.log('i'.red + ' ' + checkName(profile) + ' ' + 'Could not locate any courses in your profile. Have you registered already?\n');
- }
+ if (data.length) {
- classes[0].message = checkName(profile) + ' Found ' + data.length + ' Course'+ ((data.length > 1)? 's' : '') + '. Select:';
- classes[0].choices = data;
- currentList();
+ if (pass) { return showDetails(err, data); }
- }
+ list[0].message = 'Found ' + data.length + ' List' + ((data.length > 1)? 's' : '') + '. Select:';
+ list[0].choices = data;
- function currentList() {
- inquirer.prompt(classes, function prompt(answers) {
+ return currentVideos();
- mdbvideos.getList(answers, argv, function get(err, data, pass) {
- if (err !== null) { throw err; }
+ } else {
+ if (pass) { return console.log('i'.red + ' Looks like the course is not yet available or has already ended. ' +
+ lookFor + ' list is not available.\n\nCheck the start/end date for selected course.\n'); }
+ }
- if (data.length) {
+ console.log('i'.red + ' Unable to locate any ' + lookFor.toLowerCase() + ' lists in the wiki. Are ' + lookFor.toLowerCase() + ' list present?');
- if (pass) { return showDetails(err, data); }
+ if (lookFor === 'Videos' && !argv.cw) {
- list[0].message = 'Found ' + data.length + ' List' + ((data.length > 1)? 's' : '') + '. Select:';
- list[0].choices = data;
+ confirm[0].message = 'Default wiki search returned no resuts. Perform courseware search with ' + '--cw'.green + ' ?';
- return currentVideos();
+ inquirer.prompt(confirm, function prompt(answers) {
+ if (!answers.confirm) { return; }
+ argv.cw = true;
+ content.url = content.url.replace(/course_wiki/g, '') + 'courseware';
+ getClassContent(content);
+ });
- } else {
- if (pass) { return console.log('i'.red + ' Looks like the course is not yet available or has already ended. ' +
- 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. Are ' +
- lookFor.toLowerCase() + ' list present?' +
- ((lookFor === 'Videos') ? '\n\n' + ((!argv.cw) ? 'Try to add ' + '--cw'.green + ' to switch and search on courseware instead.\n' : '') : ''));
- });
+ });
+ }
+ function currentList() {
+ inquirer.prompt(classes, function prompt(answers) {
+ getClassContent(answers);
});
}
+ function processList(data, profile) {
+
+ if (!data.length) {
+ if (profile.noCourses) { return console.log('i'.red + ' ' + checkName(profile) + ' ' + profile.noCourses); }
+ return console.log('i'.red + ' ' + checkName(profile) + ' ' + 'Could not locate any courses in your profile. Have you registered already?\n');
+ }
+
+ classes[0].message = checkName(profile) + ' Found ' + data.length + ' Course'+ ((data.length > 1)? 's' : '') + '. Select:';
+ classes[0].choices = data;
+ currentList();
+
+ }
+
function currentVideos() {
inquirer.prompt(list, function prompt(answers) {
@@ -127,6 +148,8 @@ module.exports = function run(profile, argv) {
console.log('i'.red + ' Could not locate any ' + lookFor.toLowerCase() + '.'); process.exit(0);
}
+ init(answers);
+
});
};
diff --git a/package.json b/package.json
index a0580a8..1a1786b 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.2.18",
+ "version": "0.2.19",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",
@@ -47,7 +47,7 @@
"rimraf": "~2.4.2",
"unzip": "~0.1.11",
"which": "~1.1.1",
- "yargs": "~3.18.0",
+ "yargs": "~3.19.0",
"youtube-dl": "~1.10.5"
},
"engines": {