Skip to content

Commit

Permalink
Merge pull request #75 from Gerfaut/youtube_api_v3
Browse files Browse the repository at this point in the history
Replace deprecated YouTube API V2 for new V3
  • Loading branch information
travist committed Mar 15, 2022
2 parents 297a929 + 3cf626d commit 2f3ae03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<!-- Many more themes to chose from... go to http://jqueryui.com/themeroller! -->
<link rel="stylesheet" href="jquery-ui/dark-hive/jquery-ui.css">

<!-- Configure your YouTube API Key -->
<script type="text/javascript">
var ENV = {
youtubeApiKey: '{YOUR_API_KEY}' //How-To : https://developers.google.com/youtube/registering_an_application
};
</script>

<!-- The compressed osmplayer script. -->
<!--
<script type="text/javascript" src="bin/osmplayer.compressed.js"></script>
Expand Down Expand Up @@ -59,7 +66,9 @@
$("#osmplayer").osmplayer({
width: '100%',
height: '650px',
playlist: 'http://gdata.youtube.com/feeds/api/videos'
playlist: 'https://www.googleapis.com/youtube/v3/videos?chart=mostpopular'
//playlist: 'https://www.googleapis.com/youtube/v3/playlists?channelId={YOUR_CHANNEL_ID}'
//playlist: https://www.googleapis.com/youtube/v3/search?q={YOUR_SEARCH}
});
});
</script>
Expand All @@ -68,6 +77,6 @@
<div id="osmplayer"></div>

<!-- Or you can get a feed directly from youtube like so... -->
<!--<video id="osmplayer" playlist="http://gdata.youtube.com/feeds/api/videos"></video>-->
<!--<video id="osmplayer" playlist="https://www.googleapis.com/youtube/v3/videos?chart=mostpopular"></video>-->
</body>
</html>
2 changes: 1 addition & 1 deletion minplayer
13 changes: 7 additions & 6 deletions src/osmplayer.parser.youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: []
};

Expand Down

0 comments on commit 2f3ae03

Please sign in to comment.