Skip to content

Commit

Permalink
ffmpeg: follow relative redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
calzoneman committed Mar 26, 2016
1 parent efdab32 commit 52e444a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 52e444a

Please sign in to comment.