From c4eaee1e312cfe7c367fb7ac712359852afe0316 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Mon, 28 Oct 2019 01:12:45 +0100 Subject: [PATCH] Update extractor version and add head request to downloader --- app/build.gradle | 2 +- .../java/org/schabi/newpipe/Downloader.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 13aae3619..5f34a2a2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.teamnewpipe:NewPipeExtractor:06f2144e4daa10' + implementation 'com.github.teamnewpipe:NewPipeExtractor:v0.17.4' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index ae76d5623..a8a581d1b 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -221,7 +221,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { return null; } - return new DownloadResponse(body.string(), response.headers().toMultimap()); + return new DownloadResponse(response.code(), body.string(), response.headers().toMultimap()); } @Override @@ -241,7 +241,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { String contentType = requestHeaders.get("Content-Type").get(0); RequestBody okRequestBody = null; - if(null != request.getRequestBody()){ + if (null != request.getRequestBody()) { okRequestBody = RequestBody.create(MediaType.parse(contentType), request.getRequestBody()); } final Request.Builder requestBuilder = new Request.Builder() @@ -275,6 +275,22 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { 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()); + } + } \ No newline at end of file