Skip to content
This repository was 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
fent committed May 7, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 023a502 + edee4d3 commit 7a078d3
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
@@ -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);

51 changes: 50 additions & 1 deletion test/download.js
Original file line number Diff line number Diff line change
@@ -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;
@@ -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 {

0 comments on commit 7a078d3

Please sign in to comment.