From 52e444ab64436d7416c83ed69e0a25f48682f11e Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 26 Mar 2016 11:43:26 -0700 Subject: [PATCH] ffmpeg: follow relative redirects --- src/ffmpeg.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ffmpeg.js b/src/ffmpeg.js index 6546a75e..b074546b 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -38,6 +38,14 @@ function initFFLog() { fflog.initialized = true; } +function fixRedirectIfNeeded(urldata, redirect) { + if (!/^https?:/.test(redirect)) { + redirect = urldata.protocol + "//" + urldata.host + redirect; + } + + return redirect; +} + function testUrl(url, cb, redirCount) { if (!redirCount) redirCount = 0; var data = urlparse.parse(url); @@ -59,7 +67,8 @@ function testUrl(url, cb, redirCount) { return cb("Too many redirects. Please provide a direct link to the " + "file"); } - return testUrl(res.headers["location"], cb, redirCount + 1); + return testUrl(fixRedirectIfNeeded(data, res.headers["location"]), cb, + redirCount + 1); } if (res.statusCode !== 200) {