diff options
author | przemyslawpluta <przemekpluta@hotmail.com> | 2015-04-09 18:40:19 +0100 |
---|---|---|
committer | przemyslawpluta <przemekpluta@hotmail.com> | 2015-04-09 18:40:19 +0100 |
commit | 79c06bf515f68add4631ee7da8689083ed9af571 (patch) | |
tree | f4f8b3d21b12369c275b13e0f5848edf5ed20cfd /lib | |
parent | 58e1c1cb7171ec3648d63c5dbc8034bedb23994f (diff) | |
download | mongo-edu-79c06bf515f68add4631ee7da8689083ed9af571.zip |
handle multiple matches
Diffstat (limited to 'lib')
-rw-r--r-- | lib/courseware.js | 8 |
1 files changed, 6 insertions, 2 deletions
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('&','')}; }); |