1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-03-15 12:19:45 +00:00

Merge pull request #13310 from absurdlylongusername/add-issue-url-sign-in-not-bot-exception

Add link to FAQ entry to "Sign in to confirm not a bot" exception message
This commit is contained in:
Tobi
2026-03-08 11:00:37 -07:00
committed by GitHub
6 changed files with 52 additions and 13 deletions

View File

@@ -25,6 +25,7 @@ import org.schabi.newpipe.databinding.ActivityErrorBinding
import org.schabi.newpipe.util.Localization
import org.schabi.newpipe.util.ThemeHelper
import org.schabi.newpipe.util.external_communication.ShareUtils
import org.schabi.newpipe.util.text.setTextWithLinks
/**
* This activity is used to show error details and allow reporting them in various ways.
@@ -100,7 +101,7 @@ class ErrorActivity : AppCompatActivity() {
// normal bugreport
buildInfo(errorInfo)
binding.errorMessageView.text = errorInfo.getMessage(this)
binding.errorMessageView.setTextWithLinks(errorInfo.getMessage(this))
binding.errorView.text = formErrorText(errorInfo.stackTraces)
// print stack trace once again for debugging:

View File

@@ -29,6 +29,7 @@ import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentExcepti
import org.schabi.newpipe.ktx.isNetworkRelated
import org.schabi.newpipe.player.mediasource.FailedMediaSource
import org.schabi.newpipe.player.resolver.PlaybackResolver
import org.schabi.newpipe.util.text.getText
/**
* 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(
return getServiceName(serviceId)
}
fun getMessage(context: Context): String {
return message.getString(context)
fun getMessage(context: Context): CharSequence {
return message.getText(context)
}
companion object {
@@ -146,20 +147,23 @@ class ErrorInfo private constructor(
private val stringRes: Int,
private vararg val formatArgs: String
) : Parcelable {
fun getString(context: Context): String {
fun getText(context: Context): CharSequence {
// Ensure locale aware context via ContextCompat.getContextForLanguage() (just in case context is not AppCompatActivity)
val ctx = ContextCompat.getContextForLanguage(context)
return if (formatArgs.isEmpty()) {
// use ContextCompat.getString() just in case context is not AppCompatActivity
ContextCompat.getString(context, stringRes)
ctx.getText(stringRes)
} else {
// ContextCompat.getString() with formatArgs does not exist, so we just
// replicate its source code but with formatArgs
ContextCompat.getContextForLanguage(context).getString(stringRes, *formatArgs)
ctx.resources.getText(stringRes, *formatArgs)
}
}
}
const val SERVICE_NONE = "<unknown_service>"
const val YOUTUBE_IP_BAN_FAQ_URL = "https://newpipe.net/FAQ/#ip-banned-youtube"
private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we
// want to default to SERVICE_NONE
ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name
@@ -247,7 +251,11 @@ class ErrorInfo private constructor(
ErrorMessage(R.string.youtube_music_premium_content)
throwable is SignInConfirmNotBotException ->
ErrorMessage(R.string.sign_in_confirm_not_bot_error, getServiceName(serviceId))
ErrorMessage(
R.string.sign_in_confirm_not_bot_error,
getServiceName(serviceId),
YOUTUBE_IP_BAN_FAQ_URL
)
throwable is ContentNotAvailableException ->
ErrorMessage(R.string.content_not_available)

View File

@@ -16,6 +16,7 @@ import org.schabi.newpipe.MainActivity
import org.schabi.newpipe.R
import org.schabi.newpipe.ktx.animate
import org.schabi.newpipe.util.external_communication.ShareUtils
import org.schabi.newpipe.util.text.setTextWithLinks
class ErrorPanelHelper(
private val fragment: Fragment,
@@ -64,7 +65,7 @@ class ErrorPanelHelper(
fun showError(errorInfo: ErrorInfo) {
ensureDefaultVisibility()
errorTextView.text = errorInfo.getMessage(context)
errorTextView.setTextWithLinks(errorInfo.getMessage(context))
if (errorInfo.recaptchaUrl != null) {
showAndSetErrorButtonAction(R.string.recaptcha_solve) {
@@ -109,7 +110,7 @@ class ErrorPanelHelper(
fun showTextError(errorString: String) {
ensureDefaultVisibility()
errorTextView.text = errorString
errorTextView.setTextWithLinks(errorString)
setRootVisible()
}

View File

@@ -49,7 +49,7 @@ import org.schabi.newpipe.util.NavigationHelper
*/
class MediaBrowserPlaybackPreparer(
private val context: Context,
private val setMediaSessionError: BiConsumer<String, Int>, // error string, error code
private val setMediaSessionError: BiConsumer<CharSequence, Int>, // error string, error code
private val clearMediaSessionError: Runnable,
private val onPrepare: Consumer<Boolean>
) : PlaybackPreparer {
@@ -118,7 +118,7 @@ class MediaBrowserPlaybackPreparer(
private fun onPrepareError(throwable: Throwable) {
setMediaSessionError.accept(
ErrorInfo.getMessage(throwable, null, null).getString(context),
ErrorInfo.getMessage(throwable, null, null).getText(context),
PlaybackStateCompat.ERROR_CODE_APP_ERROR
)
}

View File

@@ -0,0 +1,29 @@
package org.schabi.newpipe.util.text
import android.content.res.Resources
import android.text.SpannableString
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.util.Patterns
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.core.text.parseAsHtml
import androidx.core.text.toHtml
import androidx.core.text.toSpanned
/**
* Takes in a CharSequence [text]
* and makes raw HTTP URLs and HTML anchor tags clickable
*/
fun TextView.setTextWithLinks(text: CharSequence) {
val spanned = SpannableString(text)
// Using the pattern overload of addLinks since the one with the int masks strips all spans from the text before applying new ones
Linkify.addLinks(spanned, Patterns.WEB_URL, null)
this.text = spanned
this.movementMethod = LinkMovementMethod.getInstance()
}
/**
* Gets text from string resource with [id] while preserving styling and allowing string format value substitution of [formatArgs]
*/
fun Resources.getText(@StringRes id: Int, vararg formatArgs: Any?): CharSequence = getText(id).toSpanned().toHtml().format(*formatArgs).parseAsHtml()

View File

@@ -878,7 +878,7 @@
<string name="player_http_403">HTTP error 403 received from server while playing, likely caused by streaming URL expiration or an IP ban</string>
<string name="player_http_invalid_status">HTTP error %1$s received from server while playing</string>
<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>
<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>
<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>
<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>
<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>
<string name="kao_dialog_more_info">Details</string>