Skip to content

Instantly share code, notes, and snippets.

@jeffmerrick
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffmerrick/ffa212f8989db9986059 to your computer and use it in GitHub Desktop.
Save jeffmerrick/ffa212f8989db9986059 to your computer and use it in GitHub Desktop.
Get video from YouTube
(function(window, $, undefined){
function getInfo() {
var movieInfo = {};
movieInfo['title'] = $('h1.title').html();
movieInfo['year'] = $('span.year').html();
movieInfo['type'] = $('.noreview-col-left h3').html().replace(' Details','');
return movieInfo;
}
function getVideo(searchQuery) {
var queryURL = 'https://www.googleapis.com/youtube/v3/search?q='+searchQuery+'&key=<YOUR API KEY HERE>&part=snippet&maxResults=1&type=video&videoEmbeddable=true';
$.getJSON(queryURL, function(data) {
console.log(data);
});
}
$('.actions').append('<br><br><span class="btnWrap mltBtn mltBtn-s60"><a id="watch-trailer" href="javascript:void(0);" style="margin-top:-5px" class="svf-button svfb-silver addlk evo-btn svf-button-inq save2add"><span class="inr">Watch Trailer</span></a></span>');
$('#watch-trailer').on('click', function(){
getVideo(getInfo().title + ' ' + getInfo().year);
});
})(window, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment