mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
chore: use hls if piped proxy disabled, remove piped proxy fallback option
This commit is contained in:
parent
868bcde79d
commit
e637fc59b7
@ -100,7 +100,6 @@ object PreferenceKeys {
|
|||||||
const val UNLIMITED_SEARCH_HISTORY = "unlimited_search_history"
|
const val UNLIMITED_SEARCH_HISTORY = "unlimited_search_history"
|
||||||
const val SB_HIGHLIGHTS = "sb_highlights"
|
const val SB_HIGHLIGHTS = "sb_highlights"
|
||||||
const val SHOW_TIME_LEFT = "show_time_left"
|
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 ALLOW_PLAYBACK_DURING_CALL = "playback_during_call"
|
||||||
const val BEHAVIOR_WHEN_MINIMIZED = "behavior_when_minimized"
|
const val BEHAVIOR_WHEN_MINIMIZED = "behavior_when_minimized"
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ object DashHelper {
|
|||||||
val audioLocale: String? = null
|
val audioLocale: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createManifest(streams: Streams, supportsHdr: Boolean, rewriteUrls: Boolean): String {
|
fun createManifest(streams: Streams, supportsHdr: Boolean): String {
|
||||||
val builder = builderFactory.newDocumentBuilder()
|
val builder = builderFactory.newDocumentBuilder()
|
||||||
|
|
||||||
val doc = builder.newDocument()
|
val doc = builder.newDocument()
|
||||||
@ -118,9 +118,9 @@ object DashHelper {
|
|||||||
for (stream in adapSet.formats) {
|
for (stream in adapSet.formats) {
|
||||||
val rep = let {
|
val rep = let {
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
createVideoRepresentation(doc, stream, rewriteUrls)
|
createVideoRepresentation(doc, stream)
|
||||||
} else {
|
} else {
|
||||||
createAudioRepresentation(doc, stream, rewriteUrls)
|
createAudioRepresentation(doc, stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adapSetElement.appendChild(rep)
|
adapSetElement.appendChild(rep)
|
||||||
@ -144,8 +144,7 @@ object DashHelper {
|
|||||||
|
|
||||||
private fun createAudioRepresentation(
|
private fun createAudioRepresentation(
|
||||||
doc: Document,
|
doc: Document,
|
||||||
stream: PipedStream,
|
stream: PipedStream
|
||||||
rewriteUrls: Boolean
|
|
||||||
): Element {
|
): Element {
|
||||||
val representation = doc.createElement("Representation")
|
val representation = doc.createElement("Representation")
|
||||||
representation.setAttribute("bandwidth", stream.bitrate.toString())
|
representation.setAttribute("bandwidth", stream.bitrate.toString())
|
||||||
@ -160,7 +159,7 @@ object DashHelper {
|
|||||||
audioChannelConfiguration.setAttribute("value", "2")
|
audioChannelConfiguration.setAttribute("value", "2")
|
||||||
|
|
||||||
val baseUrl = doc.createElement("BaseURL")
|
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(audioChannelConfiguration)
|
||||||
representation.appendChild(baseUrl)
|
representation.appendChild(baseUrl)
|
||||||
@ -191,8 +190,7 @@ object DashHelper {
|
|||||||
|
|
||||||
private fun createVideoRepresentation(
|
private fun createVideoRepresentation(
|
||||||
doc: Document,
|
doc: Document,
|
||||||
stream: PipedStream,
|
stream: PipedStream
|
||||||
rewriteUrls: Boolean
|
|
||||||
): Element {
|
): Element {
|
||||||
val representation = doc.createElement("Representation")
|
val representation = doc.createElement("Representation")
|
||||||
representation.setAttribute("codecs", stream.codec!!)
|
representation.setAttribute("codecs", stream.codec!!)
|
||||||
@ -203,7 +201,7 @@ object DashHelper {
|
|||||||
representation.setAttribute("frameRate", stream.fps.toString())
|
representation.setAttribute("frameRate", stream.fps.toString())
|
||||||
|
|
||||||
val baseUrl = doc.createElement("BaseURL")
|
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")
|
val segmentBase = doc.createElement("SegmentBase")
|
||||||
segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}")
|
segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}")
|
||||||
|
@ -82,11 +82,10 @@ object PlayerHelper {
|
|||||||
/**
|
/**
|
||||||
* Create a base64 encoded DASH stream manifest
|
* 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(
|
val manifest = DashHelper.createManifest(
|
||||||
streams,
|
streams,
|
||||||
DisplayHelper.supportsHdr(context),
|
DisplayHelper.supportsHdr(context)
|
||||||
disableProxy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// encode to base64
|
// encode to base64
|
||||||
@ -336,12 +335,17 @@ object PlayerHelper {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val playAutomatically: Boolean
|
val playAutomatically: Boolean
|
||||||
get() = PreferenceHelper
|
get() = PreferenceHelper.getBoolean(
|
||||||
.getBoolean(
|
|
||||||
PreferenceKeys.PLAY_AUTOMATICALLY,
|
PreferenceKeys.PLAY_AUTOMATICALLY,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val disablePipedProxy: Boolean
|
||||||
|
get() = PreferenceHelper.getBoolean(
|
||||||
|
PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean {
|
fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean {
|
||||||
return autoPlayEnabled || (
|
return autoPlayEnabled || (
|
||||||
isPlaylist && PreferenceHelper.getBoolean(
|
isPlaylist && PreferenceHelper.getBoolean(
|
||||||
|
@ -35,25 +35,20 @@ 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 {
|
fun unwrapStreamUrl(url: String): String {
|
||||||
return if (useYouTubeSourceWithoutProxy(url)) unwrapUrl(url) else url
|
return if (PlayerHelper.disablePipedProxy) {
|
||||||
}
|
unwrapUrl(url)
|
||||||
|
} else {
|
||||||
suspend fun useYouTubeSourceWithoutProxy(url: String) = when {
|
url
|
||||||
!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))
|
|
||||||
}
|
}
|
||||||
else -> true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unwrapImageUrl(url: String) = if (
|
fun unwrapImageUrl(url: String): String {
|
||||||
!PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false)
|
return if (PlayerHelper.disablePipedProxy) {
|
||||||
) {
|
unwrapUrl(url)
|
||||||
url
|
} else {
|
||||||
} else {
|
url
|
||||||
unwrapUrl(url)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,14 +325,10 @@ class OnlinePlayerService : LifecycleService() {
|
|||||||
private suspend fun setMediaItem() {
|
private suspend fun setMediaItem() {
|
||||||
val streams = streams ?: return
|
val streams = streams ?: return
|
||||||
|
|
||||||
val (uri, mimeType) = if (streams.audioStreams.isNotEmpty()) {
|
val (uri, mimeType) = if (streams.audioStreams.isNotEmpty() && !PlayerHelper.disablePipedProxy) {
|
||||||
val disableProxy = ProxyHelper.useYouTubeSourceWithoutProxy(
|
|
||||||
streams.videoStreams.first().url!!
|
|
||||||
)
|
|
||||||
PlayerHelper.createDashSource(
|
PlayerHelper.createDashSource(
|
||||||
streams,
|
streams,
|
||||||
this,
|
this
|
||||||
disableProxy
|
|
||||||
) to MimeTypes.APPLICATION_MPD
|
) to MimeTypes.APPLICATION_MPD
|
||||||
} else {
|
} else {
|
||||||
ProxyHelper.unwrapStreamUrl(streams.hls.orEmpty()).toUri() to MimeTypes.APPLICATION_M3U8
|
ProxyHelper.unwrapStreamUrl(streams.hls.orEmpty()).toUri() to MimeTypes.APPLICATION_M3U8
|
||||||
|
@ -1341,7 +1341,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
!PreferenceHelper.getBoolean(
|
!PreferenceHelper.getBoolean(
|
||||||
PreferenceKeys.USE_HLS_OVER_DASH,
|
PreferenceKeys.USE_HLS_OVER_DASH,
|
||||||
false
|
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
|
// only use the dash manifest generated by YT if either it's a livestream or no other source is available
|
||||||
val dashUri =
|
val dashUri =
|
||||||
if (streams.livestream && streams.dash != null) {
|
if (streams.livestream && streams.dash != null) {
|
||||||
@ -1350,16 +1350,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
).toUri()
|
).toUri()
|
||||||
} else {
|
} else {
|
||||||
// skip LBRY urls when checking whether the stream source is usable
|
// skip LBRY urls when checking whether the stream source is usable
|
||||||
val urlToTest = streams.videoStreams.firstOrNull {
|
PlayerHelper.createDashSource(streams, requireContext())
|
||||||
!it.quality.orEmpty().contains("LBRY")
|
|
||||||
}?.url.orEmpty()
|
|
||||||
val shouldDisableProxy =
|
|
||||||
ProxyHelper.useYouTubeSourceWithoutProxy(urlToTest)
|
|
||||||
PlayerHelper.createDashSource(
|
|
||||||
streams,
|
|
||||||
requireContext(),
|
|
||||||
disableProxy = shouldDisableProxy
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dashUri to MimeTypes.APPLICATION_MPD
|
dashUri to MimeTypes.APPLICATION_MPD
|
||||||
|
@ -73,15 +73,6 @@
|
|||||||
android:title="@string/disable_proxy"
|
android:title="@string/disable_proxy"
|
||||||
app:key="disable_video_image_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>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user