Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 15 additions & 7 deletions app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -109,7 +110,7 @@ class ErrorPanelHelper(
fun showTextError(errorString: String) {
ensureDefaultVisibility()

errorTextView.text = errorString
errorTextView.setTextWithLinks(errorString)

setRootVisible()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
absurdlylongusername marked this conversation as resolved.
private val clearMediaSessionError: Runnable,
private val onPrepare: Consumer<Boolean>
) : PlaybackPreparer {
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">the FAQ</a> for more information</string>
Comment thread
TobiGr marked this conversation as resolved.
Outdated
<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>
Expand Down