Skip to content

Commit

Permalink
Remove pbj=1 parameter from YouYube urls in recaptcha activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Dec 17, 2020
1 parent 0ced9ba commit fb1eb31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 11 additions & 6 deletions app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@ protected void onCreate(final Bundle savedInstanceState) {
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

String url = getIntent().getStringExtra(RECAPTCHA_URL_EXTRA);
if (url == null || url.isEmpty()) {
url = YT_URL;
}

final String url = getUrlFromIntent();
// set return to Cancel by default
setResult(RESULT_CANCELED);


webView = findViewById(R.id.reCaptchaWebView);

// enable Javascript
Expand Down Expand Up @@ -155,6 +150,16 @@ public boolean onOptionsItemSelected(final MenuItem item) {
}
}

private String getUrlFromIntent() {
final String url = getIntent().getStringExtra(RECAPTCHA_URL_EXTRA);
if (url == null || url.isEmpty()) {
return YT_URL; // YouTube is the most likely service to have thrown a recaptcha
} else {
// remove "pbj=1" parameter from YouYube urls, as it makes the page JSON and not HTML
return url.replace("&pbj=1", "").replace("?pbj=1&", "").replace("?pbj=1", "");
}
}

private void saveCookiesAndFinish() {
handleCookiesFromUrl(webView.getUrl()); // try to get cookies of unclosed page
if (MainActivity.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import java.time.LocalDate
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.util.Calendar
import java.util.TimeZone
Expand All @@ -13,7 +12,7 @@ class OffsetDateTimeToCalendarTest {
@Test
fun testRelativeTimeWithCurrentOffsetDateTime() {
val calendar = LocalDate.of(2020, 1, 1).atStartOfDay().atOffset(ZoneOffset.UTC)
.toCalendar()
.toCalendar()

assertEquals(2020, calendar[Calendar.YEAR])
assertEquals(0, calendar[Calendar.MONTH])
Expand Down

0 comments on commit fb1eb31

Please sign in to comment.