From 63def07a0e48287c7e5338f98d822cf38acde38f Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 17 Aug 2019 09:25:49 +0200 Subject: [PATCH 1/3] Add url to recaptcha exceptions, after update in extractor --- app/build.gradle | 2 +- app/src/main/java/org/schabi/newpipe/Downloader.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2ddfecabe..804c09c00 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.TeamNewPipe:NewPipeExtractor:5f65788a2f89e' + implementation 'com.github.Stypox:NewPipeExtractor:06689a2f27edfe83bd4605a1cceed86c06a5ebf8' 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 ff274a91a..11209a01e 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -164,7 +164,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { final ResponseBody body = response.body(); if (response.code() == 429) { - throw new ReCaptchaException("reCaptcha Challenge requested"); + throw new ReCaptchaException("reCaptcha Challenge requested", siteUrl); } if (body == null) { @@ -214,7 +214,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { final ResponseBody body = response.body(); if (response.code() == 429) { - throw new ReCaptchaException("reCaptcha Challenge requested"); + throw new ReCaptchaException("reCaptcha Challenge requested", siteUrl); } if (body == null) { @@ -268,7 +268,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { final ResponseBody body = response.body(); if (response.code() == 429) { - throw new ReCaptchaException("reCaptcha Challenge requested"); + throw new ReCaptchaException("reCaptcha Challenge requested", siteUrl); } if (body == null) { From e66f2ab36b3b826b1ccb5e1b54812af2e417ff66 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 17 Aug 2019 09:27:18 +0200 Subject: [PATCH 2/3] Fix ReCaptchaActivity layout crash due to hidden EditText Closes #2484 --- .../main/res/layout/activity_recaptcha.xml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/activity_recaptcha.xml b/app/src/main/res/layout/activity_recaptcha.xml index 7a4971cd9..1016210ec 100644 --- a/app/src/main/res/layout/activity_recaptcha.xml +++ b/app/src/main/res/layout/activity_recaptcha.xml @@ -1,16 +1,27 @@ - + + + + - - \ No newline at end of file From 43446d56c5a4bd13af9a6b19b80d7f827d35f0e7 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 17 Aug 2019 09:30:42 +0200 Subject: [PATCH 3/3] Load the url from the exception in the ReCaptchaActivity Sometimes YouTube introduces recaptchas only on some pages. By loading the url inside the ReCaptchaException into ReCaptchaActivity's webview, the page that originally caused the problem is shown. The user can then solve the page-specific recaptcha. --- .../org/schabi/newpipe/ReCaptchaActivity.java | 16 +++++++++++----- .../newpipe/fragments/BaseStateFragment.java | 8 +++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java index 74c818bf9..55deeec5f 100644 --- a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java @@ -37,15 +37,24 @@ import android.webkit.WebViewClient; */ public class ReCaptchaActivity extends AppCompatActivity { public static final int RECAPTCHA_REQUEST = 10; + public static final String RECAPTCHA_URL_EXTRA = "recaptcha_url_extra"; public static final String TAG = ReCaptchaActivity.class.toString(); public static final String YT_URL = "https://www.youtube.com"; + private String url; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recaptcha); + url = getIntent().getStringExtra(RECAPTCHA_URL_EXTRA); + if (url == null || url.isEmpty()) { + url = YT_URL; + } + + // Set return to Cancel by default setResult(RESULT_CANCELED); @@ -73,15 +82,12 @@ public class ReCaptchaActivity extends AppCompatActivity { myWebView.clearHistory(); android.webkit.CookieManager cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - cookieManager.removeAllCookies(new ValueCallback() { - @Override - public void onReceiveValue(Boolean aBoolean) {} - }); + cookieManager.removeAllCookies(aBoolean -> {}); } else { cookieManager.removeAllCookie(); } - myWebView.loadUrl(YT_URL); + myWebView.loadUrl(url); } private class ReCaptchaWebViewClient extends WebViewClient { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 4546483d2..e2bf9fb73 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -180,7 +180,7 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC } if (exception instanceof ReCaptchaException) { - onReCaptchaException(); + onReCaptchaException((ReCaptchaException) exception); return true; } else if (exception instanceof IOException) { showError(getString(R.string.network_error), true); @@ -190,11 +190,13 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC return false; } - public void onReCaptchaException() { + public void onReCaptchaException(ReCaptchaException exception) { if (DEBUG) Log.d(TAG, "onReCaptchaException() called"); Toast.makeText(activity, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show(); // Starting ReCaptcha Challenge Activity - startActivityForResult(new Intent(activity, ReCaptchaActivity.class), ReCaptchaActivity.RECAPTCHA_REQUEST); + Intent intent = new Intent(activity, ReCaptchaActivity.class); + intent.putExtra(ReCaptchaActivity.RECAPTCHA_URL_EXTRA, exception.getUrl()); + startActivityForResult(intent, ReCaptchaActivity.RECAPTCHA_REQUEST); showError(getString(R.string.recaptcha_request_toast), false); }