// 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();
}
});