Build 79: Director's Chair stage A event register, ATLAS pinned series

Stage A (approved by Paul, 25 November 2026): every special Orbit runs is now
one SpecialEvent in one register: 55 channel events, 4 takeovers and 18
Drive-In bills. Channels plan with the register's events then their own
everyday blocks; Takeovers and DriveInEvents read the register. Nothing new
is added and nothing on air changes: a 14-day replan of all 42 channels from
one TV snapshot (with every rule, presentation, takeover, age rule, Drive-In
bill, block ident and brand) is byte-identical before and after.

ATLAS: The Killing and The 8 Show are found by their approved IMDb IDs when
a name search's top ten misses them. Only on ATLAS, only for these two, and
only when the search has no exact match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 15:42:28 +00:00
co-authored by Claude Opus 5.5
parent 907b9b35d3
commit 731fc3df2e
10 changed files with 338 additions and 16 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
id("org.jetbrains.kotlin.plugin.compose")
}
/** The release's build number: versionCode is this x 10 plus the edition's channel. */
val ORBIT_BUILD = 78
val ORBIT_BUILD = 79
android {
namespace = "tv.orbit.classic"
compileSdk = 36
@@ -152,3 +152,25 @@ internal object AtlasPlayback {
"per" to "fa", "fas" to "fa", "ara" to "ar", "ice" to "is", "isl" to "is", "dut" to "nl", "nld" to "nl", "tel" to "te",
"tam" to "ta", "mal" to "ml", "kan" to "kn", "ben" to "bn", "mar" to "mr", "vie" to "vi", "cze" to "cs", "ces" to "cs")
}
/**
* ATLAS shows the library holds under their exact names, but which a name search can't reach in its top ten, as so many
* titles share the words (Paul approved both by IMDb ID on 25 November 2026). Only these, only on ATLAS.
*/
internal val AtlasPinnedSeries: Map<String, String> = mapOf("The Killing" to "tt0826760", "The 8 Show" to "tt30423279")
/**
* [candidates] from a name search, or, on ATLAS, when none has the listed name and the show is pinned, the library's
* series with its IMDb ID ([lookup] is one request) that also has the listed name. Every other channel and show: unchanged.
*/
internal fun atlasPinnedCandidates(channel: Int, listed: String, candidates: List<SeriesCandidate>, lookup: (String) -> List<org.json.JSONObject>): List<SeriesCandidate> {
if (channel != ATLAS_NUMBER || candidates.any { seriesKey(it.title) == seriesKey(listed) }) return candidates
val imdb = AtlasPinnedSeries[listed] ?: return candidates
val pinned = runCatching { lookup("imdb.$imdb") }.getOrDefault(emptyList()).mapNotNull { row ->
val id = row.optString("Id"); val title = EmbyClient.clean(row.optString("Name"), 160)
if (row.optString("Type") != "Series" || !EmbyClient.validId(id) || seriesKey(title) != seriesKey(listed)) return@mapNotNull null
SeriesCandidate(id, title, row.optInt("ProductionYear").takeIf { it in 1800..2200 }, EmbyClient.clean(row.optString("OfficialRating"), 40),
ref = providerRef(row, SERIES_REF_ORDER))
}.distinctBy { it.id }
return if (pinned.isEmpty()) candidates else pinned
}
@@ -214,17 +214,34 @@ private val AfterDarkFilms = listOf("The Thing (1982)", "The Evil Dead (1983)",
/** Films Paul added for After Dark's daytime on 18 November 2026. They play late at night too, like the rest of the day list. */
private val AfterDarkDaytimeAdditions get() = listOf("Elvira: Mistress of the Dark", "Creepshow 2", "Dead Heat (1988)", "Burke & Hare (2010)", "Godzilla vs. Biollante")
/** After Dark's rules as written: its events and strand, then night and day. */
private val AfterDarkDayParts get() = AfterDarkEvents + AfterDarkStrand + listOf(DayPart(21, 5), DayPart(5, 21, listOf("The 'Burbs", "'Til Death Do Us Part (2017)", "Tremors (1990)", "The Lost Boys (1987)", "Fright Night (1985)", "Poltergeist (1982)", "Escape from New York", "They Live", "Repo Man", "Donnie Darko", "From Dusk Till Dawn", "Creepshow", "Near Dark", "The Fog (1980)", "Blue Velvet",
"The Wicker Man (1973)", "An American Werewolf in London", "Prince of Darkness") + AfterDarkDaytimeCrossover + AfterDarkDaytimeAdditions, group = "day"))
/**
* Every built-in channel's rules as written, events first (Director's Chair stage A, 25 November 2026). The events go to the
* register ([SpecialEvents]); a channel plans with the register's events, then its own everyday blocks, in the same order as before.
*/
internal val ChannelDayPartSources: Map<Int, List<DayPart>> get() = mapOf(FRONTLINE_NUMBER to FrontlineDayParts, AFTER_DARK_NUMBER to AfterDarkDayParts,
VORTEX_NUMBER to VortexDayParts, 201 to TerraDayParts, TOTS_NUMBER to TotsDayParts, 106 to ParadoxDayParts) +
ChannelPresets.filter { it.smartOnly }.associate { it.number to SmartChannelParts[it.number].orEmpty() }
/** A channel's everyday blocks: its rules with no days of their own. */
internal fun everydayBlocks(number: Int): List<DayPart> = ChannelDayPartSources[number].orEmpty().filter { it.days.isEmpty() }
/** What a built-in channel plans with: its approved events from the register, then its everyday blocks. */
private fun channelParts(number: Int): List<DayPart> = SpecialEvents.dayPartsFor(number) + everydayBlocks(number)
/** Orbit's channels, and any you've made yourself (Create your own), as the planner and every screen see them. */
internal val SmartChannels: List<ChannelProgramming> get() = BuiltInChannels + CustomChannels.programmings
private val BuiltInChannels = listOf(
internal val BuiltInChannels = listOf(
// Frontline (Paul, 23 November 2026): war cinema across every era, with nightly runs of military series. See SilverScreenFrontline.kt.
ChannelProgramming(FRONTLINE_NUMBER, "Frontline", FrontlineFilms, seriesCount = FrontlineFilms.size, filmSeries = FrontlineSeries,
filmRestMs = 7 * 24 * 60 * 60_000L, exactTitles = true, dayParts = FrontlineDayParts),
filmRestMs = 7 * 24 * 60 * 60_000L, exactTitles = true, dayParts = channelParts(FRONTLINE_NUMBER)),
ChannelProgramming(AFTER_DARK_NUMBER, "After Dark", AfterDarkFilms, seriesCount = AfterDarkFilms.size, filmSeries = listOf(LAST_DRIVE_IN) + AfterDarkAnthologies, filmRestMs = 7 * 24 * 60 * 60_000L, adaptiveFilmRest = true,
withdrawnOnOriginal = AfterDarkWithdrawn,
dayParts = AfterDarkEvents + AfterDarkStrand + listOf(DayPart(21, 5), DayPart(5, 21, listOf("The 'Burbs", "'Til Death Do Us Part (2017)", "Tremors (1990)", "The Lost Boys (1987)", "Fright Night (1985)", "Poltergeist (1982)", "Escape from New York", "They Live", "Repo Man", "Donnie Darko", "From Dusk Till Dawn", "Creepshow", "Near Dark", "The Fog (1980)", "Blue Velvet",
"The Wicker Man (1973)", "An American Werewolf in London", "Prince of Darkness") + AfterDarkDaytimeCrossover + AfterDarkDaytimeAdditions, group = "day")),
dayParts = channelParts(AFTER_DARK_NUMBER),
suggestionRules = listOf(
SuggestionRule("day", "Daytime", "Movie", listOf("Horror", "Comedy"), 1975..2010, 6f, setOf("NC-17", "X"), 40, NotCultCinema, 70),
// Capped so the biggest blockbusters stay out: this channel is cult cinema.
@@ -232,21 +249,21 @@ private val BuiltInChannels = listOf(
SuggestionRule("day", "Daytime", "Movie", listOf("Thriller", "Mystery"), 1975..2005, 6.5f, setOf("NC-17", "X"), 30, NotCultCinema + "Science Fiction", 70, 7.9f),
SuggestionRule("late", "Late night", "Movie", listOf("Horror"), 1970..2010, 6f, emptySet(), 90, NotCultCinema, 70))),
ChannelProgramming(VORTEX_NUMBER, "Vortex", VortexShows, seriesCount = 40, finishTogether = true, exactTitles = true, englishAudio = false, tierWeights = VortexTiers, catalogueScaleHours = CATALOGUE_SCALE_HOURS,
dayParts = VortexDayParts, withdrawnOnOriginal = setOf(BEERUS_OTHER_COPY), storyGrouping = true,
dayParts = channelParts(VORTEX_NUMBER), withdrawnOnOriginal = setOf(BEERUS_OTHER_COPY), storyGrouping = true,
suggestionRules = listOf(
SuggestionRule("movie", "Movie Night", "Movie", listOf("Animation"), 1985..2025, 5f, setOf("NC-17", "X"), 30, setOf("Documentary"), 30, titleContains = "Dragon Ball"),
SuggestionRule("movie", "Movie Night", "Movie", listOf("Animation", "Action"), 1985..2015, 7f, setOf("NC-17", "X"), 30, setOf("Documentary", "Family"), 60),
SuggestionRule("day", "Daytime", "Series", listOf("Animation", "Action"), 1985..2015, 7f, setOf("TV-MA"), 30),
SuggestionRule("night", "Evening", "Series", listOf("Anime", "Action"), 1985..2020, 7f, setOf("TV-MA"), 30))),
// Reads every show on its list, as the other curated channels do. Its old limit of 20 dates from when the list was short.
ChannelProgramming(201, "Terra", TerraShows, seriesCount = TerraShows.size, finishTogether = true, exactTitles = true, dayParts = TerraDayParts, storyGrouping = true),
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = TotsDayParts, shuffleEpisodes = true,
ChannelProgramming(201, "Terra", TerraShows, seriesCount = TerraShows.size, finishTogether = true, exactTitles = true, dayParts = channelParts(201), storyGrouping = true),
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = channelParts(TOTS_NUMBER), shuffleEpisodes = true,
tierWeights = TotsTiers, catalogueScaleHours = CATALOGUE_SCALE_HOURS, storyGrouping = true, shorts = TotsShorts),
ChannelProgramming(106, "Paradox", ParadoxShows, seriesCount = 20, finishTogether = true, exactTitles = true, dayParts = ParadoxDayParts, shuffleTitles = (ParadoxStandalones + ParadoxAdult).toSet(),
ChannelProgramming(106, "Paradox", ParadoxShows, seriesCount = 20, finishTogether = true, exactTitles = true, dayParts = channelParts(106), shuffleTitles = (ParadoxStandalones + ParadoxAdult).toSet(),
tierWeights = ParadoxTiers, storyGrouping = true)) +
ChannelPresets.filter { it.smartOnly }.map { ChannelProgramming(it.number, it.name, it.searches, seriesCount = if (it.films) it.searches.size else maxOf(60, it.searches.size), finishTogether = !it.films, exactTitles = true,
filmRestMs = if (it.films) 7 * 24 * 60 * 60_000L else null,
suggestionRules = SmartChannelRules[it.number].orEmpty(), dayParts = SmartChannelParts[it.number].orEmpty(), shuffleTitles = SmartChannelMixed[it.number].orEmpty(),
suggestionRules = SmartChannelRules[it.number].orEmpty(), dayParts = channelParts(it.number), shuffleTitles = SmartChannelMixed[it.number].orEmpty(),
// ATLAS (24 November 2026) plays international programmes in their own language: no English-sound filter; its own
// rule ([AtlasPlayback]) is applied as its pools are read instead.
englishAudio = it.number != ATLAS_NUMBER,
@@ -40,7 +40,10 @@ private fun night(date: String) = LocalDate.parse(date)
* checked against Paul's library when these were approved, never by one server's item. [CuratedDriveInEvents] finds them in
* the library signed in to. What anyone approves or books stays with their own server, apart from these.
*/
internal val DriveInEvents: List<DriveInEvent> = listOf(
internal val DriveInEvents: List<DriveInEvent> get() = SpecialEvents.approvedBills
/** The Drive-In's bills as written, held by the register ([SpecialEvents]); everything else reads [DriveInEvents]. */
internal val DriveInBillDefinitions: List<DriveInEvent> get() = listOf(
DriveInEvent("hammer", "Hammer Horror Double Bill", night("2026-11-13"), 20, 0, listOf(
EventFilm("The Curse of Frankenstein", 1957, "tt0050280"), EventFilm("Dracula", 1958, "tt0051554")), "drivein.fright"),
DriveInEvent("universal", "Universal Monsters Takeover", night("2026-11-14"), 19, 0, listOf(
@@ -438,16 +438,18 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
if (pool.none { it.id == kept.id }) pool += kept
continue
}
val exact = candidates.count { seriesKey(it.title) == seriesKey(search) }
val match = bestSeriesMatch(search, if (programming.exactTitles) candidates.filter { seriesKey(it.title) == seriesKey(search) } else candidates)
// ATLAS's pinned shows (25 November 2026): a name too common for the top ten is found once by its IMDb ID instead.
val found = atlasPinnedCandidates(programming.number, search, candidates) { ref -> requests++; byProvider("Series", ref, "&Fields=ProviderIds,ProductionYear") }
val exact = found.count { seriesKey(it.title) == seriesKey(search) }
val match = bestSeriesMatch(search, if (programming.exactTitles) found.filter { seriesKey(it.title) == seriesKey(search) } else found)
// Counts only, never titles: which list entry found nothing, and at which step, so a missing show can be traced.
if (match == null) { android.util.Log.i("OrbitSchedule", "channel=${programming.number} listed=${index + 1} unmatched candidates=${candidates.size} exact=$exact"); continue }
if (match == null) { android.util.Log.i("OrbitSchedule", "channel=${programming.number} listed=${index + 1} unmatched candidates=${found.size} exact=$exact"); continue }
// A second copy of a show in the library counts as the same show.
if (pool.any { it.id == match.id || seriesKey(it.title) == seriesKey(match.title) }) continue
// A library can hold several copies of one show, one with a single episode and another with the whole run.
// The copy with the most episodes this box can play is the one the channel uses.
// A copy taken off the channel by editorial decision is never read, so it can't stand in for the one chosen.
val copies = (listOf(match) + candidates.filter { it.id != match.id && seriesKey(it.title) == seriesKey(match.title) }.sortedBy { it.year ?: Int.MAX_VALUE })
val copies = (listOf(match) + found.filter { it.id != match.id && seriesKey(it.title) == seriesKey(match.title) }.sortedBy { it.year ?: Int.MAX_VALUE })
.filter { it.id !in programming.withdrawn }.take(MAX_SERIES_COPIES)
val read = try { traced("read") { copies.map { copy -> readWholeSeries(transport, userId, ::currentToken, copy, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio, sourceOk = AtlasPlayback.sourceCheck(programming.number, copy.title)) } } }
catch (failure: EmbyCheckException) {
@@ -0,0 +1,83 @@
package tv.orbit.classic
/**
* The Director's Chair, stage A (approved by Paul on 25 November 2026): every special Orbit runs, in one description.
* A channel's weekly or monthly event, a takeover of a channel's late hours, and a Drive-In bill were three separate kinds
* of thing; here each is a [SpecialEvent] with the same parts: where, what it's called, its titles in order, when, how it's
* presented, and whether it's approved. Stage C's proposals and stage D's calendar read this register.
*
* Stage A changes nothing on air: the register holds exactly what each channel, takeover and Drive-In bill did before
* (StageABaselineTest compares full plans from one TV snapshot before and after).
*/
internal enum class SpecialKind { ChannelEvent, Takeover, DriveInBill }
/** Approved specials run; proposals (stage C) wait for Paul and never book. Everything in stage A is approved. */
internal enum class SpecialStatus { Approved, Proposed }
internal class SpecialEvent(
/** Unique and stable: the channel, then the event's presentation key, group or first title. */
val id: String,
val kind: SpecialKind,
/** The channel it's on; the Drive-In's own number for a bill. */
val channel: Int,
val name: String,
/** In order: a bill's films, an event's series or films. */
val titles: List<String>,
/** When, in words, for the calendar: "Fridays 20:00–00:00, on time", "first Friday of the month 23:00", "Sat 5 Dec 20:00". */
val recurrence: String,
/** Its presentation key (block ident, takeover look or Drive-In identity), or "" for none. */
val presentation: String,
val status: SpecialStatus = SpecialStatus.Approved,
/** A channel event's exact scheduling rule, as the planner uses it. */
val part: DayPart? = null,
val takeover: Takeover? = null,
val bill: DriveInEvent? = null)
private val DayNames = mapOf(java.time.DayOfWeek.MONDAY to "Mon", java.time.DayOfWeek.TUESDAY to "Tue", java.time.DayOfWeek.WEDNESDAY to "Wed",
java.time.DayOfWeek.THURSDAY to "Thu", java.time.DayOfWeek.FRIDAY to "Fri", java.time.DayOfWeek.SATURDAY to "Sat", java.time.DayOfWeek.SUNDAY to "Sun")
/** A channel event's rule in words. */
internal fun recurrenceOf(part: DayPart): String {
val days = part.days.sorted().joinToString(", ") { DayNames.getValue(it) }
val week = part.monthWeek?.let { w -> " (week $w of the month)" }.orEmpty()
val rules = listOfNotNull("premiere nights".takeIf { part.premiereNights == true }, "other nights".takeIf { part.premiereNights == false },
"premieres".takeIf { part.premiere }, "on time".takeIf { part.onTime }, "one a night".takeIf { part.once }, "${part.run} in a row".takeIf { part.run > 1 },
part.from?.let { "from $it" }).joinToString(", ")
return "$days$week %02d:00–%02d:00".format(part.fromHour, part.toHour) + if (rules.isEmpty()) "" else ", $rules"
}
internal object SpecialEvents {
/** Each channel's events, from its rules as written, kept once so every reader plans with the very same rule. */
private val channelEventParts: Map<Int, List<DayPart>> by lazy {
ChannelDayPartSources.toSortedMap().mapValues { (_, parts) -> parts.filter { it.days.isNotEmpty() } }.filterValues { it.isNotEmpty() }
}
private val takeoverList: List<Takeover> by lazy { TakeoverDefinitions }
private val billList: List<DriveInEvent> by lazy { DriveInBillDefinitions }
/** Every special, in order: channel events by channel, then takeovers, then Drive-In bills. */
val all: List<SpecialEvent> by lazy { channelEvents() + takeovers() + driveInBills() }
/** A channel's approved events, in its own order, for its planner. */
fun dayPartsFor(channel: Int): List<DayPart> = all.filter { it.kind == SpecialKind.ChannelEvent && it.channel == channel && it.status == SpecialStatus.Approved }.map { it.part!! }
val approvedTakeovers: List<Takeover> get() = all.filter { it.kind == SpecialKind.Takeover && it.status == SpecialStatus.Approved }.map { it.takeover!! }
val approvedBills: List<DriveInEvent> get() = all.filter { it.kind == SpecialKind.DriveInBill && it.status == SpecialStatus.Approved }.map { it.bill!! }
private fun channelEvents(): List<SpecialEvent> = channelEventParts.flatMap { (number, parts) ->
parts.map { part ->
val label = part.key.ifEmpty { part.group }.ifEmpty { part.titles.firstOrNull().orEmpty() }
val nights = when (part.premiereNights) { true -> ":premiere"; false -> ":other"; null -> "" }
SpecialEvent("$number:$label:${part.days.sorted().joinToString("") { DayNames.getValue(it) }}:${part.fromHour}$nights", SpecialKind.ChannelEvent, number,
part.group.ifEmpty { label }, part.titles, recurrenceOf(part), part.key, part = part)
}
}
private fun takeovers(): List<SpecialEvent> = takeoverList.map { t ->
SpecialEvent("${t.channel}:${t.key}", SpecialKind.Takeover, t.channel, t.name, t.titles, "nightly %02d:00–%02d:00".format(t.fromHour, t.toHour) +
if (t.byTheClock) ", by the clock" else "", t.key, takeover = t)
}
private fun driveInBills(): List<SpecialEvent> = billList.map { e ->
SpecialEvent("$DRIVE_IN_NUMBER:${e.key}", SpecialKind.DriveInBill, DRIVE_IN_NUMBER, e.name, e.films.map { "${it.title} (${it.year})" },
"${e.evening} %02d:%02d".format(e.hour, e.minute), e.presentation, bill = e)
}
}
@@ -52,7 +52,9 @@ internal val NITE_OWL = Takeover(611, "junior.niteowl", "Nite Owl", Color(0xFFFF
internal val TOTS_DREAMTIME = Takeover(TOTS_NUMBER, "tots.dreamtime", "Tots Dreamtime", Color(0xFFC9B8FF), 19, 6, TotsWindDown, TakeoverHost.NightCap, "Bedtime shows with Luna",
kidsSafe = true, byTheClock = true)
internal val TERRA_STARLIGHT = Takeover(201, "terra.starlight", "Terra Starlight", Color(0xFF6EDCAA), 23, 3, TerraStarlightShows, TakeoverHost.Drift, "Space and the night sky till 3am", kidsSafe = true)
internal val Takeovers get() = listOf(TOONZ_LATE, NITE_OWL, TOTS_DREAMTIME, TERRA_STARLIGHT)
/** The takeovers as written; the register ([SpecialEvents]) holds them, and everything else reads [Takeovers]. */
internal val TakeoverDefinitions get() = listOf(TOONZ_LATE, NITE_OWL, TOTS_DREAMTIME, TERRA_STARLIGHT)
internal val Takeovers: List<Takeover> get() = SpecialEvents.approvedTakeovers
/** A takeover as a block of its channel's day: its own titles, equal turns, its name on the plan. */
internal fun takeoverPart(t: Takeover) = DayPart(t.fromHour, t.toHour, t.titles, group = t.name, key = t.key, weighted = false)
@@ -0,0 +1,68 @@
package tv.orbit.classic
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* Build 79's ATLAS naming fix: The Killing and The 8 Show are in the library under their exact names, but a name search's
* top ten held neither (25 November 2026: ten candidates, none exact). On ATLAS they're found once by their IMDb IDs.
*/
class AtlasPinnedSeriesTest {
private fun near(vararg names: String) = names.mapIndexed { i, n -> SeriesCandidate("${100 + i}", n, 2010 + i, "TV-14") }
private fun row(id: String, name: String, year: Int, type: String = "Series") =
JSONObject().put("Id", id).put("Name", name).put("Type", type).put("ProductionYear", year).put("ProviderIds", JSONObject().put("Imdb", "x"))
// What a name search returns: shows sharing the words, sorted by name, none of them the one listed.
private val killingSearch = near("A Killing in the Family", "Killing Eve", "Killing Fields", "Killing Kennedy", "Killing Lincoln", "The Killing Floor",
"The Killing Game", "The Killing of America", "The Killing Season", "The Killings at Badger's Drift")
private val eightSearch = near("8 Simple Rules", "8 Out of 10 Cats", "The Show", "The Late Show", "The Muppet Show", "The Big Show Show",
"The Graham Norton Show", "The Truman Show", "That '70s Show", "The 80s Show")
@Test fun theKillingIsFoundByItsImdbIdOnAtlas() {
val asked = mutableListOf<String>()
val found = atlasPinnedCandidates(ATLAS_NUMBER, "The Killing", killingSearch) { asked += it; listOf(row("3725924", "The Killing", 2007)) }
assertEquals(listOf("imdb.tt0826760"), asked)
val match = bestSeriesMatch("The Killing", found.filter { seriesKey(it.title) == seriesKey("The Killing") })!!
assertEquals("3725924", match.id); assertEquals(2007, match.year)
}
@Test fun theEightShowIsFoundByItsImdbIdOnAtlas() {
val asked = mutableListOf<String>()
val found = atlasPinnedCandidates(ATLAS_NUMBER, "The 8 Show", eightSearch) { asked += it; listOf(row("3442711", "The 8 Show", 2024)) }
assertEquals(listOf("imdb.tt30423279"), asked)
assertEquals("3442711", bestSeriesMatch("The 8 Show", found)!!.id)
}
@Test fun bothKeepTheirAtlasPlaybackRule() {
assertEquals(AtlasTracks("da", subtitles = true), AtlasPlayback.forProgramme(ATLAS_NUMBER, "The Killing / S1 E1 / Day 1"))
assertEquals(AtlasTracks("ko", subtitles = true), AtlasPlayback.forProgramme(ATLAS_NUMBER, "The 8 Show / S1 E1 / Episode 1"))
}
@Test fun bothStayListedOnAtlasUnderTheirOwnNames() {
assertTrue("The Killing" in AtlasShows); assertTrue("The 8 Show" in AtlasShows)
}
@Test fun noExtraRequestWhenTheSearchAlreadyFindsIt() {
val withExact = killingSearch + SeriesCandidate("3725924", "The Killing", 2007, "TV-14")
val found = atlasPinnedCandidates(ATLAS_NUMBER, "The Killing", withExact) { error("no lookup") }
assertEquals(withExact, found)
}
@Test fun otherChannelsAndOtherShowsAreUnchanged() {
assertEquals(killingSearch, atlasPinnedCandidates(EVIDENCE_PROBE, "The Killing", killingSearch) { error("no lookup") })
assertEquals(killingSearch, atlasPinnedCandidates(ATLAS_NUMBER, "Borgen", killingSearch) { error("no lookup") })
}
@Test fun aDifferentShowUnderTheIdIsNeverTaken() {
assertEquals(killingSearch, atlasPinnedCandidates(ATLAS_NUMBER, "The Killing", killingSearch) { listOf(row("9", "The Killing (2011)", 2011)) })
assertEquals(killingSearch, atlasPinnedCandidates(ATLAS_NUMBER, "The Killing", killingSearch) { listOf(row("9", "The Killing", 2007, type = "Movie")) })
}
@Test fun aFailedLookupLeavesTheSearchAsItWas() {
assertEquals(eightSearch, atlasPinnedCandidates(ATLAS_NUMBER, "The 8 Show", eightSearch) { throw EmbyCheckException("down", 503) })
}
private companion object { const val EVIDENCE_PROBE = 107 }
}
@@ -0,0 +1,72 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/** Director's Chair stage A, step 1: every special Orbit already runs is in the register exactly once, and nothing else is. */
class SpecialEventsTest {
private val all = SpecialEvents.all
@Test fun idsAreUnique() {
val dupes = all.groupBy { it.id }.filterValues { it.size > 1 }.keys
assertTrue("duplicate ids: $dupes", dupes.isEmpty())
}
@Test fun everyChannelEventIsThereExactlyOnce() {
val expected = BuiltInChannels.flatMap { p -> p.dayParts.filter { it.days.isNotEmpty() }.map { p.number to it } }
val held = all.filter { it.kind == SpecialKind.ChannelEvent }.map { it.channel to it.part!! }
// Identity, not equality: the very same rule each channel plans with, once each.
expected.forEach { (n, part) -> assertEquals("channel $n ${part.key}${part.group}", 1, held.count { it.first == n && it.second === part }) }
assertEquals(expected.size, held.size)
assertEquals(55, held.size)
}
@Test fun everyTakeoverIsThereExactlyOnce() {
val held = all.filter { it.kind == SpecialKind.Takeover }.map { it.takeover!! }
Takeovers.forEach { t -> assertEquals(t.key, 1, held.count { it === t }) }
assertEquals(4, held.size)
}
@Test fun everyDriveInBillIsThereExactlyOnce() {
val held = all.filter { it.kind == SpecialKind.DriveInBill }.map { it.bill!! }
DriveInEvents.forEach { e -> assertEquals(e.key, 1, held.count { it === e }) }
assertEquals(DriveInEvents.size, held.size)
assertEquals(18, held.size)
}
@Test fun stageAAddsNothingAndEverythingIsApproved() {
assertEquals(55 + 4 + 18, all.size)
assertTrue(all.all { it.status == SpecialStatus.Approved })
}
@Test fun eachSpecialKeepsItsPresentationAndTitles() {
all.forEach { s ->
when (s.kind) {
SpecialKind.ChannelEvent -> { assertEquals(s.part!!.key, s.presentation); assertEquals(s.part.titles, s.titles) }
SpecialKind.Takeover -> { assertEquals(s.takeover!!.key, s.presentation); assertEquals(s.takeover.titles, s.titles) }
SpecialKind.DriveInBill -> { assertEquals(s.bill!!.presentation, s.presentation); assertEquals(s.bill.films.size, s.titles.size) }
}
}
}
/** Step 2 keeps each channel's order only because every channel writes its events before its everyday blocks. */
@Test fun everyChannelListsItsEventsFirst() {
ChannelDayPartSources.forEach { (n, parts) ->
val firstBlock = parts.indexOfFirst { it.days.isEmpty() }
assertTrue("channel $n has an event after a block", firstBlock < 0 || parts.drop(firstBlock).all { it.days.isEmpty() })
}
}
@Test fun channelsTakeoversAndTheDriveInReadTheRegister() {
BuiltInChannels.forEach { p ->
val events = p.dayParts.filter { it.days.isNotEmpty() }
assertEquals(SpecialEvents.dayPartsFor(p.number).size, events.size)
events.zip(SpecialEvents.dayPartsFor(p.number)).forEach { (a, b) -> assertTrue(a === b) }
}
Takeovers.zip(SpecialEvents.approvedTakeovers).forEach { (a, b) -> assertTrue(a === b) }
DriveInEvents.zip(SpecialEvents.approvedBills).forEach { (a, b) -> assertTrue(a === b) }
assertEquals(TakeoverDefinitions.map { it.key }, Takeovers.map { it.key })
assertEquals(DriveInBillDefinitions.map { it.key }, DriveInEvents.map { it.key })
}
}
@@ -0,0 +1,53 @@
package tv.orbit.classic
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
import java.time.ZoneId
/**
* Director's Chair stage A (Paul, 25 November 2026): a full record of what Orbit would book and present, from one pulled TV
* snapshot (STAGE_A_SNAP=<schedule dir>), written to STAGE_A_OUT. Run on the code before and after the migration; the two
* files must be identical. Every channel is planned for 14 days from a fixed moment, as its top-up would, with its own
* blocks, events, tiers, story order, film rest and approvals. Alongside: every event part with all its rules, the
* takeovers, the Drive-In bills, the block idents and each booking's presentation.
*/
class StageABaselineTest {
@Test fun record() {
val dir = System.getenv("STAGE_A_SNAP")?.let(::File)
assumeTrue(dir != null && dir.isDirectory)
val out = StringBuilder()
val zone = ZoneId.of("Europe/London")
val now = java.time.LocalDateTime.of(2026, 11, 30, 6, 0).atZone(zone).toInstant().toEpochMilli()
val user = dir!!.listFiles()!!.first { it.name.startsWith("schedule-") }.let { org.json.JSONObject(it.readText()).getString("user") }
val store = ScheduleStore(dir)
fun part(p: DayPart) = "from=${p.fromHour} to=${p.toHour} days=${p.days.sorted()} onTime=${p.onTime} once=${p.once} key=${p.key} group=${p.group} weighted=${p.weighted} " +
"weights=${p.weights.toSortedMap()} start=${p.from} premiere=${p.premiere}/${p.premiereDouble}/${p.premiereBuffer} nights=${p.premiereNights} grace=${p.graceMs} run=${p.run} " +
"shuffled=${p.shuffled} rotating=${p.rotating}/${p.rotateCap}/${p.rotateWeekHours} monthWeek=${p.monthWeek} titles=${p.titles}"
for (p in SmartChannels.sortedBy { it.number }) {
out.append("## channel ${p.number} ${p.name}\n")
p.dayParts.forEachIndexed { i, d -> out.append("part $i ${part(d)}\n") }
out.append("films=${p.channelFilms} filmSeries=${p.filmSeries} englishAudio=${p.englishAudio} rest=${p.filmRestMs} locked=${p.number in LockedChannels}\n")
val pool = store.loadPool(user, p.number)?.series ?: continue
val choices = store.loadChoices(user, p.number)
val plan = topUpPlan(null, ScheduleCursor(), withOpenApprovals(pool, choices).let { if (p.mixedTurns) mixedTurnOrder(it, p.number) else it }, now,
p.filmRestMs, p.finishTogether, p.dayParts, zone, shuffle = p.shuffleEpisodes, mixed = p::mixes,
weightOf = p.tierWeights?.let { p::weightOf }, adaptiveRest = p.adaptiveFilmRest, fileRestMs = p.fileRestMs, stories = p.storyGrouping,
shorts = p.shorts, marathon = p.marathon, seasonEndMs = seasonEndMs(p.number, now)) ?: continue
plan.entries.forEach { e ->
out.append("${e.startMs} ${e.endMs} ${e.media.durationMs} item=${e.media.item.id} src=${e.media.sourceId} series=${e.seriesId} mark=${e.mark.season}.${e.mark.episode} " +
"file=${e.fileMs} presentation=${presentationOf(e, p.dayParts, zone)} why=${e.why} " +
"takeover=${takeoverOf(p.number, e, zone)?.let { "${it.key}/kidsSafe=${it.kidsSafe}" }}\n")
}
}
out.append("## takeovers\n")
Takeovers.forEach { t -> out.append("${t.channel} ${t.key} ${t.name} ${t.colour} ${t.fromHour}-${t.toHour} ${t.host} kids=${t.kidsSafe} clock=${t.byTheClock} ${t.line} ${t.titles}\n") }
out.append("## drive-in\n")
DriveInEvents.forEach { e -> out.append("${e.key} ${e.name} ${e.evening} ${e.hour}:${e.minute} presentation=${e.presentation} person=${e.person} films=${e.films.map { "${it.title}|${it.year}|${it.imdb}" }}\n") }
out.append("## block idents\n")
BlockIdents.toSortedMap().forEach { (k, v) -> out.append("$k ${v.video} ${v.sting} ${v.overlay}\n") }
out.append("## branding\n")
SmartChannels.sortedBy { it.number }.forEach { p -> ChannelBrands.forNumber(p.number)?.let { b -> out.append("${p.number} ${b.presetId} ${b.displayName} ${b.logo} ${b.background} ${b.bug} ${b.category}\n") } }
File(System.getenv("STAGE_A_OUT") ?: "/tmp/stage-a.txt").writeText(out.toString())
}
}