From 79c06bf515f68add4631ee7da8689083ed9af571 Mon Sep 17 00:00:00 2001 From: przemyslawpluta Date: Thu, 9 Apr 2015 18:40:19 +0100 Subject: handle multiple matches --- lib/courseware.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/courseware.js b/lib/courseware.js index 7d7ca7c..7ed606a 100644 --- a/lib/courseware.js +++ b/lib/courseware.js @@ -47,9 +47,13 @@ function listVideos(url, jar, id, callback) { var $ = cheerio.load(body), pageView = $('div.col-sm-9.course-content section').html(), - getVideoIds = (pageView) ? pageView.match(/(.0:)(.*?)(&)/g) : pageView; + getVideoIds = (pageView) ? pageView.match(/(.0:)(.*?)(&)/g) : pageView, i; - if (getVideoIds && getVideoIds.length > 1) { getVideoIds = [getVideoIds[0]]; } + if (getVideoIds && getVideoIds.length > 1) { + for (i = 0; i < getVideoIds.length; i++) { + if (getVideoIds[i].length > 15) { getVideoIds.splice(i, 1); } + } + } getVideoIds = (!getVideoIds) ? [] : getVideoIds.map(function map(item) { return { id: id, video: 'https://youtu.be/' + item.replace('.0:','').replace('&','')}; }); -- cgit v1.2.3