mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +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
|
package com.github.libretube.helpers
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import com.github.libretube.api.CronetHelper
|
import com.github.libretube.api.CronetHelper
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
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
|
* Detect whether the proxy should be used or not for a given stream URL based on user preferences
|
||||||
*/
|
*/
|
||||||
suspend fun unwrapStreamUrl(url: String): String {
|
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.DISABLE_VIDEO_IMAGE_PROXY, false) -> false
|
||||||
PreferenceHelper.getBoolean(PreferenceKeys.FALLBACK_PIPED_PROXY, true) -> isUrlUsable(
|
PreferenceHelper.getBoolean(PreferenceKeys.FALLBACK_PIPED_PROXY, true) -> {
|
||||||
unwrapUrl(url)
|
// check whether the URL has content available, and disable proxy if that's the case
|
||||||
)
|
isUrlUsable(unwrapUrl(url))
|
||||||
|
}
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +62,12 @@ object ProxyHelper {
|
|||||||
*/
|
*/
|
||||||
fun unwrapUrl(url: String, unwrap: Boolean = true) = url.toHttpUrlOrNull()
|
fun unwrapUrl(url: String, unwrap: Boolean = true) = url.toHttpUrlOrNull()
|
||||||
?.takeIf { unwrap }?.let {
|
?.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()
|
it.newBuilder()
|
||||||
.host(it.queryParameter("host").orEmpty())
|
.host(host)
|
||||||
.removeAllQueryParameters("host")
|
.removeAllQueryParameters("host")
|
||||||
.build()
|
.build()
|
||||||
.toString()
|
.toString()
|
||||||
|
@ -42,7 +42,6 @@ import com.github.libretube.util.PlayingQueue
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
|
|
||||||
@ -299,7 +298,7 @@ class OnlinePlayerService : LifecycleService() {
|
|||||||
val streams = streams ?: return
|
val streams = streams ?: return
|
||||||
|
|
||||||
val (uri, mimeType) = if (streams.audioStreams.isNotEmpty()) {
|
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(
|
PlayerHelper.createDashSource(
|
||||||
streams,
|
streams,
|
||||||
this,
|
this,
|
||||||
|
@ -1290,8 +1290,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl(
|
if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl(
|
||||||
streams.dash!!
|
streams.dash!!
|
||||||
).toUri() else {
|
).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 =
|
val shouldDisableProxy =
|
||||||
ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!)
|
ProxyHelper.useYouTubeSourceWithoutProxy(urlToTest)
|
||||||
PlayerHelper.createDashSource(
|
PlayerHelper.createDashSource(
|
||||||
streams,
|
streams,
|
||||||
requireContext(),
|
requireContext(),
|
||||||
|
Loading…
Reference in New Issue
Block a user