Handle removed youtube videos. Fixes #14

This commit is contained in:
daniel-j 2016-09-08 20:58:32 +02:00
parent e1d6647411
commit b2b6cb010d
2 changed files with 6 additions and 6 deletions

View file

@ -222,7 +222,7 @@ class FimFic2Epub extends Emitter {
this.chapters[index] = chapter this.chapters[index] = chapter
completeCount++ completeCount++
this.progress(0, completeCount / chapterCount, 'Fetched chapter ' + (completeCount) + ' / ' + chapters.length) this.progress(0, completeCount / chapterCount, 'Fetched chapter ' + (completeCount) + ' / ' + chapterCount)
if (completeCount < chapterCount) { if (completeCount < chapterCount) {
recursive() recursive()
} else { } else {

View file

@ -67,17 +67,15 @@ export function cleanMarkup (html) {
function getYoutubeInfo (ids) { function getYoutubeInfo (ids) {
fetch('https://www.googleapis.com/youtube/v3/videos?id=' + ids + '&part=snippet&maxResults=50&key=' + youtubeKey).then((raw) => { fetch('https://www.googleapis.com/youtube/v3/videos?id=' + ids + '&part=snippet&maxResults=50&key=' + youtubeKey).then((raw) => {
let data let data = []
try { try {
data = JSON.parse(raw).items data = JSON.parse(raw).items
} catch (e) { } catch (e) { }
}
data.forEach((video) => { data.forEach((video) => {
cache.set(video.id, video.snippet) cache.set(video.id, video.snippet)
completeCount++ completeCount++
}) })
if (completeCount === cache.size) { if (completeCount === cache.size || data.length === 0) {
html = html.replace(matchYoutube, replaceYoutube) html = html.replace(matchYoutube, replaceYoutube)
continueParsing() continueParsing()
} }
@ -96,6 +94,8 @@ export function cleanMarkup (html) {
thumbnail = (data.thumbnails.standard || data.thumbnails.high || data.thumbnails.medium || data.thumbnails.default).url thumbnail = (data.thumbnails.standard || data.thumbnails.high || data.thumbnails.medium || data.thumbnails.default).url
title = data.title title = data.title
caption = data.title + ' on YouTube' caption = data.title + ' on YouTube'
} else {
return ''
} }
return render(m('figure.youtube', [ return render(m('figure.youtube', [
m('a', {href: youtubeUrl}, m('a', {href: youtubeUrl},