0.109.1: Advent on Orbit with a planned run-up to each door
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m26s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m41s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 21:37:57 +00:00
co-authored by Claude Opus 5.5
parent 1e19030ab3
commit 0748207892
6 changed files with 95 additions and 24 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 158
versionName = "0.109.0-advent"
versionCode = 159
versionName = "0.109.1-advent"
}
buildFeatures { compose = true }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
@@ -444,6 +444,8 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
val blockRest = HashMap<DayPart?, Long>()
// Fixed slots still ahead of what's booked, soonest first. One whose time has already been filled isn't booked late.
val slots = fixed.filter { it.startMs >= fromMs && it.startMs < untilMs }.sortedBy { it.startMs }.toMutableList()
var planned = mutableListOf<PoolSeries>()
var plannedFor: Long? = null
while (start < untilMs) {
val slot = slots.firstOrNull()
if (slot != null && start >= slot.startMs) {
@@ -481,10 +483,16 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
val dayAppointment = if (part?.onTime == true) null else nextAppointment(start, zone, (ON_TIME_FILM_RUN_IN_MS / (60 * 60_000L)).toInt()) { at -> dayPartFor(pool, dayParts, at, zone) }
val slotAhead = slot?.takeIf { it.startMs - start <= ON_TIME_FILM_RUN_IN_MS && (dayAppointment == null || it.startMs <= dayAppointment) }
// Before a fixed slot, the films are planned as a run that lands on its time: see [runToSlot].
val toSlot = slotAhead?.let { runToSlot(it.startMs, start, films.filter { f -> !avoid(f, start, start + f.episodes.first().durationMs) }, shown, rest) }
fun filmsAt(at: Long) = dayPartFor(pool, dayParts, at, zone).first.filter { f -> f.isFilm && !held(f, at) && !avoid(f, at, at + f.episodes.first().durationMs) }
// Keep to the run already planned for this slot while its next film can still go out now; otherwise plan afresh.
if (slotAhead == null || plannedFor != slotAhead.startMs || planned.firstOrNull()?.let { it !in filmsAt(start) } != false) {
planned = slotAhead?.let { runToSlot(it.startMs, start, ::filmsAt, shown, rest) }.orEmpty().toMutableList()
plannedFor = slotAhead?.startMs
}
val toSlot = planned.removeFirstOrNull()
if (toSlot != null) {
film = toSlot
why = "$why; chosen so the fixed slot at ${java.time.Instant.ofEpochMilli(slotAhead.startMs).atZone(zone).toLocalTime()} starts on time"
why = "$why; chosen so the fixed slot at ${java.time.Instant.ofEpochMilli(slotAhead!!.startMs).atZone(zone).toLocalTime()} starts on time"
}
val appointment = if (toSlot != null) null else listOfNotNull(dayAppointment, slotAhead?.startMs).minOrNull()
if (appointment != null) {
@@ -576,32 +584,37 @@ internal class FixedSlot(val startMs: Long, val film: PoolSeries, val why: Strin
/** A fixed slot whose time has passed by more than this when its turn comes isn't booked at all, rather than booked late. */
internal const val FIXED_SLOT_LATE_MS = 30 * 60_000L
/** How late a run before a fixed slot may finish, tightest first. */
private val FIXED_SLOT_LANDINGS = listOf(5 * 60_000L, 12 * 60_000L, 20 * 60_000L)
private val FIXED_SLOT_LANDINGS = listOf(5 * 60_000L, 12 * 60_000L, 20 * 60_000L, FIXED_SLOT_LATE_MS)
/**
* The first film of a run of up to three, back to back from [start], that ends at [slotMs] or just after it, so a fixed
* slot starts on time. Rested films first, in the planner's seeded order; then, only if no rested run lands, films not
* shown in the last two days. Null when nothing lands, and the planner's own choice stands.
* A run of up to four films, back to back from [start], that ends at [slotMs] or just after it, so a fixed slot starts on
* time; the planner follows it to the slot unless a film in it can no longer go out then. Each film comes from what the channel may show at its own start ([filmsAt]: its block's films,
* held and clashing ones left out), rested first in the planner's seeded order; then, only if no rested run lands, films
* not shown in the last two days. Null when nothing lands, and the planner's own choice stands.
*/
internal fun runToSlot(slotMs: Long, start: Long, films: List<PoolSeries>, shown: Map<String, Long>, restMs: Long): PoolSeries? {
internal fun runToSlot(slotMs: Long, start: Long, filmsAt: (Long) -> List<PoolSeries>, shown: Map<String, Long>, restMs: Long): List<PoolSeries>? {
fun len(f: PoolSeries) = f.episodes.first().durationMs
val remaining = slotMs - start
if (remaining <= 0) return null
val rested = films.filter { f -> shown[f.id]?.let { start - it >= restMs } != false }.shuffled(java.util.Random(start)).take(40)
val recent = films.filter { f -> f !in rested && shown[f.id]?.let { start - it >= 2 * 24 * 60 * 60_000L } != false }.sortedBy { shown[it.id] ?: Long.MIN_VALUE }.take(40)
for (pool in listOf(rested, rested + recent)) for (late in FIXED_SLOT_LANDINGS) {
fun lands(total: Long) = total in remaining..remaining + late
for (a in pool) {
if (len(a) > remaining + late) continue
if (lands(len(a))) return a
for (b in pool) {
if (b === a) continue
val two = len(a) + len(b)
if (two > remaining + late) continue
if (lands(two)) return a
if (pool.any { c -> c !== a && c !== b && lands(two + len(c)) }) return a
val choices = HashMap<Pair<Long, Boolean>, List<PoolSeries>>()
/** The candidates at [at]: rested ones, or with [wider], also those not shown in the last two days. */
fun at(at: Long, wider: Boolean) = choices.getOrPut(at to wider) {
val films = filmsAt(at)
val rested = films.filter { f -> shown[f.id]?.let { at - it >= restMs } != false }.shuffled(java.util.Random(at)).take(30)
if (!wider) rested else rested + films.filter { f -> f !in rested && shown[f.id]?.let { at - it >= 2 * 24 * 60 * 60_000L } != false }.sortedBy { shown[it.id] ?: Long.MIN_VALUE }.take(30)
}
for (late in FIXED_SLOT_LANDINGS) for (wider in listOf(false, true)) {
/** A run continuing [used] ([total] long so far) with up to [more] others that lands in the window, or null. */
fun run(total: Long, used: List<PoolSeries>, more: Int): List<PoolSeries>? {
if (total in remaining..remaining + late) return used
if (more == 0 || total > remaining + late) return null
for (next in at(start + total, wider)) {
if (next in used || total + len(next) > remaining + late) continue
run(total + len(next), used + next, more - 1)?.let { return it }
}
return null
}
run(0, emptyList(), 4)?.let { return it }
}
return null
}
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
connection.connectTimeout = 10_000
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.109.0\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.109.1\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.109.0")
next.setRequestProperty("User-Agent", "OrbitTV/0.109.1")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
+20
View File
@@ -0,0 +1,20 @@
# 0.109.1: Advent on Orbit, with a steadier run-up to each door (replaces 0.109.0, which was never installed)
**What changed from 0.109.0, in `ChannelSchedule.kt` only:** `runToSlot` now plans the whole run of films leading up to a fixed slot, up to four films.
- **Follows the plan:** the planner sticks to that run until the slot, unless a film in it can no longer go out at its time. Before, it re-planned at every pick, which could break the run.
- **Block-aware:** each film in the run comes from what the channel may show at that film's own start, so a run can cross a block boundary.
- **Prefers being on time:** it takes the tightest landing first (5, then 12, 20 and 30 minutes), using films not shown in the last two days before it accepts a later start.
- **Everything else is as in 0.109.0**, documented in VERIFICATION-0.109.0.md: fixed slots only append, a door whose time is already committed is skipped, door films are held for 14 days, and the presentation and What's On rules are unchanged.
## Checks
- 487 unit tests run, 0 failures; lint unchanged (22 warnings, none new).
- **Replay on the box's own files** (as for 0.109.0; `docs/replays/advent-doors-0.109.1.txt`):
- **All 25 doors are booked**, 23 of them within 4 minutes of their time. The exceptions are Door 12 at +16 and Door 22 at +14, both on Premiere, whose films run 2 to 3 hours.
- Door 19 starts at 17:03, and Door 25 at 17:02.
- No overlaps.
- 0 committed plans changed.
- 0 door films in any rotation within their hold.
- Channels differ from the run without Advent only from 22 November.
APK: `outputs/revision-0.109.1`, signed. **Not installed.** It's to be installed between 15 and 20 November, on Paul's word.
+38
View File
@@ -0,0 +1,38 @@
Door 1 612 The Polar Express booked 2026-12-01 18:01 (+1 min) 99 min, key advent.door
Door 2 306 Scrooged booked 2026-12-02 18:04 (+4 min) 101 min, key advent.door
Door 3 309 Get Santa booked 2026-12-03 18:01 (+1 min) 102 min, key advent.door
Door 4 301 Fred Claus booked 2026-12-04 18:03 (+3 min) 115 min, key advent.door
Door 5 306 Home Alone 2: Lost in New York booked 2026-12-05 18:00 (+0 min) 120 min, key advent.door
Door 6 612 Klaus booked 2026-12-06 18:01 (+1 min) 98 min, key advent.door
Door 7 301 The Christmas Chronicles booked 2026-12-07 18:00 (+0 min) 103 min, key advent.door
Door 8 306 The Santa Clause booked 2026-12-08 18:03 (+3 min) 97 min, key advent.door
Door 9 309 A Boy Called Christmas booked 2026-12-09 18:03 (+3 min) 106 min, key advent.door
Door 10 612 The Nightmare Before Christmas booked 2026-12-10 18:03 (+3 min) 76 min, key advent.door
Door 11 306 Jingle All the Way booked 2026-12-11 18:01 (+1 min) 93 min, key advent.door
Door 12 301 How the Grinch Stole Christmas booked 2026-12-12 18:16 (+16 min) 104 min, key advent.door
Door 13 612 Arthur Christmas booked 2026-12-13 18:01 (+1 min) 97 min, key advent.door
Door 14 306 A Christmas Story booked 2026-12-14 18:03 (+3 min) 93 min, key advent.door
Door 15 309 Nativity! booked 2026-12-15 18:01 (+1 min) 105 min, key advent.door
Door 16 612 A Christmas Carol booked 2026-12-16 18:03 (+3 min) 95 min, key advent.door
Door 17 306 Santa Claus: The Movie booked 2026-12-17 18:03 (+3 min) 108 min, key advent.door
Door 18 301 Red One booked 2026-12-18 18:04 (+4 min) 124 min, key advent.door
Door 19 306 National Lampoon's Christmas Vacation booked 2026-12-19 17:03 (+3 min) 97 min, key advent.door
Door 20 612 The Grinch booked 2026-12-20 18:01 (+1 min) 85 min, key advent.door
Door 21 309 Last Christmas booked 2026-12-21 18:02 (+2 min) 102 min, key advent.door
Door 22 301 White Christmas booked 2026-12-22 18:14 (+14 min) 120 min, key advent.door
Door 23 309 Scrooge booked 2026-12-23 18:00 (+0 min) 86 min, key advent.door
Door 24 301 Miracle on 34th Street booked 2026-12-24 18:03 (+3 min) 96 min, key advent.door
Door 25 612 The Muppet Christmas Carol booked 2026-12-25 17:02 (+2 min) 86 min, key advent.door25
overlaps: {}
committed plans changed: 0
door films in rotation within the hold: 0 []
channels whose bookings differ from the run without Advent: [301, 304, 306, 309, 602, 603, 612, 613]
301 first differs at 2026-12-04T13:07:46.770: Apollo 13 -> Mission: Impossible - Fallout | whole pool; picked from 20 rested films, last shown 205h ago; chosen so the fixed slot at 18:00 starts on time
304 first differs at 2026-12-11T05:19:05.418: Paranormal Activity -> The Exorcist | no block, whole pool; picked from 21 rested films, last shown 170h ago
306 first differs at 2026-11-28T04:36:55.215: Home Alone 2: Lost in New York -> Beverly Hills Cop | whole pool; fallback: no film past its rest, so the longest waiting
309 first differs at 2026-12-03T13:38:09.271: Control -> Control | whole pool; fallback: no film past its rest, so the longest waiting; chosen so the fixed slot at 18:00 starts
602 first differs at 2026-12-20T08:01:02.325: Static Shock / S4 E8 / Now You See Him... -> The Batman / S3 E3 / A Dark Knight to Remember | block 6-15; weighted: lowest tally for its tier (412), others resting or just played
603 first differs at 2026-12-28T10:36:23.734: The Transformers / S3 E13 / Madman's Paradise -> Exosquad / S2 E16 / Miracle | block 6-18; weighted: lowest tally for its tier (528), others resting or just played
612 first differs at 2026-11-24T11:54:53.225: Klaus -> Castle in the Sky | whole pool; fallback: no film past its rest, so the longest waiting
613 first differs at 2026-11-22T01:08:03.394: The Polar Express -> How to Train Your Dragon | whole pool; fallback: no film past its rest, so the longest waiting