Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Created September 16, 2015 20:42
Show Gist options
  • Select an option

  • Save Tiny-Giant/e66168c22e20cf6c5c5e to your computer and use it in GitHub Desktop.

Select an option

Save Tiny-Giant/e66168c22e20cf6c5c5e to your computer and use it in GitHub Desktop.

// load future from fibers var Future = Meteor.npmRequire("fibers/future"); // load youtubedl var youtubedl = Meteor.npmRequire('youtube-dl'); // load ytdl-core var ytdl = Meteor.npmRequire('ytdl-core');

Meteor.methods({ 'command' : function(line) { // this method call won't return immediately, it will wait for the // asynchronous code to finish, so we call unblock to allow this client this.unblock(); var future = new Future();

ytdl.getInfo(line, function(err, stdout, stderr) {
  
  if(stdout) {
    if(!future.return({stdout:stdout, stderr:stderr})) {
      youtubedl.getInfo(line, function(err, stdout, stderr) {
        future.return({stdout:stdout, stderr:stderr})
      });
    }
  } else {
    youtubedl.getInfo(line, function(err, stdout, stderr) {
      future.return({stdout:stdout, stderr:stderr})
    });
  }
});
return future.wait();

}

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment