Add head request to the current downloader implementation

This commit is contained in:
Mauricio Colli
2019-10-22 13:21:23 -03:00
committed by Tobias Groza
parent 06f2144e4d
commit 250c0bb1e8
3 changed files with 33 additions and 4 deletions

View File

@@ -172,6 +172,28 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
return dl(con);
}
@Override
public DownloadResponse head(String siteUrl) throws IOException, ReCaptchaException {
final HttpsURLConnection con = (HttpsURLConnection) new URL(siteUrl).openConnection();
try {
con.setRequestMethod("HEAD");
setDefaults(con);
} catch (Exception e) {
/*
* HTTP 429 == Too Many Request Receive from Youtube.com = ReCaptcha challenge
* request See : https://github.com/rg3/youtube-dl/issues/5138
*/
if (con.getResponseCode() == 429) {
throw new ReCaptchaException("reCaptcha Challenge requested", con.getURL().toString());
}
throw new IOException(con.getResponseCode() + " " + con.getResponseMessage(), e);
}
return new DownloadResponse(con.getResponseCode(), null, con.getHeaderFields());
}
@Override
public DownloadResponse get(String siteUrl, DownloadRequest request)
throws IOException, ReCaptchaException {
@@ -183,7 +205,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
}
}
String responseBody = dl(con);
return new DownloadResponse(responseBody, con.getHeaderFields());
return new DownloadResponse(con.getResponseCode(), responseBody, con.getHeaderFields());
}
@Override
@@ -219,6 +241,6 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
sb.append(inputLine);
}
}
return new DownloadResponse(sb.toString(), con.getHeaderFields());
return new DownloadResponse(con.getResponseCode(), sb.toString(), con.getHeaderFields());
}
}