mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-29 08:20:34 +05:30
Backport/Sync code from NewPipe implementation
This commit is contained in:
parent
c892cfaafa
commit
ad5ca4eced
@ -22,8 +22,8 @@ public final class DownloaderTestImpl extends Downloader {
|
|||||||
/**
|
/**
|
||||||
* Should be the latest Firefox ESR version.
|
* Should be the latest Firefox ESR version.
|
||||||
*/
|
*/
|
||||||
private static final String USER_AGENT
|
private static final String USER_AGENT =
|
||||||
= "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0";
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0";
|
||||||
private static DownloaderTestImpl instance;
|
private static DownloaderTestImpl instance;
|
||||||
private final RateLimitedClientWrapper clientWrapper;
|
private final RateLimitedClientWrapper clientWrapper;
|
||||||
|
|
||||||
@ -65,41 +65,36 @@ public final class DownloaderTestImpl extends Downloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final okhttp3.Request.Builder requestBuilder = new okhttp3.Request.Builder()
|
final okhttp3.Request.Builder requestBuilder = new okhttp3.Request.Builder()
|
||||||
.method(httpMethod, requestBody).url(url)
|
.method(httpMethod, requestBody)
|
||||||
|
.url(url)
|
||||||
.addHeader("User-Agent", USER_AGENT);
|
.addHeader("User-Agent", USER_AGENT);
|
||||||
|
|
||||||
for (final Map.Entry<String, List<String>> pair : headers.entrySet()) {
|
headers.forEach((headerName, headerValueList) -> {
|
||||||
final String headerName = pair.getKey();
|
|
||||||
final List<String> headerValueList = pair.getValue();
|
|
||||||
|
|
||||||
if (headerValueList.size() > 1) {
|
|
||||||
requestBuilder.removeHeader(headerName);
|
requestBuilder.removeHeader(headerName);
|
||||||
for (final String headerValue : headerValueList) {
|
headerValueList.forEach(headerValue ->
|
||||||
requestBuilder.addHeader(headerName, headerValue);
|
requestBuilder.addHeader(headerName, headerValue));
|
||||||
}
|
});
|
||||||
} else if (headerValueList.size() == 1) {
|
|
||||||
requestBuilder.header(headerName, headerValueList.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final okhttp3.Response response =
|
|
||||||
clientWrapper.executeRequestWithLimit(requestBuilder.build());
|
|
||||||
|
|
||||||
|
try (okhttp3.Response response =
|
||||||
|
clientWrapper.executeRequestWithLimit(requestBuilder.build())
|
||||||
|
) {
|
||||||
if (response.code() == 429) {
|
if (response.code() == 429) {
|
||||||
response.close();
|
|
||||||
|
|
||||||
throw new ReCaptchaException("reCaptcha Challenge requested", url);
|
throw new ReCaptchaException("reCaptcha Challenge requested", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ResponseBody body = response.body();
|
|
||||||
String responseBodyToReturn = null;
|
String responseBodyToReturn = null;
|
||||||
|
try (ResponseBody body = response.body()) {
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
responseBodyToReturn = body.string();
|
responseBodyToReturn = body.string();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String latestUrl = response.request().url().toString();
|
return new Response(
|
||||||
return new Response(response.code(), response.message(), response.headers().toMultimap(),
|
response.code(),
|
||||||
responseBodyToReturn, latestUrl);
|
response.message(),
|
||||||
|
response.headers().toMultimap(),
|
||||||
|
responseBodyToReturn,
|
||||||
|
response.request().url().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user