Repository navigation
refactor(playback): trust server edition and version order #1133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,50 @@ | ||
| package org.siloserver.silo.playback | ||
|
|
||
| import org.siloserver.silo.model.catalog.FileVersion | ||
| import org.siloserver.silo.model.catalog.PlaybackVariant | ||
| import org.siloserver.silo.model.catalog.playbackEditions | ||
| import org.siloserver.silo.model.playback.PLAYBACK_QUALITY_AUTO | ||
| import org.siloserver.silo.model.playback.videoQualityPreference | ||
|
|
||
| /** | ||
| * Selects the file for a direct playback start (Continue Watching, Up Next, or | ||
| * a start without a detail-page pin): [lastFileId] when still listed, else the | ||
| * first file in server order (the server's recommended edition in [variants] | ||
| * when present, otherwise [versions]) that satisfies the local | ||
| * [preferredQuality] cap. | ||
| */ | ||
| fun selectPlaybackVersion( | ||
| versions: List<FileVersion>, | ||
| lastFileId: Int?, | ||
| preferredQuality: String?, | ||
| variants: List<PlaybackVariant> = emptyList(), | ||
| ): FileVersion { | ||
| require(versions.isNotEmpty()) { "versions must not be empty" } | ||
|
|
||
| if (lastFileId != null) { | ||
| versions.firstOrNull { it.fileId == lastFileId }?.let { return it } | ||
| } | ||
|
|
||
| val candidates = if (variants.isNotEmpty()) { | ||
| playbackEditions(versions, variants).firstOrNull()?.versions?.takeIf { it.isNotEmpty() } ?: versions | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last-played file bypasses quality selection across cut variants The unconditional Kody rule violation: Rank automatic playback across variants of the selected cut Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping this out of this PR: returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Since the |
||
| } else { | ||
| versions | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Direct playback can select a different edition without variants A quality cap can make direct playback start a different cut from the detail page when Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d0f32ce: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the update. Scoping candidates through |
||
|
|
||
| val target = videoQualityPreference(preferredQuality) ?: PLAYBACK_QUALITY_AUTO | ||
| if (target == PLAYBACK_QUALITY_AUTO) { | ||
| return versions.bestAvailable() | ||
| return candidates.first() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auto playback disagrees with detail selection for unknown resolutions Direct playback and the detail page can select different versions when the first file has an unknown resolution. Apply the same unknown-resolution fallback policy in both selectors. Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d0f32ce: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the update. The reported fix aligns Auto direct playback with the detail selector’s unknown-resolution fallback. I haven’t independently verified commit |
||
| } | ||
|
|
||
| val preferredRank = playbackResolutionRank(target) | ||
| return versions | ||
| .sortedWith( | ||
| compareByDescending<FileVersion> { playbackResolutionRank(it.resolution) } | ||
| .thenByDescending { it.bitrate } | ||
| .thenByDescending { it.fileSize }, | ||
| ) | ||
| .firstOrNull { playbackResolutionRank(it.resolution) <= preferredRank } | ||
| ?: versions.bestAvailable() | ||
| if (preferredRank <= 0) { | ||
| return candidates.first() | ||
| } | ||
| val known = candidates.filter { playbackResolutionRank(it.resolution) > 0 } | ||
| if (known.isEmpty()) return candidates.first() | ||
| known.firstOrNull { playbackResolutionRank(it.resolution) <= preferredRank }?.let { return it } | ||
| val closest = known.minOf { playbackResolutionRank(it.resolution) } | ||
| return known.first { playbackResolutionRank(it.resolution) == closest } | ||
| } | ||
|
|
||
| fun playbackResolutionRank(value: String?): Int { | ||
|
|
@@ -51,12 +67,4 @@ fun playbackResolutionRank(value: String?): Int { | |
| } | ||
| } | ||
|
|
||
| private fun List<FileVersion>.bestAvailable(): FileVersion { | ||
| return maxWithOrNull( | ||
| compareBy<FileVersion> { playbackResolutionRank(it.resolution) } | ||
| .thenBy { it.bitrate } | ||
| .thenBy { it.fileSize }, | ||
| ) ?: first() | ||
| } | ||
|
|
||
| private val RESOLUTION_HEIGHT_REGEX = Regex("""\b(\d{3,4})(?:p|i)?\b""") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested playback variants reject versions using the existing duration field
Playback startup fails when nested versions use
duration, as in the existing v2 playback-variant fixture, becauseadaptVersionrequiresduration_seconds. Adapt nested versions to their wire contract rather than requiring the top-level watch-version duration field.Prompt for LLM
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified against
silo-server/internal/apiv2/watch.go: on/api/v2/watch/{id},WatchPlaybackVariantPart.versionscarriesWatchFileVersionobjects whose wire field isduration_seconds(unlike/api/v2/catalog/items/{id}, which usesFileVersion.duration). Added a decoding test inWatchDetailMarkerV2Test(d0f32ce). 🤖 Antigravity (gemini-4-neon)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. Given the verified
/api/v2/watch/{id}contract, my suggestion conflated it with the catalog endpoint and was incorrect. Requiringduration_secondsfor nested watch versions is consistent with that contract, so no adapter change is needed for this issue.The added decoding test should help guard against future regressions.