1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Update extractor version and add head request to downloader

This commit is contained in:
TobiGr 2019-10-28 01:12:45 +01:00
parent 4f688862a2
commit c4eaee1e31
2 changed files with 20 additions and 4 deletions

View File

@ -57,7 +57,7 @@ dependencies {
exclude module: 'support-annotations' exclude module: 'support-annotations'
}) })
implementation 'com.github.teamnewpipe:NewPipeExtractor:06f2144e4daa10' implementation 'com.github.teamnewpipe:NewPipeExtractor:v0.17.4'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0' testImplementation 'org.mockito:mockito-core:2.23.0'

View File

@ -221,7 +221,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
return null; return null;
} }
return new DownloadResponse(body.string(), response.headers().toMultimap()); return new DownloadResponse(response.code(), body.string(), response.headers().toMultimap());
} }
@Override @Override
@ -241,7 +241,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
String contentType = requestHeaders.get("Content-Type").get(0); String contentType = requestHeaders.get("Content-Type").get(0);
RequestBody okRequestBody = null; RequestBody okRequestBody = null;
if(null != request.getRequestBody()){ if (null != request.getRequestBody()) {
okRequestBody = RequestBody.create(MediaType.parse(contentType), request.getRequestBody()); okRequestBody = RequestBody.create(MediaType.parse(contentType), request.getRequestBody());
} }
final Request.Builder requestBuilder = new Request.Builder() final Request.Builder requestBuilder = new Request.Builder()
@ -275,6 +275,22 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
return null; return null;
} }
return new DownloadResponse(body.string(), response.headers().toMultimap()); return new DownloadResponse(response.code(), body.string(), response.headers().toMultimap());
} }
@Override
public DownloadResponse head(String siteUrl) throws IOException, ReCaptchaException {
final Request request = new Request.Builder()
.head().url(siteUrl)
.addHeader("User-Agent", USER_AGENT)
.build();
final Response response = client.newCall(request).execute();
if (response.code() == 429) {
throw new ReCaptchaException("reCaptcha Challenge requested", siteUrl);
}
return new DownloadResponse(response.code(), null, response.headers().toMultimap());
}
} }