0.94.0: PPV Sunday on Ring X (opt-in event films, one a night, near 19:00)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m47s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m27s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-03 15:56:35 +00:00
co-authored by Claude Opus 5.5
parent c9928482cb
commit 6f3f1e5c19
11 changed files with 375 additions and 174 deletions
@@ -334,5 +334,21 @@ internal val RingXDayParts get() = listOf(
DayPart(18, 23, RingXMonday, days = setOf(DayOfWeek.MONDAY)), DayPart(18, 23, RingXTuesday, days = setOf(DayOfWeek.TUESDAY)),
DayPart(18, 23, RingXWednesday, days = setOf(DayOfWeek.WEDNESDAY)), DayPart(18, 23, RingXThursday, days = setOf(DayOfWeek.THURSDAY)),
DayPart(18, 23, RingXFriday, days = setOf(DayOfWeek.FRIDAY)), DayPart(18, 23, RingXSaturday, days = setOf(DayOfWeek.SATURDAY)),
// Sunday evening is the vault until PPV Sunday is built.
// PPV Sunday: one event, starting near 19:00 and running to its natural end, however late.
DayPart(19, 20, PpvSunday, days = setOf(DayOfWeek.SUNDAY), onTime = true, once = true),
DayPart(6, 23, RingXDaytimeVault), DayPart(23, 6, RingXLate))
/**
* PPV Sunday: 52 events from the library, a year without a repeat, in this order. Promotions and eras are spaced through the year;
* the order is programming, not history. Named with their year where the library has another event of that name.
*/
internal val PpvSunday = listOf("WWE WrestleMania III", "WCW Capital Combat: The Return of RoboCop", "ECW Hardcore Heaven 1996", "AEW Double or Nothing 2019", "WWE WrestleMania 39 Sunday",
"NWA Starrcade 1983", "WWE Survivor Series 1987", "NJPW Wrestle Kingdom 11", "TNA Unbreakable 2005", "WCW Fall Brawl 1997", "WWE Royal Rumble 2022",
"ECW One Night Stand 2005", "AEW: All In 2023", "ROH: Supercard of Honor XII", "WWE SummerSlam 1988", "WCW SuperBrawl II", "WWE Evolution (2018)",
"ECW Barely Legal 1997", "WWE WrestleMania VI", "NWA WrestleWar '89: The Music City Showdown", "WCW World War 3 1996", "AEW All Out (2019)",
"WWE WrestleMania XXX", "ECW Anarchy Rulz 2000", "WWE Royal Rumble 1992", "NJPW Wrestle Kingdom 13", "Impact Wrestling: Slammiversary 2022", "WCW Beach Blast",
"WWE SummerSlam 2013", "AEW x NJPW Presents Forbidden Door", "WWE SummerSlam 1992", "WCW Hog Wild 1996", "NWA Starrcade '86: The Night of The Sky-Walkers",
"WWE WrestleMania XX", "ECW Heat Wave 1998", "WWE WrestleMania X", "WCW Starrcade 1993", "AEW Revolution 2021", "ROH: Final Battle (2021)",
"WWE WrestleMania X-Seven", "ECW Guilty as Charged 1999", "WWE In Your House 16: Canadian Stampede", "NJPW Dominion 6.9 in Osaka-jo Hall",
"IMPACT Wrestling: Bound for Glory 2019", "WCW Bash at the Beach 1996", "WWE WrestleMania XV", "NWA Chi-Town Rumble", "AEW Full Gear (2021)",
"WWE Survivor Series 1997", "ECW November To Remember 1998", "WCW Spring Stampede 1994", "WWE King of the Ring 1998")
@@ -3,7 +3,11 @@ package tv.orbit.classic
/** Local hours, wrapping past midnight, and the titles a channel may use then. No titles means everything in its pool. */
internal data class DayPart(val fromHour: Int, val toHour: Int, val titles: List<String> = emptyList(), val group: String = "",
/** Set for an event: only these days, starting from its [fromHour] on each. List it before the everyday blocks. */
val days: Set<java.time.DayOfWeek> = emptySet()) {
val days: Set<java.time.DayOfWeek> = emptySet(),
/** An appointment: the programmes before it are chosen, where one fits, to finish by its hour, so it starts on time. */
val onTime: Boolean = false,
/** One start a night: once a programme from this event has started, the rest of its window goes to the usual block. */
val once: Boolean = false) {
fun covers(hour: Int) = if (fromHour <= toHour) hour in fromHour until toHour else hour >= fromHour || hour < toHour
/** An event that runs past midnight belongs to the night it started, so its small hours count from the day before. */
fun covers(hour: Int, day: java.time.DayOfWeek) = covers(hour) && (days.isEmpty() || (if (fromHour > toHour && hour < toHour) day.minus(1) else day) in days)
@@ -25,12 +29,14 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
val shuffleEpisodes: Boolean = false,
/** Shows played in a mixed order on a channel that otherwise runs in season order, such as Paradox's standalone adventures. */
val shuffleTitles: Set<String> = emptySet(),
/** Films a series channel may carry, each only in an event that names it. Empty everywhere but Ring X. */
val channelFilms: List<String> = emptyList(),
/** Series a film channel may carry, each only in an event that names it, one whole episode a night in order. Empty everywhere but After Dark. */
val filmSeries: List<String> = emptyList()) {
/** Whether a show plays its episodes in a mixed order here. */
fun mixes(show: PoolSeries) = shuffleEpisodes || seriesKey(show.title) in shuffleTitles.mapTo(HashSet(), ::seriesKey)
/** Changes when the list does, so the episode cache is read again. What's already committed stays. */
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount" + if (filmSeries.isEmpty()) "" else "#series:${filmSeries.joinToString("|")}"
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount" + if (filmSeries.isEmpty()) "" else "#series:${filmSeries.joinToString("|")}" + if (channelFilms.isEmpty()) "" else "#films:${channelFilms.joinToString("|")}"
}
/** Expect the unexpected: standalone adventures by day in a mixed order, cult drama in order in prime time, and the strange stuff late. */
@@ -79,7 +85,8 @@ internal val SmartChannels = listOf(
ChannelProgramming(106, "Paradox", ParadoxShows, seriesCount = 20, finishTogether = true, exactTitles = true, dayParts = ParadoxDayParts, shuffleTitles = ParadoxStandalones.toSet())) +
ChannelPresets.filter { it.smartOnly }.map { ChannelProgramming(it.number, it.name, it.searches, seriesCount = if (it.films) it.searches.size else 60, 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 = SmartChannelParts[it.number].orEmpty(), shuffleTitles = SmartChannelMixed[it.number].orEmpty(),
channelFilms = if (it.number == 401) PpvSunday else emptyList()) }
/** 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, 103 to ThreeMixed, 104 to GoldMixed, 105 to RiotMixed,
@@ -159,20 +166,24 @@ internal fun dayPartPool(pool: List<PoolSeries>, parts: List<DayPart>, startMs:
dayPartChoice(pool, parts, startMs, zone).first
/** [dayPartPool], with a short name for the block it came from, for the reasons kept with each programme. */
internal fun dayPartChoice(pool: List<PoolSeries>, parts: List<DayPart>, startMs: Long, zone: java.time.ZoneId): Pair<List<PoolSeries>, String> {
internal fun dayPartChoice(pool: List<PoolSeries>, parts: List<DayPart>, startMs: Long, zone: java.time.ZoneId): Pair<List<PoolSeries>, String> =
dayPartFor(pool, parts, startMs, zone).let { it.first to it.second }
/** [dayPartChoice], with the part it came from, or null for the whole pool. */
internal fun dayPartFor(pool: List<PoolSeries>, parts: List<DayPart>, startMs: Long, zone: java.time.ZoneId): Triple<List<PoolSeries>, String, DayPart?> {
val local = java.time.Instant.ofEpochMilli(startMs).atZone(zone)
// An event with nothing to show gives way to the ordinary block for that time.
for (part in parts.filter { it.covers(local.hour, local.dayOfWeek) }) {
val name = (if (part.days.isNotEmpty()) "event " else "block ") + part.group.ifEmpty { "${part.fromHour}-${part.toHour}" }
if (part.titles.isEmpty() && part.group.isEmpty()) return pool to name
if (part.titles.isEmpty() && part.group.isEmpty()) return Triple(pool, name, part)
val titles = part.titles.map(::seriesKey).toSet()
// A film is named with its year, as "Halloween (1978)"; the pool already holds that exact film under its plain title.
val films = part.titles.map { seriesKey(FilmIdentity.of(it).title) }.toSet()
val allowed = pool.filter { seriesKey(it.title) in titles || (it.isFilm && seriesKey(it.title) in films) || (part.group.isNotEmpty() && it.group == part.group) }
if (allowed.isNotEmpty()) return allowed to name
if (allowed.isNotEmpty()) return Triple(allowed, name, part)
}
// A film saved for an event doesn't appear in everyday programming.
return pool.filter { !it.isFilm || pool.all(PoolSeries::isFilm) }.ifEmpty { pool } to (if (parts.isEmpty()) "whole pool" else "no block, whole pool")
return Triple(pool.filter { !it.isFilm || pool.all(PoolSeries::isFilm) }.ifEmpty { pool }, if (parts.isEmpty()) "whole pool" else "no block, whole pool", null)
}
/** A few names and how many more, so a reason stays short. */
@@ -262,6 +273,16 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
return ChannelPlan(entries, ScheduleCursor(last, marks, shown))
}
/** A one-a-night event counts as having had its turn for this long after a programme from it starts. */
private const val ONCE_A_NIGHT_MS = 12 * 60 * 60_000L
/** How far ahead an on-time appointment is looked for, and how late after its hour it may start. */
private const val ON_TIME_LOOKAHEAD_HOURS = 4
private const val ON_TIME_GRACE_MS = 20 * 60_000L
/** An appointment's window is its first hour; a programme must end inside it for the appointment to happen at all. */
private const val ON_TIME_LAST_CALL_MS = 60 * 60_000L
/** How long before an appointment the programmes leading into it may be adjusted. */
private const val ON_TIME_RUN_IN_MS = 90 * 60_000L
/** A series on a film channel airs at most once in this long, so a long event window still holds one episode. */
private const val SERIES_NIGHT_MS = 12 * 60 * 60_000L
@@ -286,6 +307,25 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
// 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()
// When each film last started, kept so a one-a-night event can tell it has had its turn.
val shown = cursor.filmShown.toMutableMap()
fun hadItsTurn(available: List<PoolSeries>, at: Long) = available.any { film -> film.isFilm && shown[film.id]?.let { at - it < ONCE_A_NIGHT_MS } == true }
/** The part for [at], passing over a one-a-night event that has already started a programme tonight. */
fun partAt(at: Long): Triple<List<PoolSeries>, String, DayPart?> {
val first = dayPartFor(pool, dayParts, at, zone)
val part = first.third ?: return first
return if (part.once && hadItsTurn(first.first, at)) dayPartFor(pool, dayParts - part, at, zone) else first
}
/** The next on-time appointment within a few hours, if there is one and it hasn't had its turn tonight. */
fun appointmentAfter(at: Long): Long? {
val hour = 60 * 60_000L
val local = java.time.Instant.ofEpochMilli(at).atZone(zone)
val nextHour = local.truncatedTo(java.time.temporal.ChronoUnit.HOURS).plusHours(1).toInstant().toEpochMilli()
return (0 until ON_TIME_LOOKAHEAD_HOURS).map { nextHour + it * hour }.firstOrNull { boundary ->
val (films, _, part) = partAt(boundary)
part?.onTime == true && films.isNotEmpty()
}
}
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 {
@@ -294,7 +334,7 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
return mix[(mix.indexOfFirst { it.mark == marks[show.id] } + 1) % mix.size]
}
while (start < untilMs) {
val (available, block) = dayPartChoice(pool, dayParts, start, zone)
val (available, block, part) = partAt(start)
// Shows only wait for others in the same block, or a daytime show could stand idle for an evening one.
val restarted = finishTogether && available.all { marks[it.id] == running(it).last().mark }
if (restarted) available.forEach { marks.remove(it.id) }
@@ -310,7 +350,27 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
else -> true
}
}
val chosen = picked ?: nextInTurn(pool, after, allowed)
var chosen = picked ?: nextInTurn(pool, after, allowed)
// Before an appointment, a show in turn that finishes in time goes first, so the appointment starts near its hour. Nothing is cut.
val appointment = if (part?.onTime == true) null else appointmentAfter(start)
var fitted = false
val latest = (appointment ?: 0L) + ON_TIME_GRACE_MS
fun ends(show: PoolSeries) = start + following(show).durationMs
val candidates = if (appointment == null) emptyList() else turnOrder(pool, after).filter { show -> allowed(show) && !avoid(show, start, ends(show)) }
/** Whether [show] leaves the appointment on time: ending in its first minutes, or leaving a gap another show closes. */
fun onTimeAfter(show: PoolSeries) = ends(show) in appointment!!..latest ||
(ends(show) < appointment && candidates.any { other -> other.id != show.id && ends(show) + following(other).durationMs in appointment..latest })
// Only the last stretch before the appointment is adjusted; earlier programmes keep their ordinary turns.
if (appointment != null && ends(chosen) > appointment - ON_TIME_RUN_IN_MS && !onTimeAfter(chosen)) {
val fits = candidates.filter { ends(it) <= latest }
// Best is a show ending right at the appointment; next, one that leaves a gap another show can close; then anything that fits.
val choice = fits.firstOrNull { ends(it) >= appointment }
?: fits.firstOrNull { onTimeAfter(it) }
?: fits.firstOrNull().takeIf { ends(chosen) > latest }
// Failing that, at least something that ends while the appointment's window is still open, so it isn't missed.
?: candidates.firstOrNull { ends(it) < appointment + ON_TIME_LAST_CALL_MS }.takeIf { ends(chosen) >= appointment + ON_TIME_LAST_CALL_MS }
if (choice != null) { chosen = choice; fitted = true }
}
// 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, 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)
@@ -326,6 +386,7 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
else -> "; fallback: every show in turn airs elsewhere then"
})
if (isMixed(series)) append(", episode from its shuffled order")
if (fitted) append("; chosen to finish before the appointment at ${java.time.Instant.ofEpochMilli(appointment!!).atZone(zone).toLocalTime()}")
if (restarted) append("; every show had finished, so all started again")
if (waiting.isNotEmpty()) append("; deferred until the rest finish: ${someOf(waiting)}")
if (elsewhere.isNotEmpty()) append("; deferred, airing elsewhere: ${someOf(elsewhere)}")
@@ -337,9 +398,10 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
run = if (series.id == last) run + 1 else 1
last = series.id
blockLast[block] = series.id
if (series.isFilm) shown[series.id] = start
start += episode.durationMs
}
return ChannelPlan(entries, ScheduleCursor(last, marks, blockLast = blockLast))
return ChannelPlan(entries, ScheduleCursor(last, marks, shown, blockLast))
}
internal fun scheduledItem(seriesTitle: String, episode: PoolEpisode) = SampleItem(
@@ -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.93.0\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.94.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -257,6 +257,15 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
if (copies.size > 1) android.util.Log.i("OrbitSchedule", "channel=${programming.number} copies=${copies.size} usedCopy=${read.indexOf(best) + 1} episodes=${read.map { it.episodes.size }}")
pool += best
}
// Films this series channel carries in an event, found exactly as a film channel finds them. Nothing stands in for one that isn't there.
if (programming.filmRestMs == null) for (entry in programming.channelFilms) {
checkActive()
requests++
val lookup = findFilm(transport, userId, ::currentToken, entry, BoxDecoders::canDecode)
if (lookup.note.isNotEmpty()) android.util.Log.i("OrbitSchedule", "channel=${programming.number} ${lookup.note}")
val film = lookup.film ?: continue
if (pool.none { it.id == film.id }) pool += film
}
for (accepted in choices.accepted) {
checkActive()
if (pool.any { it.id == accepted.id || seriesKey(it.title) == seriesKey(accepted.title) }) continue
@@ -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.93.0")
next.setRequestProperty("User-Agent", "OrbitTV/0.94.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()) {