diff --git a/lib/ffmpeg.js b/lib/ffmpeg.js index ee6d664c..a793ffb0 100644 --- a/lib/ffmpeg.js +++ b/lib/ffmpeg.js @@ -25,7 +25,8 @@ var audioOnlyContainers = { "mp3": true }; -function testUrl(url, cb, redirected) { +function testUrl(url, cb, redirCount) { + if (!redirCount) redirCount = 0; var data = urlparse.parse(url); if (!/https?:/.test(data.protocol)) { return cb("Video links must start with http:// or https://"); @@ -41,11 +42,11 @@ function testUrl(url, cb, redirected) { req.abort(); if (res.statusCode === 301 || res.statusCode === 302) { - if (redirected) { + if (redirCount > 2) { return cb("Too many redirects. Please provide a direct link to the " + "file"); } - return testUrl(res.headers['location'], cb, true); + return testUrl(res.headers['location'], cb, redirCount + 1); } if (res.statusCode !== 200) {