Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PlaybackEdition>, cap: Int?): PlaybackEdition =
editions.mapIndexed { index, edition -> OpeningCandidate(index, edition, edition.autoFile(cap), cap) }
private fun openingEdition(editions: List<PlaybackEdition>, cap: Int?): PlaybackEdition {
val bestClass = editions.minOf { it.preference }
return editions.filter { it.preference == bestClass }
Comment thread
Quick104 marked this conversation as resolved.
Resolved
.mapIndexed { index, edition -> OpeningCandidate(index, edition, edition.autoFile(cap), cap) }
.minWith(
compareBy<OpeningCandidate> { 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DetailVersionSelectorTest {
)?.fileId

@Test
fun nothingPlayedOpensOnTheEditionHoldingTheBestFile() {
fun nothingPlayedOpensOnThePreferredCutWithItsBestFile() {
assertEquals(1, select())
}

Expand Down Expand Up @@ -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))))
}
Expand Down
Loading