Using fetch instead of xhr, grabbing title for YouTube

This commit is contained in:
Sam Potts
2017-11-16 11:38:06 +01:00
parent c64b8f6940
commit d7a1c44281
12 changed files with 47 additions and 50 deletions

View File

@ -23,6 +23,20 @@ const youtube = {
// Set ID
this.media.setAttribute('id', utils.generateId(this.type));
// Get the title
const key = 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c';
const url = `https://www.googleapis.com/youtube/v3/videos?id=${videoId}&fields=items(snippet(title))&part=snippet&key=${key}`;
fetch(url)
.then(response => response.json())
.then(obj => {
if (utils.is.object(obj)) {
this.config.title = obj.items[0].snippet.title;
ui.setTitle.call(this);
}
})
.catch(() => {});
// Setup API
if (utils.is.object(window.YT)) {
youtube.ready.call(this, videoId);