mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 05:40:31 +05:30
fix: disabled proxy when lbry stream available
This commit is contained in:
parent
c230be85b5
commit
9cb0725be9
@ -1,5 +1,6 @@
|
||||
package com.github.libretube.helpers
|
||||
|
||||
import android.util.Log
|
||||
import com.github.libretube.api.CronetHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
@ -36,15 +37,15 @@ 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 (shouldDisableProxy(url)) unwrapUrl(url) else url
|
||||
return if (useYouTubeSourceWithoutProxy(url)) unwrapUrl(url) else url
|
||||
}
|
||||
|
||||
suspend fun shouldDisableProxy(url: String) = when {
|
||||
suspend fun useYouTubeSourceWithoutProxy(url: String) = when {
|
||||
!PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false) -> false
|
||||
PreferenceHelper.getBoolean(PreferenceKeys.FALLBACK_PIPED_PROXY, true) -> isUrlUsable(
|
||||
unwrapUrl(url)
|
||||
)
|
||||
|
||||
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))
|
||||
}
|
||||
else -> true
|
||||
}
|
||||
|
||||
@ -61,8 +62,12 @@ object ProxyHelper {
|
||||
*/
|
||||
fun unwrapUrl(url: String, unwrap: Boolean = true) = url.toHttpUrlOrNull()
|
||||
?.takeIf { unwrap }?.let {
|
||||
val host = it.queryParameter("host")
|
||||
// if there's no host parameter specified, there's no way to unwrap the URL
|
||||
// and the proxied one must be used. That's the case if using LBRY.
|
||||
if (host.isNullOrEmpty()) return@let url
|
||||
it.newBuilder()
|
||||
.host(it.queryParameter("host").orEmpty())
|
||||
.host(host)
|
||||
.removeAllQueryParameters("host")
|
||||
.build()
|
||||
.toString()
|
||||
|
@ -42,7 +42,6 @@ import com.github.libretube.util.PlayingQueue
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.encodeToString
|
||||
|
||||
@ -299,7 +298,7 @@ class OnlinePlayerService : LifecycleService() {
|
||||
val streams = streams ?: return
|
||||
|
||||
val (uri, mimeType) = if (streams.audioStreams.isNotEmpty()) {
|
||||
val disableProxy = ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!)
|
||||
val disableProxy = ProxyHelper.useYouTubeSourceWithoutProxy(streams.videoStreams.first().url!!)
|
||||
PlayerHelper.createDashSource(
|
||||
streams,
|
||||
this,
|
||||
|
@ -1290,8 +1290,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl(
|
||||
streams.dash!!
|
||||
).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.shouldDisableProxy(streams.videoStreams.first().url!!)
|
||||
ProxyHelper.useYouTubeSourceWithoutProxy(urlToTest)
|
||||
PlayerHelper.createDashSource(
|
||||
streams,
|
||||
requireContext(),
|
||||
|
Loading…
Reference in New Issue
Block a user