Skip to content

Instantly share code, notes, and snippets.

@paulomcnally
Created March 2, 2014 21:24
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 paulomcnally/9314167 to your computer and use it in GitHub Desktop.
Save paulomcnally/9314167 to your computer and use it in GitHub Desktop.
var youtube = require('youtube-node');
youtube.setKey('AIzaSyB1OOSpTREs85WUMvIgJvLTZKye4BVsoFU');
youtube.addParam('type','video');
youtube.addParam('order','date');
youtube.search('World War z Trailer', 10, function(results) {
var ids = [];
var videos = [];
results.items.forEach( function( item ){
ids.push( item.id.videoId );
});
youtube.getById( ids.join(','), function( results ){
results.items.forEach(function( video ){
var obj = {
id: video.id,
title: video.snippet.title,
thumbnail_url: video.snippet.thumbnails.default.url,
duration: video.contentDetails.duration
};
videos.push( obj );
});
console.log( JSON.stringify( videos, null, 2 ) );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment