diff options
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | lib/initialize.js | 89 | ||||
-rw-r--r-- | package.json | 4 |
3 files changed, 59 insertions, 36 deletions
@@ -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": { |