diff options
author | przemyslawpluta <przemekpluta@hotmail.com> | 2014-04-06 19:37:29 +0100 |
---|---|---|
committer | przemyslawpluta <przemekpluta@hotmail.com> | 2014-04-06 19:37:29 +0100 |
commit | 11b317833a8d5a332d8cba564edbcd68cf7f9a7a (patch) | |
tree | 7529d9a469514db79053ea88f77a77d82f8f87a6 /lib/login.js | |
parent | aa5184821120aac47547cf1745c350d1efa51c8f (diff) | |
download | mongo-edu-11b317833a8d5a332d8cba564edbcd68cf7f9a7a.zip |
handle youtube playlists
Diffstat (limited to 'lib/login.js')
-rw-r--r-- | lib/login.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/login.js b/lib/login.js index 12de9e4..6804031 100644 --- a/lib/login.js +++ b/lib/login.js @@ -9,7 +9,8 @@ var request = require('request'), cheerio = require('cheerio'), ProgressBar = require('progress'), - _ = require('lodash'); + _ = require('lodash'), + videoHandler = require('./videos'); var jar = request.jar(), host = 'https://university.mongodb.com'; @@ -106,19 +107,19 @@ module.exports = { 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' : 'Handout'; + var list = [], getCourses = [], $ = cheerio.load(body), tag = opt.url.replace('course_', ''), options = (!argv.h)? 'Video|playlist' : 'Handout'; if (!argv.h) { $('div.wiki-article p').children().filter('a').map(function map(i, item) { var current = $(item); - if (current.text().indexOf(options) !== -1) { + if (current.text().match(options)) { 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; } + if (item.href.match(/(wiki\/M101|wiki\/M102|wiki\/C100|wiki\/M202|wiki\/list-youtube-links|playlist\?list|view_play_list)/)) { return item; } }); return callback(null, _.map(getCourses, function map(item) { return { name: item.text, value: item.href }; })); @@ -144,10 +145,14 @@ module.exports = { }, - listVideos: function listVideos(opt, callback) { + listVideos: function listVideos(opt, argv, callback) { var videos = [], state = false, list, $, current; + if (opt.url.match(/playlist\?list|view_play_list/)) { + return videoHandler.listVideosFromPlaylist(opt, argv, callback); + } + request({ url: opt.url, jar: jar }, function get(err, res, body) { if (err !== null) { return callback(err, null); } if (res.statusCode === 200) { |