diff options
author | Sam Potts <sam@potts.es> | 2017-11-18 19:30:26 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2017-11-18 19:30:26 +1100 |
commit | 6984d6fb1606a71edd35ac043ac1116b6de8e98b (patch) | |
tree | 1dc18a90bb2870b3c4665e40a3dcaeb75f3bb831 /src/js/plugins | |
parent | d7a1c4428138d2dd5af09e41e998d1e08dafe76e (diff) | |
download | plyr-6984d6fb1606a71edd35ac043ac1116b6de8e98b.tar.lz plyr-6984d6fb1606a71edd35ac043ac1116b6de8e98b.tar.xz plyr-6984d6fb1606a71edd35ac043ac1116b6de8e98b.zip |
Controls cleanup, work on captions bug, click to invert time
Diffstat (limited to 'src/js/plugins')
-rw-r--r-- | src/js/plugins/youtube.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js index 6b70af4c..a46773a0 100644 --- a/src/js/plugins/youtube.js +++ b/src/js/plugins/youtube.js @@ -23,19 +23,21 @@ 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(() => {}); + // Get the media title via Google API + const key = this.config.keys.google; + if (utils.is.string(key) && !utils.is.empty(key)) { + const url = `https://www.googleapis.com/youtube/v3/videos?id=${videoId}&key=${key}&fields=items(snippet(title))&part=snippet`; + + fetch(url) + .then(response => (response.ok ? response.json() : null)) + .then(result => { + if (result !== null && utils.is.object(result)) { + this.config.title = result.items[0].snippet.title; + ui.setTitle.call(this); + } + }) + .catch(() => {}); + } // Setup API if (utils.is.object(window.YT)) { |