summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2014-04-07 19:48:20 +0100
committerprzemyslawpluta <przemekpluta@hotmail.com>2014-04-07 19:48:20 +0100
commit5f2170a945f7d2061ae523737785b173e98151d7 (patch)
tree0718be8efbae054b72511181a6ec450387edb0e1 /lib
parent11b317833a8d5a332d8cba564edbcd68cf7f9a7a (diff)
downloadmongo-edu-5f2170a945f7d2061ae523737785b173e98151d7.zip
handle youtube playlists
Diffstat (limited to 'lib')
-rw-r--r--lib/login.js15
-rw-r--r--lib/validate.js6
-rw-r--r--lib/videos.js36
3 files changed, 42 insertions, 15 deletions
diff --git a/lib/login.js b/lib/login.js
index 6804031..5069e7d 100644
--- a/lib/login.js
+++ b/lib/login.js
@@ -15,6 +15,9 @@ var request = require('request'),
var jar = request.jar(), host = 'https://university.mongodb.com';
function addCookies(cookies, url) {
+
+ 'use strict';
+
_.each(cookies, function cookies(cookie) { jar.setCookie(cookie, url + '/login'); });
}
@@ -22,6 +25,8 @@ module.exports = {
init: function init(opt, argv, callback) {
+ 'use strict';
+
var url = host,
bar = new ProgressBar('[' + '>'.magenta + '] Searching [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: 5 }),
CSRFTokenCookie = '',
@@ -62,7 +67,7 @@ module.exports = {
bar.tick();
if (res.statusCode === 200) {
- var list = [], getCourses = [], $ = cheerio.load(body),
+ var list = [], $ = cheerio.load(body),
current = $('article.my-course.panel').children(),
@@ -82,7 +87,7 @@ module.exports = {
});
};
- request(url, function (err, res, body) {
+ request(url, function (err, res) {
if (err !== null) { return callback(err, null); }
@@ -103,11 +108,13 @@ module.exports = {
getList: function getList(opt, argv, callback) {
+ 'use strict';
+
request({ url: opt.url, jar: jar }, function get(err, res, body) {
if (err !== null) { return callback(err, null); }
if (res.statusCode === 200) {
- var list = [], getCourses = [], $ = cheerio.load(body), tag = opt.url.replace('course_', ''), options = (!argv.h)? 'Video|playlist' : 'Handout';
+ var list = [], getCourses = [], $ = cheerio.load(body), options = (!argv.h)? 'Video|playlist' : 'Handout';
if (!argv.h) {
@@ -147,6 +154,8 @@ module.exports = {
listVideos: function listVideos(opt, argv, callback) {
+ 'use strict';
+
var videos = [], state = false, list, $, current;
if (opt.url.match(/playlist\?list|view_play_list/)) {
diff --git a/lib/validate.js b/lib/validate.js
index 1480b11..c6909d6 100644
--- a/lib/validate.js
+++ b/lib/validate.js
@@ -10,14 +10,16 @@ var mkdirp = require('mkdirp');
module.exports.init = function init(opt, callback) {
+ 'use strict';
+
var profile = [
{ type: 'input', name: 'user', message: 'MongoDB Uni User Name', default: '', validate: function(value) {
if (value !== '') { return true; }
- return "Please enter your MongoDB Uni user name - email address";
+ return 'Please enter your MongoDB Uni user name - email address';
}},
{ type: 'password', message: 'MongoDB Uni Password', name: 'password', validate: function(value) {
if (value !== '') { return true; }
- return "Please enter your MongoDB Uni password";
+ return 'Please enter your MongoDB Uni password';
}}
];
diff --git a/lib/videos.js b/lib/videos.js
index 017787a..9b60aeb 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -19,8 +19,20 @@ var path = require('path'),
var downloadPath = '', ncc = false, handout = false, cc = false;
+var setOptions = function setOptions(argv) {
+
+ 'use strict';
+
+ downloadPath = argv.d;
+ if (argv.ncc) { ncc = true; }
+ if (argv.h) { handout = true; }
+ if (argv.cc) { cc = true; }
+};
+
var handleList = function handleList(list) {
+ 'use strict';
+
var currentList = list,
opt = (!ncc) ? ['--max-quality=18'] : ['--max-quality=18', '--no-check-certificate'];
@@ -118,10 +130,9 @@ module.exports = {
details: function details(opt, argv, callback) {
- downloadPath = argv.d;
- if (argv.ncc) { ncc = true; }
- if (argv.h) { handout = true; }
- if (argv.cc) { cc = true; }
+ 'use strict';
+
+ setOptions(argv);
var bar = new ProgressBar('[' + '>'.magenta + '] Collecting [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: opt.length }),
options = (!ncc) ? [] : ['--no-check-certificate'];
@@ -177,10 +188,9 @@ module.exports = {
download: function download(opt, list, argv) {
- if (argv.h) {
- handout = true;
- downloadPath = argv.d;
- }
+ 'use strict';
+
+ setOptions(argv);
var options = opt.videos, fullList = [], selected = [];
@@ -201,10 +211,16 @@ module.exports = {
listVideosFromPlaylist: function getIdsFromPlaylist(opt, argv, callback) {
+ 'use strict';
+
+ var args = [opt.url, '--get-id', '--get-title'];
+ args = (!argv.ncc) ? args : args.concat(['--no-check-certificate']);
+
var isWin = /^win/.test(process.platform),
file = path.join(__dirname, '..', 'node_modules/youtube-dl/bin', 'youtube-dl'),
- args = [opt.url, '--get-id', '--get-title'],
- options = [file, (!argv.ncc) ? args : args.concat(['--no-check-certificate']), ''];
+ options = [file, args, ''];
+
+ setOptions(argv);
if (isWin) { options = ['python', [file].concat(args), '\r']; }