ffmpeg: follow relative redirects

This commit is contained in:
calzoneman 2016-03-26 11:43:26 -07:00
parent efdab32aa8
commit 52e444ab64
1 changed files with 10 additions and 1 deletions

View File

@ -38,6 +38,14 @@ function initFFLog() {
fflog.initialized = true; fflog.initialized = true;
} }
function fixRedirectIfNeeded(urldata, redirect) {
if (!/^https?:/.test(redirect)) {
redirect = urldata.protocol + "//" + urldata.host + redirect;
}
return redirect;
}
function testUrl(url, cb, redirCount) { function testUrl(url, cb, redirCount) {
if (!redirCount) redirCount = 0; if (!redirCount) redirCount = 0;
var data = urlparse.parse(url); 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 " + return cb("Too many redirects. Please provide a direct link to the " +
"file"); "file");
} }
return testUrl(res.headers["location"], cb, redirCount + 1); return testUrl(fixRedirectIfNeeded(data, res.headers["location"]), cb,
redirCount + 1);
} }
if (res.statusCode !== 200) { if (res.statusCode !== 200) {