Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
buffer info call
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Aug 1, 2012
1 parent 5247bdb commit c46a993
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var spawn = require('child_process').spawn
, execFile = require('child_process').execFile
, EventEmitter = require('events').EventEmitter
, fs = require('fs')
, path = require('path')
Expand Down Expand Up @@ -205,7 +206,7 @@ exports.download = function(url, dest, args) {


// gets info from a video
module.exports.info = function(url, callback, args) {
exports.info = function(url, callback, args) {
// setup settings
if (args == null) {
args = [];
Expand All @@ -222,25 +223,19 @@ module.exports.info = function(url, callback, args) {
args.push(url);

// call youtube-dl
var youtubedl = spawn(file, args);
var err = null, info;
youtubedl.stdout.on('data', function(data) {
data = data.toString().split('\n');
var youtubedl = execFile(file, args, function(err, stdout, stderr) {
if (err) return callback(err);
if (stderr) return callback(new Error(stderr.slice(7)));

var data = stdout.split('\n');
info = {
title : data[0]
, url : data[1]
, thumbnail : data[2]
, description : data[3]
, filename : data[4]
};
});

youtubedl.stderr.on('data', function(data) {
data = data.toString().trim();
err = new Error(data.substring(7, data.length - 1));
});

youtubedl.on('exit', function(code) {
return callback(err, info);
callback(null, info);
});
};

0 comments on commit c46a993

Please sign in to comment.