From 0df2ae550c4f5e16298d1cbdde788ce7acc575e3 Mon Sep 17 00:00:00 2001 From: przemyslawpluta Date: Fri, 1 Aug 2014 11:08:47 +0100 Subject: update parse html href links cleanup --- lib/login.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'lib/login.js') diff --git a/lib/login.js b/lib/login.js index 2dd9bef..968b518 100644 --- a/lib/login.js +++ b/lib/login.js @@ -162,7 +162,7 @@ module.exports = { 'use strict'; - var videos = [], state = false, list, $, current; + var videos = [], list, $, current; if (argv.cw || argv.cwd) { return coursewareHandler.filterVideos(opt, host, jar, argv, callback); } @@ -178,24 +178,17 @@ module.exports = { current = list.find('code').text(); - if ((current.indexOf('http://') !== -1) || (current.indexOf('https://') !== -1)) { - videos = _.compact(current.split('\n')); - } + if (current.match(/http:\/\/|https:\/\//)) { videos = _.compact(current.split('\n')); } if (!videos.length) { list.children('p').children().each(function each(i, item) { - var current = $(item); - if (current.attr('href')) { - videos.push({ name: current.text().split('-')[0], value: current.attr('href') }); - } + var current = $(item), href = current.attr('href'); + if (href && href.match(/http:\/\/|https:\/\//)) { videos.push(href); } }); - - if (videos.length) { videos.unshift({name: 'All', value: 'all', checked: true}, {name: 'Cancel', value: 'cancel'}); } - state = true; } - return callback(null, videos, state); + return callback(null, videos); } callback(new Error(res.statusCode)); -- cgit v1.2.3