diff --git a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/detail/MediaSelectors.kt b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/detail/MediaSelectors.kt index 4d1277c7d..b7a8b6986 100644 --- a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/detail/MediaSelectors.kt +++ b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/detail/MediaSelectors.kt @@ -555,8 +555,8 @@ private fun BadgePill(text: String) { * Index of the version a video detail page shows for [versions], which is * also the version its Play and Download buttons use. An explicit pick wins. * Auto resolves through [selectDetailPlaybackVersion]: the current edition - * ([editionId], else the last-played one, else the one whose Auto file - * compares best across cuts), then its best file for the quality preference. While the preference + * ([editionId], else the last-played one, else the preferred cut by name + * whose Auto file compares best), then its best file for the quality preference. While the preference * is still loading, Auto names no version (-1, the bare "Auto" placeholder) * unless the viewer picked an edition, so the page never shows a file the * arriving preference contradicts. diff --git a/shared/src/commonMain/kotlin/org/siloserver/silo/playback/DetailVersionSelector.kt b/shared/src/commonMain/kotlin/org/siloserver/silo/playback/DetailVersionSelector.kt index 1a47497ac..1b4da16bc 100644 --- a/shared/src/commonMain/kotlin/org/siloserver/silo/playback/DetailVersionSelector.kt +++ b/shared/src/commonMain/kotlin/org/siloserver/silo/playback/DetailVersionSelector.kt @@ -16,8 +16,8 @@ import org.siloserver.silo.model.settings.QualityPresets * it, so it is normally inside the current edition. * - The edition is [editionId] (the viewer's pick), else the one last played * ([lastEditionKey], where a present "" names the unnamed edition, then the - * edition of [lastFileId]), else the one whose Auto file compares best - * across cuts ([openingEdition]). + * edition of [lastFileId]), else the preferred cut by name whose Auto file + * compares best ([openingEdition]). * - Auto is the edition's best first-part file at or below [preferredQuality], * else the closest file above it, else a file of unknown resolution. History * picks only the edition, with one exception: while the item is @@ -94,20 +94,24 @@ private fun lastPlayedEdition( } /** - * The edition a page opens on with no history: each edition's Auto file - * compared across cuts by fit (within the cap, above it, unknown resolution), - * then resolution (higher within the cap, lower above it), then HDR, then - * edition preference, then server order. File size is not compared across cuts. + * The edition a page opens on with no history, chosen by name first: only the + * cuts in the most preferred [preference] class compete, so a standard cut is + * never passed over for a longer one in better quality. Among those, each + * cut's Auto file is compared by fit (within the cap, above it, unknown + * resolution), then resolution (higher within the cap, lower above it), then + * HDR, then server order. File size is not compared across cuts. */ -private fun openingEdition(editions: List, cap: Int?): PlaybackEdition = - editions.mapIndexed { index, edition -> OpeningCandidate(index, edition, edition.autoFile(cap), cap) } +private fun openingEdition(editions: List, cap: Int?): PlaybackEdition { + val bestClass = editions.minOf { it.preference } + return editions.filter { it.preference == bestClass } + .mapIndexed { index, edition -> OpeningCandidate(index, edition, edition.autoFile(cap), cap) } .minWith( compareBy { it.fit } .thenBy { if (it.fit == 1) it.rank else -it.rank } .thenByDescending { it.auto.hdr } - .thenBy { it.edition.preference } .thenBy { it.index }, ).edition +} private class OpeningCandidate(val index: Int, val edition: PlaybackEdition, val auto: FileVersion, cap: Int?) { val rank = resolutionRank(auto.resolution) diff --git a/shared/src/commonTest/kotlin/org/siloserver/silo/playback/DetailVersionSelectorTest.kt b/shared/src/commonTest/kotlin/org/siloserver/silo/playback/DetailVersionSelectorTest.kt index 2878b0c7a..9373e8fb0 100644 --- a/shared/src/commonTest/kotlin/org/siloserver/silo/playback/DetailVersionSelectorTest.kt +++ b/shared/src/commonTest/kotlin/org/siloserver/silo/playback/DetailVersionSelectorTest.kt @@ -29,7 +29,7 @@ class DetailVersionSelectorTest { )?.fileId @Test - fun nothingPlayedOpensOnTheEditionHoldingTheBestFile() { + fun nothingPlayedOpensOnThePreferredCutWithItsBestFile() { assertEquals(1, select()) } @@ -74,18 +74,20 @@ class DetailVersionSelectorTest { } @Test - fun withNoHistoryEachCutsAutoFileIsComparedAcrossCuts() { + fun withNoHistoryTheCutIsPickedByNameThenQuality() { fun cut(id: Int, key: String?, resolution: String, hdr: Boolean = false, size: Long = 1) = FileVersion(id, resolution = resolution, hdr = hdr, fileSize = size, editionKey = key, editionRaw = key) - // A cut with a file within the cap beats one only above it. + // Name first (unnamed or standard, then theatrical, then any other cut), even over better quality. + assertEquals(1, select(files = listOf(cut(1, "standard", "1080p"), cut(2, "extended", "2160p", hdr = true)))) + assertEquals(2, select(files = listOf(cut(1, "theatrical", "1080p"), cut(2, null, "1080p")))) + assertEquals(2, select(files = listOf(cut(1, "theatrical", "1080p"), cut(2, "standard edition", "1080p")))) + assertEquals(2, select(files = listOf(cut(1, "directors_cut", "1080p", size = 9_000), cut(2, "theatrical", "1080p")))) + // Among equally named cuts, a file within the cap beats one only above it. assertEquals(2, select(preferredQuality = "1080p", files = listOf(cut(1, "imax", "2160p"), cut(2, "extended", "720p")))) // Above the cap, the closer one wins. assertEquals(2, select(preferredQuality = "480p", files = listOf(cut(1, "imax", "2160p"), cut(2, "extended", "720p")))) - // Same resolution: HDR, then edition preference (unnamed or standard, then theatrical); never file size. - assertEquals(2, select(files = listOf(cut(1, "theatrical", "1080p"), cut(2, "directors_cut", "1080p", hdr = true)))) - assertEquals(2, select(files = listOf(cut(1, "directors_cut", "1080p", size = 9_000), cut(2, "theatrical", "1080p")))) - assertEquals(2, select(files = listOf(cut(1, "theatrical", "1080p"), cut(2, null, "1080p")))) - assertEquals(2, select(files = listOf(cut(1, "theatrical", "1080p"), cut(2, "standard edition", "1080p")))) + // Same resolution: HDR; never file size. + assertEquals(2, select(files = listOf(cut(1, "extended", "1080p", size = 9_000), cut(2, "directors_cut", "1080p", hdr = true)))) // A full tie keeps server order. assertEquals(1, select(files = listOf(cut(1, "extended", "1080p"), cut(2, "directors_cut", "1080p", size = 9_000)))) }