Swap a heavy booked film to a lighter copy when it's tuned
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 11m3s
release-gate / verify (push) Failing after 14m48s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 2m1s

Films booked this week keep their 4K copies until each channel's weekly refresh.
openBooked now notices a heavy copy (EmbyPlaybackPlan.heavy, from copyWeight),
looks once for a lighter copy of the same film, plays it and updates the plan.
One search per film, only for heavy copies. Roadmap: copies matched to the
household's TV and server at set-up (Paul's idea).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:39:10 +00:00
co-authored by Claude Opus 5.5
parent 0bee17ec42
commit 9e75c9816f
4 changed files with 54 additions and 3 deletions
@@ -80,3 +80,31 @@ class CopyChoiceTest {
assertEquals("aaa1", resolveFilm(FilmIdentity("An American Werewolf in London", 1981), listOf(heavy)).film!!.id)
}
}
/** 13 November 2026: a film already booked as a heavy copy swaps to a lighter one when tuned, searched for once. */
class LighterCopyTest {
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
@org.junit.After fun noServer() { EmbyServer.origin = "" }
private val booked = SampleItem("Fixture Werewolf", "Movie", 97, "", "heavy1", 97 * 60_000L)
private fun source(id: String, width: Int, bitrate: Long) = JSONObject().put("Id", id).put("Container", "mkv").put("Bitrate", bitrate)
.put("SupportsDirectStream", true).put("RunTimeTicks", 97 * 60_000L * 10_000)
.put("MediaStreams", JSONArray().put(JSONObject().put("Type", "Video").put("Codec", if (width > 1920) "hevc" else "h264").put("Width", width)))
@Test fun aHeavyCopyIsMarkedAndALighterOneFoundOnce() {
var searches = 0
val transport = EmbyTransport { r ->
when {
r.path.contains("/PlaybackInfo") -> EmbyReply(200, JSONObject().put("PlaySessionId", "play1").put("ErrorCode", JSONObject.NULL)
.put("MediaSources", JSONArray().put(source("srcheavy1", 3840, 54_000_000))).toString())
r.path.contains("IncludeItemTypes=Movie") -> { searches++; EmbyReply(200, JSONObject().put("Items", JSONArray()
.put(JSONObject().put("Id", "heavy1").put("Type", "Movie").put("Name", "Fixture Werewolf").put("ProductionYear", 1981).put("MediaSources", JSONArray().put(source("srcheavy1", 3840, 54_000_000))))
.put(JSONObject().put("Id", "light1").put("Type", "Movie").put("Name", "Fixture Werewolf").put("ProductionYear", 1981).put("MediaSources", JSONArray().put(source("srclight1", 1920, 9_000_000))))).toString()) }
else -> EmbyReply(404, "")
}
}
val session = EmbySampleSession(transport, "fixture-token-private", "fixture-user", EmbySample(listOf(booked), 1))
assertTrue(session.prepareForTuning(booked, "srcheavy1").heavy)
assertEquals("light1", session.lighterFilm(booked)!!.item.id)
assertNull(session.lighterFilm(booked))
assertEquals(1, searches)
}
}