avoid duplicated resolutions

This commit is contained in:
Bnyro 2022-11-16 19:04:47 +01:00
parent 44163d5659
commit 2acea5fddc

View File

@ -1087,12 +1087,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
val videoStreams = try { val videoStreams = try {
// attempt to sort the qualities, catch if there was an error ih parsing // attempt to sort the qualities, catch if there was an error ih parsing
streams.videoStreams?.sortedBy { streams.videoStreams?.sortedBy {
it.quality it.quality?.toLong() ?: 0L
.toString()
.split("p")
.first()
.replace("p", "")
.toLong()
}?.reversed() }?.reversed()
.orEmpty() .orEmpty()
} catch (_: Exception) { } catch (_: Exception) {
@ -1102,14 +1097,20 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
for (vid in videoStreams) { for (vid in videoStreams) {
// append quality to list if it has the preferred format (e.g. MPEG) // append quality to list if it has the preferred format (e.g. MPEG)
val preferredMimeType = "video/${PlayerHelper.videoFormatPreference}" val preferredMimeType = "video/${PlayerHelper.videoFormatPreference}"
if (vid.url != null && vid.mimeType == preferredMimeType) { // preferred format if (vid.url != null && vid.mimeType == preferredMimeType) {
// avoid duplicated resolutions
if (resolutions.any {
it.resolution == vid.quality.toString().split("p").first().toInt()
}
) continue
resolutions.add( resolutions.add(
VideoResolution( VideoResolution(
name = vid.quality!!, name = vid.quality!!,
resolution = vid.quality.toString().split("p").first().toInt() resolution = vid.quality.toString().split("p").first().toInt()
) )
) )
} else if (vid.quality.equals("LBRY") && vid.format.equals("MP4")) { // LBRY MP4 format } else if (vid.quality.equals("LBRY") && vid.format.equals("MP4")) {
resolutions.add( resolutions.add(
VideoResolution( VideoResolution(
name = "LBRY MP4", name = "LBRY MP4",