paulomcnally / youtube-node

Youtube api implementation for nodeJS
https://www.npmjs.com/package/youtube-node
Apache License 2.0
108 stars 53 forks source link

self.addPart in #search doesn't work #24

Open danielravina opened 8 years ago

danielravina commented 8 years ago

Hi, I'm trying to add more parts to the search function with the following code but I don't see them in the results Code:

var YouTube = require('youtube-node');

var youTube = new YouTube();

youTube.setKey('AIzaSyB1OOSpTREs85WUMvIgJvLTZKye4BVsoFU');

youTube.addPart('contentDetails');
youTube.addPart('statistics');
youTube.addPart('status');

youTube.search('World War z Trailer', 2, function(error, result) {
  if (error) {
    console.log(error);
  }
  else {
    console.log(result);
  }
});

Result:

etag: "\"5g01s4-wS2b4VpScndqCYc5Y-8k/suscqJikhZQTuxqt_8zSu3fP_fA\""
id: Object {kind: "youtube#video", …}
kind: "youtube#searchResult"
snippet: {
  channelId: "UCkR0GY0ue02aMyM-oxwgg9g"
  channelTitle: "Movieclips Coming Soon"
  description: "Subscribe to TRAILERS: http://bit…://goo.gl/dHs73 Follow us on ..."
  liveBroadcastContent: "none"
  publishedAt: "2013-03-25T07:02:54.000Z"
  thumbnails: Object {default: , …}
  title: "World War Z TRAILER 2 (2013) - Brad Pitt Movie HD"
}
danielravina commented 8 years ago

NM ijust noticed the search endpoint only support the snippet. Is there a way to get a list of search results with more data?

paulomcnally commented 8 years ago

See https://developers.google.com/youtube/v3/docs/search/list

danielravina commented 8 years ago

I made a workaround with 2 api calls. I guess there isn't a way to get everything in one shot.

module.exports.search = (q) => {
  return new Promise((resolve, reject) => {
    youTube.search(q, 20, (error, result) => {
      if (error) return reject(error);

      const ids = result.items.map(r => r.id.videoId).join(',');

      youTube.getById(ids, (error, r) => {
        if (error) return reject(error);
        resolve(r);
      });
    });
  });
};
paulomcnally commented 7 years ago

Hi @danielravina have a pull request?