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

Commit

Permalink
updated getFormats regex to handle unknown & ?x formats
Browse files Browse the repository at this point in the history
  • Loading branch information
t3rr0r committed Nov 22, 2014
1 parent cff5763 commit 7e33ace
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ ytdl.getInfo = function(url, args, options, callback) {
};


var formatsRegex = /^(\d+)\s+([a-z0-9]+)\s+(\d+x\d+|\d+p|audio only)/;
var formatsRegex = /^(\d+)\s+([a-z0-9]+)\s+(\d+x\d+|\d+p|audio only|\?x\d+|unknown)/;

/**
* @param {String} url
Expand Down
60 changes: 39 additions & 21 deletions test/getFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ var assert = require('assert');
var video = 'http://www.youtube.com/watch?v=0k2Zzkw_-0I';


var expected = [
{ id: '0k2Zzkw_-0I', itag: 139, filetype: 'm4a', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 140, filetype: 'm4a', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 171, filetype: 'webm', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 141, filetype: 'm4a', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 172, filetype: 'webm', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 278, filetype: 'webm', resolution: '192x144' },
{ id: '0k2Zzkw_-0I', itag: 160, filetype: 'mp4', resolution: '192x144' },
{ id: '0k2Zzkw_-0I', itag: 242, filetype: 'webm', resolution: '320x240' },
{ id: '0k2Zzkw_-0I', itag: 133, filetype: 'mp4', resolution: '320x240' },
{ id: '0k2Zzkw_-0I', itag: 243, filetype: 'webm', resolution: '480x360' },
{ id: '0k2Zzkw_-0I', itag: 134, filetype: 'mp4', resolution: '480x360' },
{ id: '0k2Zzkw_-0I', itag: 244, filetype: 'webm', resolution: '640x480' },
{ id: '0k2Zzkw_-0I', itag: 135, filetype: 'mp4', resolution: '640x480' },
{ id: '0k2Zzkw_-0I', itag: 17, filetype: '3gp', resolution: '176x144' },
{ id: '0k2Zzkw_-0I', itag: 36, filetype: '3gp', resolution: '320x240' },
{ id: '0k2Zzkw_-0I', itag: 5, filetype: 'flv', resolution: '400x240' },
{ id: '0k2Zzkw_-0I', itag: 43, filetype: 'webm', resolution: '640x360' },
{ id: '0k2Zzkw_-0I', itag: 18, filetype: 'mp4', resolution: '640x360'}
];
var expected = {
video: [
{ id: '0k2Zzkw_-0I', itag: 139, filetype: 'm4a', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 140, filetype: 'm4a', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 171, filetype: 'webm', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 141, filetype: 'm4a', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 172, filetype: 'webm', resolution: 'audio only' },
{ id: '0k2Zzkw_-0I', itag: 278, filetype: 'webm', resolution: '192x144' },
{ id: '0k2Zzkw_-0I', itag: 160, filetype: 'mp4', resolution: '192x144' },
{ id: '0k2Zzkw_-0I', itag: 242, filetype: 'webm', resolution: '320x240' },
{ id: '0k2Zzkw_-0I', itag: 133, filetype: 'mp4', resolution: '320x240' },
{ id: '0k2Zzkw_-0I', itag: 243, filetype: 'webm', resolution: '480x360' },
{ id: '0k2Zzkw_-0I', itag: 134, filetype: 'mp4', resolution: '480x360' },
{ id: '0k2Zzkw_-0I', itag: 244, filetype: 'webm', resolution: '640x480' },
{ id: '0k2Zzkw_-0I', itag: 135, filetype: 'mp4', resolution: '640x480' },
{ id: '0k2Zzkw_-0I', itag: 17, filetype: '3gp', resolution: '176x144' },
{ id: '0k2Zzkw_-0I', itag: 36, filetype: '3gp', resolution: '320x240' },
{ id: '0k2Zzkw_-0I', itag: 5, filetype: 'flv', resolution: '400x240' },
{ id: '0k2Zzkw_-0I', itag: 43, filetype: 'webm', resolution: '640x360' },
{ id: '0k2Zzkw_-0I', itag: 18, filetype: 'mp4', resolution: '640x360'}
],

mixcloud: [
{ id: 'TheBloodyBeetroots-sbcr-dj-mix-october-2014', itag: 0, filetype: 'mp3', resolution: 'unknown' }
]
};

vows.describe('getFormats').addBatch({
'from a video': {
Expand All @@ -34,7 +40,19 @@ vows.describe('getFormats').addBatch({
'formats returned': function(err, formats) {
assert.isNull(err);
assert.isArray(formats);
assert.deepEqual(formats, expected);
assert.deepEqual(formats, expected.video);
}
},

'from a mixcloud mix': {
'topic': function() {
ytdl.getFormats('http://www.mixcloud.com/TheBloodyBeetroots/sbcr-dj-mix-october-2014/', this.callback);
},

'formats returned': function(err, formats) {
assert.isNull(err);
assert.isArray(formats);
assert.deepEqual(formats, expected.mixcloud);
}
}
}).export(module);
17 changes: 17 additions & 0 deletions test/getInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ vows.describe('getInfo').addBatch({
assert.equal(info.resolution, '640x360');
}
},
'from a soundcloud track': {
'topic': function() {
var video = 'https://soundcloud.com/erasedtapes/kiasmos-bent';
ytdl.getInfo(video, this.callback);
},
'info returned': function(err, info) {
assert.isNull(err);
assert.isObject(info);
assert.equal(info.id, '147055755');
assert.equal(info.title, 'Kiasmos - Bent');
assert.isString(info.url);
assert.isString(info.thumbnail);
assert.isString(info.description);
assert.equal(info.filename, 'Kiasmos - Bent-147055755.mp3');
assert.equal(info.resolution, 'audio only');
}
},
'from a vimeo video': {
'topic': function() {
var video = 'https://vimeo.com/6586873';
Expand Down

0 comments on commit 7e33ace

Please sign in to comment.