From 7e33ace993b3d631598924a1fa47e89d8737aeac Mon Sep 17 00:00:00 2001 From: t3rr0r Date: Sat, 22 Nov 2014 17:02:07 -0500 Subject: [PATCH] updated getFormats regex to handle unknown & ?x formats --- lib/youtube-dl.js | 2 +- test/getFormat.js | 60 ++++++++++++++++++++++++++++++----------------- test/getInfo.js | 17 ++++++++++++++ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/lib/youtube-dl.js b/lib/youtube-dl.js index ea13e02..11f0889 100644 --- a/lib/youtube-dl.js +++ b/lib/youtube-dl.js @@ -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 diff --git a/test/getFormat.js b/test/getFormat.js index 50f5020..8c54424 100644 --- a/test/getFormat.js +++ b/test/getFormat.js @@ -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': { @@ -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); diff --git a/test/getInfo.js b/test/getInfo.js index 6edc0d3..78cb620 100644 --- a/test/getInfo.js +++ b/test/getInfo.js @@ -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';