youtube fix

This commit is contained in:
daniel-j 2020-10-19 12:43:48 +02:00
parent c5ee26d7cc
commit c6e5ae80e3
2 changed files with 7 additions and 4 deletions

View file

@ -34,7 +34,7 @@
"permissions": [
"https://fimfiction.net/*",
"https://*.fimfiction.net/*",
"https://www.googleapis.com/youtube/v3/videos?id=*",
"https://www.googleapis.com/*",
"https://i.ytimg.com/*",
"https://twemoji.maxcdn.com/*",
"storage"

View file

@ -4,7 +4,7 @@ import { XmlEntities } from 'html-entities'
import twemoji from 'twemoji'
import render from 'mithril-node-render'
import fetch from './fetch'
import fetchRemote from './fetchRemote'
import { youtubeKey } from './constants'
import { replaceAsync } from './utils'
@ -85,15 +85,18 @@ export async function cleanMarkup (html) {
}
async function getYoutubeInfo (ids) {
return fetch('https://www.googleapis.com/youtube/v3/videos?id=' + ids + '&part=snippet&maxResults=50&key=' + youtubeKey).then(async (raw) => {
return fetchRemote('https://www.googleapis.com/youtube/v3/videos?id=' + ids + '&part=snippet&maxResults=50&key=' + youtubeKey).then(async (raw) => {
let data = []
try {
data = JSON.parse(raw).items
} catch (e) {}
} catch (e) {
console.error('Error parsing Youtube API response:', e)
}
if (!data) {
data = []
}
data.forEach((video) => {
console.log('Adding Youtube video ' + video.id + ' to cache')
cache.set(video.id, video.snippet)
completeCount++
})