diff --git a/lib/youtube-dl.js b/lib/youtube-dl.js index 740db1b..b660e9b 100644 --- a/lib/youtube-dl.js +++ b/lib/youtube-dl.js @@ -45,7 +45,7 @@ function processData (data, args, options, stream) { if (options && options.start > 0 && options.end > 0) { headers.Range = 'bytes=' + options.start + '-' + options.end - } else { + } else if (typeof item.filesize === 'number') { headers.Range = 'bytes=0-' + item.filesize } diff --git a/package.json b/package.json index c00d53b..4eb17d9 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,10 @@ { "name": "coderaiser", "email": "mnemonic.enemy@gmail.com" + }, + { + "name": "RafaelKr", + "email": "coding@rafael.kr" } ], "repository": { diff --git a/test/download.js b/test/download.js index 2466bf7..87eacc6 100644 --- a/test/download.js +++ b/test/download.js @@ -8,6 +8,7 @@ var video2 = 'https://www.youtube.com/watch?v=179MiZSibco' var video3 = 'https://www.youtube.com/watch?v=AW8OOp2undg' var video4 = 'https://www.youtube.com/watch?v=yy7EUIR0fic' var video5 = 'https://www.youtube.com/watch?v=LDDy4m_TiVk' +var video6 = 'http://www.youtube.com/watch?v=NOaxV9N108g' var subtitleFile = '1 1 1-179MiZSibco.en.vtt' var thumbnailFile = 'Too Many Twists (Heist Night 5_5)-yy7EUIR0fic.jpg' @@ -182,6 +183,60 @@ vows } } }, + 'a video with `filesize: null`': { + topic: function () { + 'use strict' + var dl = ytdl(video6) + 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) { + 'use strict' + if (err) { + throw err + } + + assert.strictEqual(progress, 1) + assert.isObject(data) + assert.strictEqual(data.id, 'NOaxV9N108g') + }, + + 'file was downloaded': function (err, progress, data) { + 'use strict' + 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 () { 'use strict'