Skip to content

Commit 675d156

Browse files
authored
Merge pull request #13324 from TeamNewPipe/backport-13310-to-release-0.28.4
[Backport release-0.28.4] Add link to FAQ entry to "Sign in to confirm not a bot" exception message
2 parents 816f5f9 + 54021a9 commit 675d156

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.schabi.newpipe.databinding.ActivityErrorBinding
2525
import org.schabi.newpipe.util.Localization
2626
import org.schabi.newpipe.util.ThemeHelper
2727
import org.schabi.newpipe.util.external_communication.ShareUtils
28+
import org.schabi.newpipe.util.text.setTextWithLinks
2829

2930
/**
3031
* This activity is used to show error details and allow reporting them in various ways.
@@ -100,7 +101,7 @@ class ErrorActivity : AppCompatActivity() {
100101

101102
// normal bugreport
102103
buildInfo(errorInfo)
103-
binding.errorMessageView.text = errorInfo.getMessage(this)
104+
binding.errorMessageView.setTextWithLinks(errorInfo.getMessage(this))
104105
binding.errorView.text = formErrorText(errorInfo.stackTraces)
105106

106107
// print stack trace once again for debugging:

app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentExcepti
2929
import org.schabi.newpipe.ktx.isNetworkRelated
3030
import org.schabi.newpipe.player.mediasource.FailedMediaSource
3131
import org.schabi.newpipe.player.resolver.PlaybackResolver
32+
import org.schabi.newpipe.util.text.getText
3233

3334
/**
3435
* An error has occurred in the app. This class contains plain old parcelable data that can be used
@@ -135,8 +136,8 @@ class ErrorInfo private constructor(
135136
return getServiceName(serviceId)
136137
}
137138

138-
fun getMessage(context: Context): String {
139-
return message.getString(context)
139+
fun getMessage(context: Context): CharSequence {
140+
return message.getText(context)
140141
}
141142

142143
companion object {
@@ -146,20 +147,23 @@ class ErrorInfo private constructor(
146147
private val stringRes: Int,
147148
private vararg val formatArgs: String
148149
) : Parcelable {
149-
fun getString(context: Context): String {
150+
fun getText(context: Context): CharSequence {
151+
// Ensure locale aware context via ContextCompat.getContextForLanguage() (just in case context is not AppCompatActivity)
152+
val ctx = ContextCompat.getContextForLanguage(context)
150153
return if (formatArgs.isEmpty()) {
151-
// use ContextCompat.getString() just in case context is not AppCompatActivity
152-
ContextCompat.getString(context, stringRes)
154+
ctx.getText(stringRes)
153155
} else {
154156
// ContextCompat.getString() with formatArgs does not exist, so we just
155157
// replicate its source code but with formatArgs
156-
ContextCompat.getContextForLanguage(context).getString(stringRes, *formatArgs)
158+
ctx.resources.getText(stringRes, *formatArgs)
157159
}
158160
}
159161
}
160162

161163
const val SERVICE_NONE = "<unknown_service>"
162164

165+
const val YOUTUBE_IP_BAN_FAQ_URL = "https://newpipe.net/FAQ/#ip-banned-youtube"
166+
163167
private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we
164168
// want to default to SERVICE_NONE
165169
ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name
@@ -247,7 +251,11 @@ class ErrorInfo private constructor(
247251
ErrorMessage(R.string.youtube_music_premium_content)
248252

249253
throwable is SignInConfirmNotBotException ->
250-
ErrorMessage(R.string.sign_in_confirm_not_bot_error, getServiceName(serviceId))
254+
ErrorMessage(
255+
R.string.sign_in_confirm_not_bot_error,
256+
getServiceName(serviceId),
257+
YOUTUBE_IP_BAN_FAQ_URL
258+
)
251259

252260
throwable is ContentNotAvailableException ->
253261
ErrorMessage(R.string.content_not_available)

app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.schabi.newpipe.MainActivity
1616
import org.schabi.newpipe.R
1717
import org.schabi.newpipe.ktx.animate
1818
import org.schabi.newpipe.util.external_communication.ShareUtils
19+
import org.schabi.newpipe.util.text.setTextWithLinks
1920

2021
class ErrorPanelHelper(
2122
private val fragment: Fragment,
@@ -64,7 +65,7 @@ class ErrorPanelHelper(
6465

6566
fun showError(errorInfo: ErrorInfo) {
6667
ensureDefaultVisibility()
67-
errorTextView.text = errorInfo.getMessage(context)
68+
errorTextView.setTextWithLinks(errorInfo.getMessage(context))
6869

6970
if (errorInfo.recaptchaUrl != null) {
7071
showAndSetErrorButtonAction(R.string.recaptcha_solve) {
@@ -109,7 +110,7 @@ class ErrorPanelHelper(
109110
fun showTextError(errorString: String) {
110111
ensureDefaultVisibility()
111112

112-
errorTextView.text = errorString
113+
errorTextView.setTextWithLinks(errorString)
113114

114115
setRootVisible()
115116
}

app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserPlaybackPreparer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import org.schabi.newpipe.util.NavigationHelper
4949
*/
5050
class MediaBrowserPlaybackPreparer(
5151
private val context: Context,
52-
private val setMediaSessionError: BiConsumer<String, Int>, // error string, error code
52+
private val setMediaSessionError: BiConsumer<CharSequence, Int>, // error string, error code
5353
private val clearMediaSessionError: Runnable,
5454
private val onPrepare: Consumer<Boolean>
5555
) : PlaybackPreparer {
@@ -118,7 +118,7 @@ class MediaBrowserPlaybackPreparer(
118118

119119
private fun onPrepareError(throwable: Throwable) {
120120
setMediaSessionError.accept(
121-
ErrorInfo.getMessage(throwable, null, null).getString(context),
121+
ErrorInfo.getMessage(throwable, null, null).getText(context),
122122
PlaybackStateCompat.ERROR_CODE_APP_ERROR
123123
)
124124
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.schabi.newpipe.util.text
2+
3+
import android.content.res.Resources
4+
import android.text.SpannableString
5+
import android.text.method.LinkMovementMethod
6+
import android.text.util.Linkify
7+
import android.util.Patterns
8+
import android.widget.TextView
9+
import androidx.annotation.StringRes
10+
import androidx.core.text.parseAsHtml
11+
import androidx.core.text.toHtml
12+
import androidx.core.text.toSpanned
13+
14+
/**
15+
* Takes in a CharSequence [text]
16+
* and makes raw HTTP URLs and HTML anchor tags clickable
17+
*/
18+
fun TextView.setTextWithLinks(text: CharSequence) {
19+
val spanned = SpannableString(text)
20+
// Using the pattern overload of addLinks since the one with the int masks strips all spans from the text before applying new ones
21+
Linkify.addLinks(spanned, Patterns.WEB_URL, null)
22+
this.text = spanned
23+
this.movementMethod = LinkMovementMethod.getInstance()
24+
}
25+
26+
/**
27+
* Gets text from string resource with [id] while preserving styling and allowing string format value substitution of [formatArgs]
28+
*/
29+
fun Resources.getText(@StringRes id: Int, vararg formatArgs: Any?): CharSequence = getText(id).toSpanned().toHtml().format(*formatArgs).parseAsHtml()

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@
878878
<string name="player_http_403">HTTP error 403 received from server while playing, likely caused by streaming URL expiration or an IP ban</string>
879879
<string name="player_http_invalid_status">HTTP error %1$s received from server while playing</string>
880880
<string name="youtube_player_http_403">HTTP error 403 received from server while playing, likely caused by an IP ban or streaming URL deobfuscation issues</string>
881-
<string name="sign_in_confirm_not_bot_error">%1$s refused to provide data, asking for a login to confirm the requester is not a bot.\n\nYour IP might have been temporarily banned by %1$s, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).</string>
881+
<string name="sign_in_confirm_not_bot_error">%1$s refused to provide data, asking for a login to confirm the requester is not a bot.\n\nYour IP might have been temporarily banned by %1$s, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).\n\nPlease see <a href="%2$s">this FAQ entry</a> for more information.</string>
882882
<string name="unsupported_content_in_country">This content is not available for the currently selected content country.\n\nChange your selection from \"Settings > Content > Default content country\".</string>
883883
<string name="kao_dialog_warning">In August 2025, Google announced that as of September 2026, installing apps will require developer verification for all Android apps on certified devices, including those installed outside of the Play Store. Since the developers of NewPipe do not agree to this requirement, NewPipe will no longer work on certified Android devices after that time.</string>
884884
<string name="kao_dialog_more_info">Details</string>

0 commit comments

Comments
 (0)