Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use hls if piped proxy disabled, remove piped proxy fallback option #5829

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ object PreferenceKeys {
const val UNLIMITED_SEARCH_HISTORY = "unlimited_search_history"
const val SB_HIGHLIGHTS = "sb_highlights"
const val SHOW_TIME_LEFT = "show_time_left"
const val FALLBACK_PIPED_PROXY = "fallback_piped_proxy"
const val ALLOW_PLAYBACK_DURING_CALL = "playback_during_call"
const val BEHAVIOR_WHEN_MINIMIZED = "behavior_when_minimized"

Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/com/github/libretube/helpers/DashHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
val audioLocale: String? = null
)

fun createManifest(streams: Streams, supportsHdr: Boolean, rewriteUrls: Boolean): String {
fun createManifest(streams: Streams, supportsHdr: Boolean): String {

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/DashHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected after opening parenthesis Raw Output: app/src/main/java/com/github/libretube/helpers/DashHelper.kt:28:24: error: Newline expected after opening parenthesis (standard:function-signature)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/DashHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/helpers/DashHelper.kt:28:42: error: Parameter should start on a newline (standard:function-signature)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/DashHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected before closing parenthesis Raw Output: app/src/main/java/com/github/libretube/helpers/DashHelper.kt:28:62: error: Newline expected before closing parenthesis (standard:function-signature)
val builder = builderFactory.newDocumentBuilder()

val doc = builder.newDocument()
Expand Down Expand Up @@ -118,9 +118,9 @@
for (stream in adapSet.formats) {
val rep = let {
if (isVideo) {
createVideoRepresentation(doc, stream, rewriteUrls)
createVideoRepresentation(doc, stream)
} else {
createAudioRepresentation(doc, stream, rewriteUrls)
createAudioRepresentation(doc, stream)
}
}
adapSetElement.appendChild(rep)
Expand All @@ -144,8 +144,7 @@

private fun createAudioRepresentation(
doc: Document,
stream: PipedStream,
rewriteUrls: Boolean
stream: PipedStream

Check failure on line 147 in app/src/main/java/com/github/libretube/helpers/DashHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/helpers/DashHelper.kt:147:28: error: Missing trailing comma before ")" (standard:trailing-comma-on-declaration-site)
): Element {
val representation = doc.createElement("Representation")
representation.setAttribute("bandwidth", stream.bitrate.toString())
Expand All @@ -160,7 +159,7 @@
audioChannelConfiguration.setAttribute("value", "2")

val baseUrl = doc.createElement("BaseURL")
baseUrl.appendChild(doc.createTextNode(ProxyHelper.unwrapUrl(stream.url!!, rewriteUrls)))
baseUrl.appendChild(doc.createTextNode(stream.url!!))

representation.appendChild(audioChannelConfiguration)
representation.appendChild(baseUrl)
Expand Down Expand Up @@ -191,8 +190,7 @@

private fun createVideoRepresentation(
doc: Document,
stream: PipedStream,
rewriteUrls: Boolean
stream: PipedStream

Check failure on line 193 in app/src/main/java/com/github/libretube/helpers/DashHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/helpers/DashHelper.kt:193:28: error: Missing trailing comma before ")" (standard:trailing-comma-on-declaration-site)
): Element {
val representation = doc.createElement("Representation")
representation.setAttribute("codecs", stream.codec!!)
Expand All @@ -203,7 +201,7 @@
representation.setAttribute("frameRate", stream.fps.toString())

val baseUrl = doc.createElement("BaseURL")
baseUrl.appendChild(doc.createTextNode(ProxyHelper.unwrapUrl(stream.url!!, rewriteUrls)))
baseUrl.appendChild(doc.createTextNode(stream.url!!))

val segmentBase = doc.createElement("SegmentBase")
segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}")
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@
/**
* Create a base64 encoded DASH stream manifest
*/
fun createDashSource(streams: Streams, context: Context, disableProxy: Boolean): Uri {
fun createDashSource(streams: Streams, context: Context): Uri {
val manifest = DashHelper.createManifest(
streams,
DisplayHelper.supportsHdr(context),
disableProxy
DisplayHelper.supportsHdr(context)
)

// encode to base64
Expand Down Expand Up @@ -336,12 +335,17 @@
)

val playAutomatically: Boolean
get() = PreferenceHelper
.getBoolean(
get() = PreferenceHelper.getBoolean(
PreferenceKeys.PLAY_AUTOMATICALLY,
true
)

val disablePipedProxy: Boolean
get() = PreferenceHelper.getBoolean(
PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY,

Check failure on line 345 in app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt:345:17: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
false

Check failure on line 346 in app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Unexpected indentation (16) (should be 12) Raw Output: app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt:346:1: error: Unexpected indentation (16) (should be 12) (standard:indent)
)

Check failure on line 347 in app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Unexpected indentation (16) (should be 12) Raw Output: app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt:347:1: error: Unexpected indentation (16) (should be 12) (standard:indent)

Check failure on line 347 in app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt:347:22: error: Missing trailing comma before ")" (standard:trailing-comma-on-call-site)

fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean {
return autoPlayEnabled || (
isPlaylist && PreferenceHelper.getBoolean(
Expand Down
27 changes: 11 additions & 16 deletions app/src/main/java/com/github/libretube/helpers/ProxyHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,20 @@ object ProxyHelper {
/**
* Detect whether the proxy should be used or not for a given stream URL based on user preferences
*/
suspend fun unwrapStreamUrl(url: String): String {
return if (useYouTubeSourceWithoutProxy(url)) unwrapUrl(url) else url
}

suspend fun useYouTubeSourceWithoutProxy(url: String) = when {
!PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false) -> false
PreferenceHelper.getBoolean(PreferenceKeys.FALLBACK_PIPED_PROXY, true) -> {
// check whether the URL has content available, and disable proxy if that's the case
isUrlUsable(unwrapUrl(url))
fun unwrapStreamUrl(url: String): String {
return if (PlayerHelper.disablePipedProxy) {
unwrapUrl(url)
} else {
url
}
else -> true
}

fun unwrapImageUrl(url: String) = if (
!PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false)
) {
url
} else {
unwrapUrl(url)
fun unwrapImageUrl(url: String): String {
return if (PlayerHelper.disablePipedProxy) {
unwrapUrl(url)
} else {
url
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@ class OnlinePlayerService : LifecycleService() {
private suspend fun setMediaItem() {
val streams = streams ?: return

val (uri, mimeType) = if (streams.audioStreams.isNotEmpty()) {
val disableProxy = ProxyHelper.useYouTubeSourceWithoutProxy(
streams.videoStreams.first().url!!
)
val (uri, mimeType) = if (streams.audioStreams.isNotEmpty() && !PlayerHelper.disablePipedProxy) {
PlayerHelper.createDashSource(
streams,
this,
disableProxy
this
) to MimeTypes.APPLICATION_MPD
} else {
ProxyHelper.unwrapStreamUrl(streams.hls.orEmpty()).toUri() to MimeTypes.APPLICATION_M3U8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
!PreferenceHelper.getBoolean(
PreferenceKeys.USE_HLS_OVER_DASH,
false
) && streams.videoStreams.isNotEmpty() -> {
) && streams.videoStreams.isNotEmpty() && !PlayerHelper.disablePipedProxy -> {
// only use the dash manifest generated by YT if either it's a livestream or no other source is available
val dashUri =
if (streams.livestream && streams.dash != null) {
Expand All @@ -1350,16 +1350,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
).toUri()
} else {
// skip LBRY urls when checking whether the stream source is usable
val urlToTest = streams.videoStreams.firstOrNull {
!it.quality.orEmpty().contains("LBRY")
}?.url.orEmpty()
val shouldDisableProxy =
ProxyHelper.useYouTubeSourceWithoutProxy(urlToTest)
PlayerHelper.createDashSource(
streams,
requireContext(),
disableProxy = shouldDisableProxy
)
PlayerHelper.createDashSource(streams, requireContext())
}

dashUri to MimeTypes.APPLICATION_MPD
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/xml/instance_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@
android:title="@string/disable_proxy"
app:key="disable_video_image_proxy" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:dependency="disable_video_image_proxy"
android:icon="@drawable/ic_music"
android:summary="@string/fallback_piped_proxy_summary"
android:title="@string/fallback_piped_proxy"
app:defaultValue="true"
app:key="fallback_piped_proxy" />

</PreferenceCategory>

</PreferenceScreen>
Loading