0.87.0: Orbit Three, Gold and Riot identities, fair block rotation
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m45s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m28s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-03 13:09:33 +00:00
co-authored by Claude Opus 5.5
parent fc2b8f18d3
commit 1d233c08bb
15 changed files with 191 additions and 39 deletions
@@ -13,7 +13,7 @@ private val Weekend = setOf(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY)
private val Orbit1Family = listOf("The Fresh Prince of Bel-Air", "Full House", "Saved by the Bell", "Boy Meets World", "Sabrina the Teenage Witch", "Family Matters",
"Sister, Sister", "Malcolm in the Middle", "My Wife and Kids", "Young Sheldon", "Happy Days", "The Wonder Years", "Step by Step", "Kenan & Kel", "Smart Guy", "Lizzie McGuire")
private val Orbit1Evening = listOf("Frasier", "Cheers", "Everybody Loves Raymond", "The King of Queens", "The Big Bang Theory",
"Modern Family", "Two and a Half Men", "Home Improvement", "The Golden Girls", "3rd Rock from the Sun", "Roseanne")
"Modern Family", "Two and a Half Men", "Home Improvement", "The Golden Girls", "3rd Rock from the Sun", "Roseanne", "Friends", "How I Met Your Mother")
private val Orbit1Late = listOf("Frasier", "Cheers", "Everybody Loves Raymond", "The King of Queens", "The Big Bang Theory", "The Golden Girls", "Happy Days")
private val Orbit1British = listOf("My Family", "Outnumbered", "Not Going Out", "Miranda",
"Last of the Summer Wine", "Bread", "Goodnight Sweetheart", "Mrs. Brown's Boys", "Red Dwarf", "The Royle Family", "My Hero", "dinnerladies")
@@ -43,3 +43,54 @@ internal val Orbit2DayParts get() = listOf(
DayPart(17, 19, Orbit2Spooky, days = setOf(DayOfWeek.FRIDAY)),
DayPart(6, 15, Orbit2Daytime), DayPart(15, 18, Orbit2Teatime), DayPart(18, 21, Orbit2GameShows), DayPart(21, 0, Orbit2Panel), DayPart(0, 6, Orbit2RetroAction))
internal val Orbit2Mixed get() = Orbit2Shows.toSet()
/** Orbit Three, the cult comedy channel: alternative British comedy in the spirit of early BBC Three, and Scottish comedy at its heart. */
private val ThreeScottish = listOf("Still Game", "Limmy's Show!", "Burnistoun", "Chewin' the Fat", "Rab C. Nesbitt", "Gary: Tank Commander", "Scot Squad")
private val ThreeDaytime = listOf("Two Pints of Lager and a Packet of Crisps", "The Inbetweeners", "Bad Education", "Uncle", "Him & Her",
"Coupling", "Cuckoo", "Lunch Monkeys", "Man Like Mobeen", "People Just Do Nothing", "Black Books") + ThreeScottish
private val ThreeEvening = listOf("Gavin & Stacey", "The Mighty Boosh", "Spaced", "Fresh Meat", "Phoenix Nights",
"Being Human", "Green Wing", "This Country", "Extras", "The Office (UK)", "Toast of London", "Peep Show", "The IT Crowd", "Family Guy")
private val ThreeLate = listOf("Little Britain", "The League of Gentlemen", "Nighty Night", "Snuff Box", "Monkey Dust", "Psychoville", "Inside No. 9",
"Garth Marenghi's Darkplace", "Brass Eye", "The Day Today", "Nathan Barley", "Bo' Selecta!", "Stressed Eric")
private val ThreeOvernight = listOf("Two Pints of Lager and a Packet of Crisps", "The Inbetweeners", "Gavin & Stacey", "The Mighty Boosh", "Still Game", "Limmy's Show!", "Burnistoun", "Black Books")
internal val ThreeShows get() = (ThreeDaytime + ThreeEvening + ThreeLate).distinct()
internal val ThreeDayParts get() = listOf(
DayPart(21, 0, ThreeScottish, days = setOf(DayOfWeek.FRIDAY, DayOfWeek.SATURDAY)),
DayPart(6, 18, ThreeDaytime), DayPart(18, 22, ThreeEvening), DayPart(22, 2, ThreeLate), DayPart(2, 6, ThreeOvernight))
/** Story sitcoms in order, sketch and standalone comedy mixed. */
private val ThreeInOrder = setOf("Gavin & Stacey", "Spaced", "Fresh Meat", "Phoenix Nights", "Being Human", "Green Wing", "This Country", "Extras", "The Office (UK)",
"Him & Her", "The Inbetweeners", "Peep Show", "Psychoville", "Nathan Barley")
internal val ThreeMixed get() = (ThreeShows.toSet() - ThreeInOrder)
/** Orbit Gold, Britain's comedy treasures: the 60s to 90s classics, as UK Gold was. */
private val GoldDaytime = listOf("Keeping Up Appearances", "Open All Hours", "Are You Being Served?", "'Allo 'Allo!", "Hi-de-Hi!",
"The Good Life (1975)", "Butterflies", "As Time Goes By", "Waiting for God", "Some Mothers Do 'Ave 'Em", "Never the Twain", "Brush Strokes", "Still Open All Hours")
private val GoldEvening = listOf("Only Fools and Horses", "Fawlty Towers", "Dad's Army", "Father Ted", "The Vicar of Dibley", "Blackadder", "Porridge",
"One Foot in the Grave", "Yes Minister", "Yes, Prime Minister", "To the Manor Born", "Ever Decreasing Circles", "Just Good Friends")
private val GoldLate = listOf("Men Behaving Badly", "Red Dwarf", "Birds Of A Feather", "Rising Damp", "Steptoe and Son", "The Likely Lads", "Citizen Smith",
"Gimme Gimme Gimme", "The Royle Family", "Taskmaster", "8 Out of 10 Cats", "Peep Show", "The IT Crowd", "The Green Green Grass", "Ghosts")
private val GoldOvernight = listOf("Only Fools and Horses", "Dad's Army", "Father Ted", "Blackadder", "Porridge", "Keeping Up Appearances", "'Allo 'Allo!", "Hi-de-Hi!")
private val GoldSaturday = listOf("The Two Ronnies", "Minder", "Lovejoy")
internal val GoldShows get() = (GoldDaytime + GoldEvening + GoldLate + GoldSaturday).distinct()
internal val GoldDayParts get() = listOf(
DayPart(18, 22, listOf("Only Fools and Horses"), days = setOf(DayOfWeek.SUNDAY)),
DayPart(17, 19, GoldSaturday, days = setOf(DayOfWeek.SATURDAY)),
DayPart(6, 17, GoldDaytime), DayPart(17, 22, GoldEvening), DayPart(22, 2, GoldLate), DayPart(2, 6, GoldOvernight))
/** Only Fools and Horses runs in order, so Sunday Gold tells its story. Blackadder too. */
internal val GoldMixed get() = GoldShows.toSet() - setOf("Only Fools and Horses", "Blackadder")
/** Riot, loud, rude and animated: adult animation getting louder through the night. */
private val RiotDaytime = listOf("The Simpsons", "Futurama", "King of the Hill", "Bob's Burgers", "American Dad!",
"Daria", "Clone High", "The Critic", "Mission Hill", "Duckman", "The Cleveland Show", "Solar Opposites")
private val RiotLaughs = listOf("It's Always Sunny in Philadelphia", "Curb Your Enthusiasm", "Seinfeld", "Scrubs",
"Arrested Development", "Parks and Recreation", "The Office", "Friends", "How I Met Your Mother", "Trailer Park Boys", "Reno 911!", "Workaholics")
private val RiotAfterHours = listOf("South Park", "Family Guy", "Rick and Morty", "Beavis and Butt-Head", "BoJack Horseman",
"Archer (2009)", "Robot Chicken", "The Boondocks", "Big Mouth", "Celebrity Deathmatch", "Drawn Together", "Metalocalypse", "The Venture Bros.")
private val RiotGraveyard = listOf("Aqua Teen Hunger Force", "Sealab 2021", "Harvey Birdman, Attorney at Law", "Squidbillies", "Moral Orel", "Superjail!",
"Tim and Eric Awesome Show, Great Job!", "Dr. Katz, Professional Therapist", "The Ren & Stimpy Show")
private val RiotStunts = listOf("Jackass", "Dirty Sanchez", "Bo' Selecta!")
internal val RiotShows get() = (RiotDaytime + RiotLaughs + RiotAfterHours + RiotGraveyard + RiotStunts).distinct()
internal val RiotDayParts get() = listOf(
DayPart(22, 0, RiotStunts, days = setOf(DayOfWeek.SATURDAY)),
DayPart(6, 18, RiotDaytime), DayPart(18, 21, RiotLaughs), DayPart(21, 2, RiotAfterHours), DayPart(2, 6, RiotGraveyard))
internal val RiotMixed get() = RiotShows.toSet() - setOf("Arrested Development", "BoJack Horseman")
@@ -28,13 +28,9 @@ internal val ChannelPresets = listOf(
ChannelPreset(101, "Orbit 1", Orbit1Shows, smartOnly = true),
ChannelPreset(201, "Terra", listOf("Blue Planet", "Planet Earth", "Frozen Planet", "Life", "Our Planet")),
ChannelPreset(106, "Paradox", listOf("The X-Files", "Buffy the Vampire Slayer", "Supernatural", "Fringe", "Doctor Who (2005)")),
ChannelPreset(104, "Orbit Gold", listOf("Only Fools and Horses", "Father Ted", "Blackadder", "The Black Adder", "Fawlty Towers", "Ghosts", "The Good Life", "The Green Green Grass",
"The Vicar of Dibley", "Porridge", "Taskmaster", "8 Out of 10 Cats", "Dad's Army", "Yes Minister", "Keeping Up Appearances", "Open All Hours", "Rising Damp", "The Likely Lads", "Steptoe and Son", "Hi-de-Hi!", "'Allo 'Allo!",
"Are You Being Served?", "Birds of a Feather", "Men Behaving Badly", "The IT Crowd", "Peep Show"), smartOnly = true),
ChannelPreset(103, "Orbit Three", listOf("Still Game", "Limmy's Show", "The Mighty Boosh", "Two Pints of Lager and a Packet of Crisps", "Gary: Tank Commander", "Family Guy", "Gavin & Stacey", "Little Britain",
"The Inbetweeners", "Bad Education", "Burnistoun", "Rab C. Nesbitt", "Chewin' the Fat", "Phoenix Nights", "Him & Her", "Spaced", "Black Books", "Fresh Meat", "Uncle", "Scot Squad"), smartOnly = true),
ChannelPreset(105, "Riot", listOf("South Park", "The Simpsons", "It's Always Sunny in Philadelphia", "Trailer Park Boys", "Friends", "How I Met Your Mother", "Futurama", "American Dad!", "Bob's Burgers",
"King of the Hill", "Rick and Morty", "Beavis and Butt-Head", "Archer", "BoJack Horseman", "Seinfeld", "Scrubs", "The Office", "Arrested Development", "Parks and Recreation", "Curb Your Enthusiasm"), smartOnly = true),
ChannelPreset(104, "Orbit Gold", GoldShows, smartOnly = true),
ChannelPreset(103, "Orbit Three", ThreeShows, smartOnly = true),
ChannelPreset(105, "Riot", RiotShows, smartOnly = true),
ChannelPreset(602, "Heroes", listOf("Batman: The Animated Series", "Superman: The Animated Series", "Spider-Man: The Animated Series", "X-Men: The Animated Series", "Batman Beyond",
"Spider-Man Unlimited", "Justice League", "Justice League Unlimited", "Teen Titans", "Static Shock", "The Spectacular Spider-Man", "Young Justice",
"Batman: The Brave and the Bold", "Iron Man: Armored Adventures", "The Avengers: Earth's Mightiest Heroes", "The Batman", "Fantastic Four", "Silver Surfer",
@@ -78,10 +78,10 @@ internal val SmartChannels = listOf(
suggestionRules = SmartChannelRules[it.number].orEmpty(), dayParts = SmartChannelParts[it.number].orEmpty(), shuffleTitles = SmartChannelMixed[it.number].orEmpty()) }
/** Shows that play in a mixed order on channels whose identity is agreed. See ChannelIdentities.kt. */
private val SmartChannelMixed: Map<Int, Set<String>> get() = mapOf(101 to Orbit1Mixed, 102 to Orbit2Mixed)
private val SmartChannelMixed: Map<Int, Set<String>> get() = mapOf(101 to Orbit1Mixed, 102 to Orbit2Mixed, 103 to ThreeMixed, 104 to GoldMixed, 105 to RiotMixed)
/** Dark Files, from the programming bible: crime by day, mysteries early evening, the paranormal late. */
private val SmartChannelParts: Map<Int, List<DayPart>> get() = mapOf(101 to Orbit1DayParts, 102 to Orbit2DayParts, 204 to listOf(
private val SmartChannelParts: Map<Int, List<DayPart>> get() = mapOf(101 to Orbit1DayParts, 102 to Orbit2DayParts, 103 to ThreeDayParts, 104 to GoldDayParts, 105 to RiotDayParts, 204 to listOf(
DayPart(6, 18, DarkFilesCrime, group = "day"), DayPart(18, 21, DarkFilesMysteries, group = "evening"), DayPart(21, 6, DarkFilesParanormal, group = "late")),
// Ring X, from the bible: each weeknight's own show, and the whole vault the rest of the week.
401 to listOf(DayPart(0, 24, RingXMondayNight, days = setOf(java.time.DayOfWeek.MONDAY)), DayPart(0, 24, RingXImpact, days = setOf(java.time.DayOfWeek.TUESDAY)),
@@ -118,7 +118,9 @@ internal data class PoolSeries(val id: String, val title: String, val episodes:
/** Where a channel has got to: the last episode of each show, and whose turn was last. */
internal data class ScheduleCursor(val lastSeriesId: String? = null, val marks: Map<String, EpisodeMark> = emptyMap(),
/** When each film last started, for its rest period. */
val filmShown: Map<String, Long> = emptyMap())
val filmShown: Map<String, Long> = emptyMap(),
/** The last show to air in each block, so a block picks up its rotation where it left off rather than starting again each day. */
val blockLast: Map<String, String> = emptyMap())
internal data class ScheduleEntry(val seriesId: String, val mark: EpisodeMark, val media: ScheduledMedia, val startMs: Long,
/** Why the planner chose this, for diagnostics only. Empty for programmes planned before reasons were kept. */
@@ -248,7 +250,9 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
/** How many times the cursor's last show had already played in a row, so a run carries across a top-up. */
runBefore: Int = 0,
/** Off only in tests, to show that this rule is the one difference from planning before it existed. */
noThirdInARow: Boolean = true): ChannelPlan {
noThirdInARow: Boolean = true,
/** Off only in tests: each block keeps its own place in the rotation. */
blockRotation: Boolean = true): ChannelPlan {
require(pool.isNotEmpty() && pool.all { it.episodes.isNotEmpty() })
if (filmRestMs != null) return extendFilmSchedule(pool, cursor, fromMs, untilMs, filmRestMs, dayParts, zone, avoid)
val marks = cursor.marks.toMutableMap()
@@ -258,6 +262,7 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
val mixes = HashMap<String, List<PoolEpisode>>()
// How many times in a row the last show has played, counted from the start of this extension.
var run = if (cursor.lastSeriesId != null) runBefore else 0
val blockLast = cursor.blockLast.toMutableMap()
fun isMixed(show: PoolSeries) = shuffle || mixed(show)
fun running(show: PoolSeries) = if (isMixed(show)) mixes.getOrPut(show.id) { shuffledEpisodes(show) } else show.episodes
fun following(show: PoolSeries): PoolEpisode {
@@ -273,16 +278,18 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
val allowed = { show: PoolSeries -> show in available && (!finishTogether || marks[show.id] != running(show).last().mark) }
// Skips a show already on elsewhere, unless that would leave nothing to show.
val waiting = mutableListOf<String>(); val elsewhere = mutableListOf<String>()
val picked = turnOrder(pool, last).firstOrNull { show ->
// A block carries on from its own last show. Starting from the channel's last show would begin each block at the same place every day.
val after = if (blockRotation) blockLast[block] ?: last else last
val picked = turnOrder(pool, after).firstOrNull { show ->
when {
!allowed(show) -> { if (show in available) waiting += show.title; false }
avoid(show, start, start + following(show).durationMs) -> { elsewhere += show.title; false }
else -> true
}
}
val chosen = picked ?: nextInTurn(pool, last, allowed)
val chosen = picked ?: nextInTurn(pool, after, allowed)
// Never a third in a row while another show in the block is only waiting for the round to finish. That one starts its next round early.
val early = if (!noThirdInARow || !finishTogether || chosen.id != last || run < 2) null else turnOrder(pool, last).firstOrNull { show ->
val early = if (!noThirdInARow || !finishTogether || chosen.id != last || run < 2) null else turnOrder(pool, after).firstOrNull { show ->
show.id != chosen.id && show in available && marks[show.id] == running(show).last().mark && !avoid(show, start, start + running(show).first().durationMs)
}
if (early != null) marks.remove(early.id)
@@ -306,9 +313,10 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
marks[series.id] = episode.mark
run = if (series.id == last) run + 1 else 1
last = series.id
blockLast[block] = series.id
start += episode.durationMs
}
return ChannelPlan(entries, ScheduleCursor(last, marks))
return ChannelPlan(entries, ScheduleCursor(last, marks, blockLast = blockLast))
}
internal fun scheduledItem(seriesTitle: String, episode: PoolEpisode) = SampleItem(
@@ -324,7 +332,7 @@ internal fun airedCursor(base: ScheduleCursor, entries: List<ScheduleEntry>, now
marks[it.seriesId] = it.mark; last = it.seriesId
if (it.media.item.type == "Movie") shown[it.seriesId] = it.startMs
}
return ScheduleCursor(last, marks, shown)
return ScheduleCursor(last, marks, shown, base.blockLast)
}
/**
@@ -333,13 +341,13 @@ internal fun airedCursor(base: ScheduleCursor, entries: List<ScheduleEntry>, now
*/
internal fun topUpPlan(existing: ChannelPlan?, aired: ScheduleCursor, pool: List<PoolSeries>?, nowMs: Long, filmRestMs: Long? = null, finishTogether: Boolean = false,
dayParts: List<DayPart> = emptyList(), zone: java.time.ZoneId = java.time.ZoneId.systemDefault(), avoid: ProgrammeClash = { _, _, _ -> false }, shuffle: Boolean = false, noThirdInARow: Boolean = true,
mixed: (PoolSeries) -> Boolean = { false }): ChannelPlan? {
mixed: (PoolSeries) -> Boolean = { false }, blockRotation: Boolean = true): ChannelPlan? {
val kept = existing?.let { plan -> plan.copy(entries = plan.entries.dropWhile { it.endMs < nowMs - SCHEDULE_KEEP_PAST_MS }) }
if (kept != null && kept.endMs >= nowMs + SCHEDULE_TOP_UP_MS) return kept
if (pool.isNullOrEmpty()) return kept
val from = if (kept != null && kept.endMs > nowMs) kept.endMs else nowMs
val trailing = kept?.entries?.lastOrNull()?.let { tail -> kept.entries.asReversed().takeWhile { it.seriesId == tail.seriesId }.size } ?: 0
val added = extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing, noThirdInARow)
val added = extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing, noThirdInARow, blockRotation)
return ChannelPlan(kept?.entries.orEmpty() + added.entries, added.tail)
}
@@ -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.86.0\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.87.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -76,12 +76,15 @@ internal class ScheduleStore(private val directory: File) {
private fun encodeCursor(cursor: ScheduleCursor) = JSONObject().put("last", cursor.lastSeriesId ?: JSONObject.NULL)
.put("marks", JSONObject().also { marks -> cursor.marks.forEach { (id, mark) -> marks.put(id, JSONArray().put(mark.season).put(mark.episode)) } })
.put("shown", JSONObject().also { shown -> cursor.filmShown.forEach { (id, at) -> shown.put(id, at) } })
.also { o -> if (cursor.blockLast.isNotEmpty()) o.put("blocks", JSONObject().also { blocks -> cursor.blockLast.forEach { (block, id) -> blocks.put(block, id) } }) }
private fun decodeCursor(o: JSONObject): ScheduleCursor {
val marks = o.getJSONObject("marks")
return ScheduleCursor(if (o.isNull("last")) null else validId(o.getString("last")),
marks.keys().asSequence().associate { id -> validId(id) to marks.getJSONArray(id).let { EpisodeMark(it.getInt(0), it.getInt(1)) } },
// Absent in files saved before film channels existed.
o.optJSONObject("shown")?.let { shown -> shown.keys().asSequence().associate { id -> validId(id) to shown.getLong(id) } }.orEmpty())
o.optJSONObject("shown")?.let { shown -> shown.keys().asSequence().associate { id -> validId(id) to shown.getLong(id) } }.orEmpty(),
// Absent in files saved before blocks kept their own place.
o.optJSONObject("blocks")?.let { blocks -> blocks.keys().asSequence().associate { block -> block.take(80) to validId(blocks.getString(block)) } }.orEmpty())
}
private fun validId(id: String) = id.also { require(EmbyClient.validId(it)) }
/** Reasons are diagnostics. A long one is cut rather than refused, so it can never cost a plan. */
@@ -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.86.0")
next.setRequestProperty("User-Agent", "OrbitTV/0.87.0")
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()) {