From 3cf626d5f9f8722e29104907697bee45cd28d48b Mon Sep 17 00:00:00 2001 From: Christophe Leemans Date: Mon, 14 Mar 2022 11:58:48 +0300 Subject: [PATCH] Replace deprecated YouTube API V2 for new V3 --- index.html | 13 +++++++++++-- src/osmplayer.parser.youtube.js | 13 +++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index e9a138ec..bcdd0f13 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,13 @@ + + + - + \ No newline at end of file diff --git a/src/osmplayer.parser.youtube.js b/src/osmplayer.parser.youtube.js index 8336966e..2de5daad 100644 --- a/src/osmplayer.parser.youtube.js +++ b/src/osmplayer.parser.youtube.js @@ -16,7 +16,7 @@ osmplayer.parser.youtube = { // Return if this is a valid youtube feed. valid: function(feed) { - return (feed.search(/^http(s)?\:\/\/gdata\.youtube\.com/i) === 0); + return (feed.search(/^http(s)?\:\/\/www\.googleapis\.com\/youtube/i) === 0); }, // Returns the type of request to make. @@ -26,18 +26,19 @@ osmplayer.parser.youtube = { // Returns the feed provided the start and numItems. getFeed: function(feed, start, numItems) { + if(typeof(ENV) == "undefined" || typeof(ENV.youtubeApiKey) == 'undefined') throw 'YouTube API V3 requires authentication, please specify your API key in ENV.youtubeApiKey variable.'; feed = feed.replace(/(.*)\??(.*)/i, '$1'); - feed += '?start-index=' + (start + 1); - feed += '&max-results=' + (numItems); - feed += '&v=2&alt=jsonc'; + //feed += '?start-index=' + (start + 1); //TODO pagination + feed += '&maxResults=' + (numItems); + feed += '&part=snippet'; + feed += '&key=' + ENV.youtubeApiKey; return feed; }, // Parse the feed. parse: function(data) { - data = data.data; var playlist = { - total_rows: data.totalItems, + total_rows: data.pageInfo.resultsPerPage, nodes: [] };