Mistletoe's 10-hour booking: a one-off adb fix, and a hold on odd running times
fix-booking replaces one booking that hasn't started with named films from the channel's own pool, back to back, the last slot running to where it ended; nothing else moves, and the plan file is kept aside. Films whose file runs over 5 hours are held for review (never on Ring X), shown under Schedule health, and released from adb with release-runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* One booking replaced by hand (Paul, 23 November 2026: Mistletoe's "Coming Home for Christmas" was a 10-hour file, booked at
|
||||
* 23:21). The films named take its place, back to back, and the last one's slot runs to where the bad booking ended, the
|
||||
* channel's ident filling the few minutes left as it does after any short file. Nothing else in the plan moves.
|
||||
*
|
||||
* - only a booking that hasn't started, found by its start and its item, is replaced;
|
||||
* - each replacement is a film in the channel's own pool, named once, and not the file being replaced;
|
||||
* - together they fill the slot to within [MAX_LEFTOVER_MS], without running past it;
|
||||
* - the plan file is kept as it was in fix-<time>/ beside the schedules, to put back if wanted.
|
||||
*/
|
||||
internal object BookingFix {
|
||||
const val MAX_LEFTOVER_MS = 30 * 60_000L
|
||||
|
||||
/** The plan with the booking at [startMs] replaced, or why not. */
|
||||
fun replaced(plan: ChannelPlan, pool: List<PoolSeries>, startMs: Long, oldId: String, withIds: List<String>, nowMs: Long): Pair<ChannelPlan?, String> {
|
||||
val at = plan.entries.indexOfFirst { it.startMs == startMs && it.media.item.id == oldId }
|
||||
if (at < 0) return null to "refused: no booking of $oldId at $startMs"
|
||||
val old = plan.entries[at]
|
||||
if (startMs <= nowMs) return null to "refused: it has already started"
|
||||
if (withIds.isEmpty() || withIds.toSet().size != withIds.size || oldId in withIds) return null to "refused: name each replacement once, and not the file itself"
|
||||
val films = withIds.map { id -> pool.firstOrNull { it.id == id && it.isFilm } ?: return null to "refused: $id isn't a film in this channel's pool" }
|
||||
val total = films.sumOf { it.episodes.first().durationMs }
|
||||
val slot = old.media.durationMs
|
||||
if (total > slot) return null to "refused: the films run ${(total - slot) / 60_000} minutes past the slot"
|
||||
if (slot - total > MAX_LEFTOVER_MS) return null to "refused: ${(slot - total) / 60_000} minutes would be left over"
|
||||
var start = startMs
|
||||
val fresh = films.mapIndexed { index, film ->
|
||||
val copy = film.episodes.first()
|
||||
val last = index == films.lastIndex
|
||||
val length = if (last) old.endMs - start else copy.durationMs
|
||||
val item = filmItem(film, copy).let { if (last) it.copy(minutes = length / 60_000, durationMs = length) else it }
|
||||
ScheduleEntry(film.id, copy.mark, ScheduledMedia(item, copy.sourceId, length), start,
|
||||
"replaced a booking whose file ran ${slot / 60_000} minutes (Paul, 23 November 2026)", old.presentation,
|
||||
fileMs = copy.durationMs.takeIf { it != length })
|
||||
.also { start += length }
|
||||
}
|
||||
val entries = plan.entries.toMutableList().apply { removeAt(at); addAll(at, fresh) }
|
||||
val shown = plan.tail.filmShown + fresh.associate { it.seriesId to maxOf(it.startMs, plan.tail.filmShown[it.seriesId] ?: Long.MIN_VALUE) }
|
||||
return ChannelPlan(entries, plan.tail.copy(filmShown = shown)) to "replaced with ${fresh.size} films, ${(slot - total) / 60_000} minutes of ident"
|
||||
}
|
||||
|
||||
/** From adb (household): {"c": channel, "start": ms, "old": item id, "with": [film ids]}. */
|
||||
fun apply(dir: File, userId: String, request: JSONObject, nowMs: Long): String {
|
||||
val channel = request.optInt("c", -1).takeIf { it in 100..999 } ?: return "refused: a bad channel"
|
||||
val oldId = request.optString("old").takeIf(EmbyClient::validId) ?: return "refused: a bad item id"
|
||||
val ids = request.optJSONArray("with") ?: JSONArray()
|
||||
val withIds = (0 until ids.length()).map { ids.optString(it).takeIf(EmbyClient::validId) ?: return "refused: a bad replacement id" }
|
||||
val store = ScheduleStore(dir)
|
||||
synchronized(PlanEdits.lock) {
|
||||
val plan = store.loadPlan(userId, channel) ?: return "refused: no plan for $channel"
|
||||
val pool = store.loadPool(userId, channel)?.series ?: return "refused: no pool for $channel"
|
||||
val (fixed, why) = replaced(plan, pool, request.optLong("start"), oldId, withIds, nowMs)
|
||||
if (fixed == null) return why
|
||||
File(dir, "schedule-$channel.json").takeIf { it.exists() }?.let { val keep = File(dir, "fix-$nowMs").apply { mkdirs() }; it.copyTo(File(keep, it.name), overwrite = true) }
|
||||
store.savePlan(userId, channel, fixed)
|
||||
return "$why (kept fix-$nowMs)"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,7 +422,7 @@ internal class ChannelScheduler(private val store: ScheduleStore,
|
||||
// Under the plan lock, so a programme being re-timed for its real length (PlanEdits) is never written over.
|
||||
val (existing, plan) = synchronized(PlanEdits.lock) {
|
||||
val existing = store.loadPlan(userId, number)
|
||||
val plan = topUpPlan(existing, base, pool?.series?.let { withOpenApprovals(withoutFailed(it, store.loadFailed(userId)), choices) }?.let { if (programming.mixedTurns) mixedTurnOrder(it, number) else it }, now, programming.filmRestMs, programming.finishTogether, programming.dayParts,
|
||||
val plan = topUpPlan(existing, base, pool?.series?.let { withOpenApprovals(withoutOddRuntimes(withoutFailed(it, store.loadFailed(userId)), number, store.runtimeReleases().load()), choices) }?.let { if (programming.mixedTurns) mixedTurnOrder(it, number) else it }, now, programming.filmRestMs, programming.finishTogether, programming.dayParts,
|
||||
avoid = { show, startMs, endMs -> others(show, startMs, endMs) }, shuffle = programming.shuffleEpisodes, mixed = programming::mixes,
|
||||
weightOf = programming.tierWeights?.let { programming::weightOf }, adaptiveRest = programming.adaptiveFilmRest, fileRestMs = programming.fileRestMs, stories = programming.storyGrouping, shorts = programming.shorts, marathon = programming.marathon,
|
||||
seasonEndMs = seasonEndMs(number, now), network = network) ?: throw EmbyCheckException("${programming.name} has no episodes to schedule.")
|
||||
|
||||
@@ -405,7 +405,9 @@ internal fun DirectorChair(load: (DirectorMode) -> DeskReport?, first: FocusRequ
|
||||
/** Your decision on a rotation card: the approved suggestions, the rest dismissed. Returns what to tell you. */
|
||||
decideRotation: suspend (RotationCard, List<RotationProposal>) -> String = { _, _ -> "" },
|
||||
/** Series a channel can only play part of ([gapReport]). */
|
||||
gaps: () -> List<SeriesGap> = { emptyList() }) {
|
||||
gaps: () -> List<SeriesGap> = { emptyList() },
|
||||
/** Films held for an odd running time ([oddRuntimeReport]). */
|
||||
oddRuntimes: () -> List<OddRuntime> = { emptyList() }) {
|
||||
var mode by remember { mutableStateOf(DirectorMode.Balanced) }
|
||||
var version by remember { mutableIntStateOf(0) }
|
||||
var report by remember { mutableStateOf<DeskReport?>(null) }
|
||||
@@ -420,6 +422,8 @@ internal fun DirectorChair(load: (DirectorMode) -> DeskReport?, first: FocusRequ
|
||||
LaunchedEffect(version) { rotationCards = withContext(Dispatchers.Default) { runCatching { rotation() }.getOrDefault(emptyList()) } }
|
||||
var gapList by remember { mutableStateOf(emptyList<SeriesGap>()) }
|
||||
LaunchedEffect(version) { gapList = withContext(Dispatchers.Default) { runCatching { gaps() }.getOrDefault(emptyList()) } }
|
||||
var oddList by remember { mutableStateOf(emptyList<OddRuntime>()) }
|
||||
LaunchedEffect(version) { oddList = withContext(Dispatchers.Default) { runCatching { oddRuntimes() }.getOrDefault(emptyList()) } }
|
||||
val scope = rememberCoroutineScope()
|
||||
LaunchedEffect(mode, version) { withContext(Dispatchers.Default) { runCatching { load(mode) }.getOrNull() }?.let { report = it; OrbitTiming.ready("Settings/Director") } }
|
||||
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
@@ -495,6 +499,7 @@ internal fun DirectorChair(load: (DirectorMode) -> DeskReport?, first: FocusRequ
|
||||
else -> thin.forEach { c -> ChairCard("RUNNING THIN", "${c.channelName} · ${c.block}", "${c.proposals.size} IDEAS", c.line, onClick = { rotationOpen = c }) }
|
||||
}
|
||||
gapList.forEach { g -> ChairCard("SHORT OF EPISODES", "${g.title} · ${g.channelName}", null, g.line) }
|
||||
oddList.forEach { o -> ChairCard("ODD RUNNING TIME", "${o.title} · ${o.channelName}", null, o.line) }
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text("NEEDS YOUR EYE", color = Ink, fontFamily = Anton, fontSize = 14.sp)
|
||||
val asks = r.asks.filter { it.id !in decided }
|
||||
|
||||
@@ -1047,6 +1047,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
} },
|
||||
rotation = { session?.let { active -> rotationReport(scheduleStore, catalogue, active.accountId) }.orEmpty() },
|
||||
gaps = { session?.let { active -> gapReport(scheduleStore, active.accountId) }.orEmpty() },
|
||||
oddRuntimes = { session?.let { active -> oddRuntimeReport(scheduleStore, active.accountId) }.orEmpty() },
|
||||
decideRotation = { card, approved -> withContext(Dispatchers.IO) {
|
||||
val active = session ?: return@withContext "Not connected to the server, so nothing was changed."
|
||||
val applied = runCatching { decideRotation(scheduleStore, active.accountId, card, approved) }.getOrElse { -1 }
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.json.JSONArray
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Odd running times (Paul, 23 November 2026: a 10-hour file of "Coming Home for Christmas" was booked on Mistletoe). A film
|
||||
* whose file runs longer than [ODD_FILM_RUNTIME_MS] isn't booked until you've looked: it's held, not dropped, and shows in the
|
||||
* Director's Chair under Schedule health. Long legitimate films (an extended Return of the King runs about 4 hours 20) stay
|
||||
* under the line, and Ring X's events, which really do run for hours, are never held. Once you've let one through it's booked
|
||||
* as normal. Programmes already booked aren't touched.
|
||||
*/
|
||||
internal const val ODD_FILM_RUNTIME_MS = 5 * 60 * 60_000L
|
||||
/** Channels whose events legitimately run long. */
|
||||
internal val LongEventChannels = setOf(401)
|
||||
|
||||
internal fun isOddRuntime(film: PoolSeries, channel: Int, released: Set<String>) =
|
||||
film.isFilm && channel !in LongEventChannels && film.id !in released && film.episodes.first().durationMs > ODD_FILM_RUNTIME_MS
|
||||
|
||||
internal fun withoutOddRuntimes(pool: List<PoolSeries>, channel: Int, released: Set<String>): List<PoolSeries> =
|
||||
pool.filter { !isOddRuntime(it, channel, released) }
|
||||
|
||||
internal class OddRuntime(val channel: Int, val channelName: String, val id: String, val title: String, val minutes: Long) {
|
||||
val line get() = "Its file runs ${minutes / 60} hours ${minutes % 60} minutes, so it isn't booked until you've looked at it."
|
||||
}
|
||||
|
||||
/** Films held for an odd running time on every channel on the box, from the pools it has kept. Read only. */
|
||||
internal fun oddRuntimeReport(store: ScheduleStore, userId: String): List<OddRuntime> {
|
||||
val released = store.runtimeReleases().load()
|
||||
return SmartChannels.flatMap { p ->
|
||||
store.loadPool(userId, p.number)?.series.orEmpty().filter { isOddRuntime(it, p.number, released) }
|
||||
.map { OddRuntime(p.number, p.name, it.id, it.title, it.episodes.first().durationMs / 60_000) }
|
||||
}
|
||||
}
|
||||
|
||||
/** The films let through. Ids only. */
|
||||
internal class RuntimeReleases(private val file: File) {
|
||||
fun load(): Set<String> = runCatching { JSONArray(file.readText()).let { a -> (0 until a.length()).map { a.getString(it) }.filter(EmbyClient::validId).toSet() } }.getOrDefault(emptySet())
|
||||
fun add(id: String): String {
|
||||
if (!EmbyClient.validId(id)) return "refused: a bad item id"
|
||||
val ids = load() + id
|
||||
writeSafely(file) { out -> out.write(JSONArray(ids.sorted()).toString().toByteArray()) }
|
||||
return "released $id"
|
||||
}
|
||||
}
|
||||
@@ -185,6 +185,8 @@ internal class ScheduleStore(private val directory: File) {
|
||||
|
||||
/** Files that wouldn't play on this box, across every channel. Never planned again. */
|
||||
fun unplayable() = UnplayableLog(File(directory, "failed-reasons-0.json"))
|
||||
/** Films you've looked at and let through despite an odd running time ([RuntimeReview]). */
|
||||
fun runtimeReleases() = RuntimeReleases(File(directory, "runtime-released-0.json"))
|
||||
fun saveFailed(userId: String, ids: Set<String>) =
|
||||
write(file("failed", 0), root(userId, 0).put("items", JSONArray(ids.toList())))
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user