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

Commit

Permalink
Merge pull request #75 from jasonpenny/no-format-specified
Browse files Browse the repository at this point in the history
Specify download format 'best' if none supplied
  • Loading branch information
fent committed May 7, 2015
2 parents 023a502 + edee4d3 commit 7a078d3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/youtube-dl.js
Expand Up @@ -217,6 +217,10 @@ ytdl.getInfo = function(url, args, options, callback) {
args = [];
}
var defaultArgs = ['--dump-json'];
if (!args || args.indexOf('-f') < 0) {
defaultArgs.push('-f');
defaultArgs.push('best');
}
call(url, defaultArgs, args, options, function(err, data) {
if (err) return callback(err);

Expand Down
51 changes: 50 additions & 1 deletion test/download.js
Expand Up @@ -9,7 +9,7 @@ var subtitleFile = '1 1 1-179MiZSibco.en.srt';


vows.describe('download').addBatch({
'a video': {
'a video with format specified': {
'topic': function() {
var dl = ytdl(video1, ['-f', '18']);
var cb = this.callback;
Expand Down Expand Up @@ -58,6 +58,55 @@ vows.describe('download').addBatch({
}
}
},
'a video with no format specified': {
'topic': function() {
var dl = ytdl(video1);
var cb = this.callback;

dl.on('error', cb);

dl.on('info', function(info) {
var pos = 0;
var progress;

dl.on('data', function(data) {
pos += data.length;
progress = pos / info.size;
});

dl.on('end', function() {
cb(null, progress, info);
});

var filepath = path.join(__dirname, info._filename);
dl.pipe(fs.createWriteStream(filepath));
});
},

'data returned': function(err, progress, data) {
if (err) throw err;

assert.equal(progress, 1);
assert.isObject(data);
assert.equal(data.id, '90AiXO1pAiA');
assert.isTrue(/lol-90AiXO1pAiA/.test(data._filename));
assert.equal(data.size, 756000);
},

'file was downloaded': function(err, progress, data) {
if (err) throw err;

// Check existance.
var filepath = path.join(__dirname, data._filename);
var exists = fs.existsSync(filepath);
if (exists) {
// Delete file after each test.
fs.unlinkSync(filepath);
} else {
assert.isTrue(exists);
}
}
},
'a video with subtitles': {
topic: function() {
try {
Expand Down

0 comments on commit 7a078d3

Please sign in to comment.