Allow 2 redirects
This commit is contained in:
parent
9b3a71d84f
commit
a81f691d4e
|
|
@ -25,7 +25,8 @@ var audioOnlyContainers = {
|
||||||
"mp3": true
|
"mp3": true
|
||||||
};
|
};
|
||||||
|
|
||||||
function testUrl(url, cb, redirected) {
|
function testUrl(url, cb, redirCount) {
|
||||||
|
if (!redirCount) redirCount = 0;
|
||||||
var data = urlparse.parse(url);
|
var data = urlparse.parse(url);
|
||||||
if (!/https?:/.test(data.protocol)) {
|
if (!/https?:/.test(data.protocol)) {
|
||||||
return cb("Video links must start with http:// or https://");
|
return cb("Video links must start with http:// or https://");
|
||||||
|
|
@ -41,11 +42,11 @@ function testUrl(url, cb, redirected) {
|
||||||
req.abort();
|
req.abort();
|
||||||
|
|
||||||
if (res.statusCode === 301 || res.statusCode === 302) {
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||||
if (redirected) {
|
if (redirCount > 2) {
|
||||||
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, true);
|
return testUrl(res.headers['location'], cb, redirCount + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.statusCode !== 200) {
|
if (res.statusCode !== 200) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue