From a81f691d4ec09d3193f8abeea7a5db44e23ee251 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 25 May 2015 16:04:27 -0400 Subject: [PATCH] Allow 2 redirects --- lib/ffmpeg.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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) {