From b2b6cb010dbea46d945045235d07d8e7e84b2554 Mon Sep 17 00:00:00 2001 From: daniel-j Date: Thu, 8 Sep 2016 20:58:32 +0200 Subject: [PATCH] Handle removed youtube videos. Fixes #14 --- src/FimFic2Epub.js | 2 +- src/cleanMarkup.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/FimFic2Epub.js b/src/FimFic2Epub.js index 25f34f7..6f5ff67 100644 --- a/src/FimFic2Epub.js +++ b/src/FimFic2Epub.js @@ -222,7 +222,7 @@ class FimFic2Epub extends Emitter { this.chapters[index] = chapter completeCount++ - this.progress(0, completeCount / chapterCount, 'Fetched chapter ' + (completeCount) + ' / ' + chapters.length) + this.progress(0, completeCount / chapterCount, 'Fetched chapter ' + (completeCount) + ' / ' + chapterCount) if (completeCount < chapterCount) { recursive() } else { diff --git a/src/cleanMarkup.js b/src/cleanMarkup.js index 99d0c8f..12f16b1 100644 --- a/src/cleanMarkup.js +++ b/src/cleanMarkup.js @@ -67,17 +67,15 @@ export function cleanMarkup (html) { function getYoutubeInfo (ids) { fetch('https://www.googleapis.com/youtube/v3/videos?id=' + ids + '&part=snippet&maxResults=50&key=' + youtubeKey).then((raw) => { - let data + let data = [] try { data = JSON.parse(raw).items - } catch (e) { - - } + } catch (e) { } data.forEach((video) => { cache.set(video.id, video.snippet) completeCount++ }) - if (completeCount === cache.size) { + if (completeCount === cache.size || data.length === 0) { html = html.replace(matchYoutube, replaceYoutube) continueParsing() } @@ -96,6 +94,8 @@ export function cleanMarkup (html) { thumbnail = (data.thumbnails.standard || data.thumbnails.high || data.thumbnails.medium || data.thumbnails.default).url title = data.title caption = data.title + ' on YouTube' + } else { + return '' } return render(m('figure.youtube', [ m('a', {href: youtubeUrl},