From 06689a2f27edfe83bd4605a1cceed86c06a5ebf8 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 17 Aug 2019 09:09:07 +0200 Subject: [PATCH] Add url to ReCaptchaException Sometimes YouTube introduces recaptchas only on some pages. By adding an url to the ReCaptchaException the NewPipe app is able to use that url to load the page that originally caused the problem. Also removed every instance of exception caught and rethrown with a different description: it makes no sense and it removes part of the useful stacktrace. --- .../newpipe/extractor/exceptions/ReCaptchaException.java | 9 ++++++++- .../youtube/extractors/YoutubeStreamExtractor.java | 2 -- .../schabi/newpipe/extractor/utils/DashMpdParser.java | 2 -- .../src/test/java/org/schabi/newpipe/Downloader.java | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/ReCaptchaException.java b/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/ReCaptchaException.java index 5f0eaee4..09c2a1c0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/ReCaptchaException.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/ReCaptchaException.java @@ -21,7 +21,14 @@ package org.schabi.newpipe.extractor.exceptions; */ public class ReCaptchaException extends ExtractionException { - public ReCaptchaException(String message) { + private String url; + + public ReCaptchaException(String message, String url) { super(message); + this.url = url; + } + + public String getUrl() { + return url; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index a4994391..d1da5376 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -714,8 +714,6 @@ public class YoutubeStreamExtractor extends StreamExtractor { } catch (IOException e) { throw new ParsingException( "Could load decryption code form restricted video for the Youtube service.", e); - } catch (ReCaptchaException e) { - throw new ReCaptchaException("reCaptcha Challenge requested"); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java index 8a994cbd..9c1a8a16 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java @@ -123,8 +123,6 @@ public class DashMpdParser { dashDoc = downloader.download(streamInfo.getDashMpdUrl()); } catch (IOException ioe) { throw new DashMpdParsingException("Could not get dash mpd: " + streamInfo.getDashMpdUrl(), ioe); - } catch (ReCaptchaException e) { - throw new ReCaptchaException("reCaptcha Challenge needed"); } try { diff --git a/extractor/src/test/java/org/schabi/newpipe/Downloader.java b/extractor/src/test/java/org/schabi/newpipe/Downloader.java index c980e1e9..b57160b2 100644 --- a/extractor/src/test/java/org/schabi/newpipe/Downloader.java +++ b/extractor/src/test/java/org/schabi/newpipe/Downloader.java @@ -129,7 +129,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { * request See : https://github.com/rg3/youtube-dl/issues/5138 */ if (con.getResponseCode() == 429) { - throw new ReCaptchaException("reCaptcha Challenge requested"); + throw new ReCaptchaException("reCaptcha Challenge requested", con.getURL().toString()); } throw new IOException(con.getResponseCode() + " " + con.getResponseMessage(), e);