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

This commit is contained in:
Bnyro 2024-03-28 16:35:38 +01:00
parent 868bcde79d
commit e637fc59b7
7 changed files with 31 additions and 57 deletions

View File

@ -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"

View File

@ -25,7 +25,7 @@ object DashHelper {
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 doc = builder.newDocument()
@ -118,9 +118,9 @@ object DashHelper {
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)
@ -144,8 +144,7 @@ object DashHelper {
private fun createAudioRepresentation(
doc: Document,
stream: PipedStream,
rewriteUrls: Boolean
stream: PipedStream
): Element {
val representation = doc.createElement("Representation")
representation.setAttribute("bandwidth", stream.bitrate.toString())
@ -160,7 +159,7 @@ object DashHelper {
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)
@ -191,8 +190,7 @@ object DashHelper {
private fun createVideoRepresentation(
doc: Document,
stream: PipedStream,
rewriteUrls: Boolean
stream: PipedStream
): Element {
val representation = doc.createElement("Representation")
representation.setAttribute("codecs", stream.codec!!)
@ -203,7 +201,7 @@ object DashHelper {
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}")

View File

@ -82,11 +82,10 @@ object PlayerHelper {
/**
* 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
@ -336,12 +335,17 @@ object PlayerHelper {
)
val playAutomatically: Boolean
get() = PreferenceHelper
.getBoolean(
get() = PreferenceHelper.getBoolean(
PreferenceKeys.PLAY_AUTOMATICALLY,
true
)
val disablePipedProxy: Boolean
get() = PreferenceHelper.getBoolean(
PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY,
false
)
fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean {
return autoPlayEnabled || (
isPlaylist && PreferenceHelper.getBoolean(

View File

@ -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))
}
else -> true
}
fun unwrapImageUrl(url: String) = if (
!PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false)
) {
url
} else {
fun unwrapStreamUrl(url: String): String {
return if (PlayerHelper.disablePipedProxy) {
unwrapUrl(url)
} else {
url
}
}
fun unwrapImageUrl(url: String): String {
return if (PlayerHelper.disablePipedProxy) {
unwrapUrl(url)
} else {
url
}
}
/**

View File

@ -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

View File

@ -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) {
@ -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

View File

@ -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>