0.98.0: weighted rotation on Odyssey, Wild, Orbit X, ToonZ and Tots Morning and Playtime
Per-block switch keeps Tots' Wind Down and Night on equal turns; per-block weights put ToonZ's teatime trio level with the core in teatime only. Tiers from each channel's brief. Four-week real-pool replays with clash avoidance and restarts, and fingerprints against 0.97.0, in docs/replays. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -171,6 +171,8 @@ internal val OrbitXDayParts get() = listOf(
|
||||
internal val OrbitXMixed get() = setOf("Biker Mice from Mars", "Teenage Mutant Ninja Turtles", "The Transformers", "He-Man and the Masters of the Universe", "ThunderCats",
|
||||
"The Real Ghostbusters", "G.I. Joe", "G.I. Joe: A Real American Hero", "Street Sharks", "SWAT Kats: The Radical Squadron", "Captain Planet and the Planeteers", "M.A.S.K.",
|
||||
"Inspector Gadget", "She-Ra: Princess of Power")
|
||||
/** Orbit X's tiers, from docs/channels/orbit-x.md: the core and its earlier names 3, everything else 2. */
|
||||
internal val OrbitXTiers: Map<String, Double> get() = (OrbitXCore + OrbitXEarlierNames).associate { seriesKey(it) to TIER_CORE }
|
||||
|
||||
/** Rewind, the after-school 2000s: Cartoon Network at its heart, with Nickelodeon, Kids' WB and a little Disney. */
|
||||
private val RewindCore = listOf("Dexter's Laboratory", "Johnny Bravo", "The Powerpuff Girls", "Cow and Chicken", "I Am Weasel", "Ed, Edd n Eddy", "Ed Edd n Eddy",
|
||||
@@ -193,9 +195,13 @@ private val ToonZSupporting = listOf("Wacky Races", "Top Cat", "Hong Kong Phooey
|
||||
private val ToonZTeatime = listOf("Danger Mouse", "Count Duckula", "Bananaman")
|
||||
internal val ToonZShows get() = (ToonZCore + ToonZSupporting + ToonZTeatime).distinct()
|
||||
internal val ToonZDayParts get() = listOf(
|
||||
DayPart(6, 10, ToonZCore + ToonZSupporting), DayPart(10, 16, ToonZCore + ToonZSupporting), DayPart(16, 18, ToonZTeatime + ToonZCore),
|
||||
DayPart(6, 10, ToonZCore + ToonZSupporting), DayPart(10, 16, ToonZCore + ToonZSupporting),
|
||||
// Teatime is the British trio's block, so there they're level with the core (approved 4 November 2026).
|
||||
DayPart(16, 18, ToonZTeatime + ToonZCore, weights = ToonZTeatime.associate { seriesKey(it) to TIER_CORE }),
|
||||
DayPart(18, 0, ToonZCore + ToonZSupporting), DayPart(0, 6, ToonZShows))
|
||||
internal val ToonZMixed get() = ToonZShows.toSet()
|
||||
/** ToonZ's tiers, from docs/channels/toonz.md: the core 3, everything else 2. The teatime trio's own block weights them 3 there. */
|
||||
internal val ToonZTiers: Map<String, Double> get() = ToonZCore.associate { seriesKey(it) to TIER_CORE }
|
||||
|
||||
/** Terra, after Eden: natural history watched and understood. The animals and places are the story. */
|
||||
private val TerraLandmarks = listOf("Life on Earth", "The Living Planet", "The Trials of Life", "The Blue Planet", "Blue Planet II", "Planet Earth", "Planet Earth II", "Planet Earth III",
|
||||
@@ -224,6 +230,9 @@ internal val WildDayParts get() = listOf(
|
||||
// Late is where the dangerous jobs live.
|
||||
DayPart(22, 6, WildFrontier))
|
||||
internal val WildMixed get() = WildShows.toSet() - setOf("Alone", "Expedition Tiger", "Running Wild with Bear Grylls: The Challenge")
|
||||
/** Wild's tiers, from docs/channels/wild.md: core 3, supporting 2, Dirty Jobs the surprise at 1. */
|
||||
internal val WildTiers: Map<String, Double> get() =
|
||||
(WildSurvival + listOf("The Crocodile Hunter", "River Monsters")).associate { seriesKey(it) to TIER_CORE } + mapOf(seriesKey("Dirty Jobs") to TIER_SURPRISE)
|
||||
|
||||
/** Odyssey, after Discovery Science: space, science and engineering, with a weekend of human journeys. */
|
||||
private val OdysseySpace = listOf("Cosmos", "Cosmos: A Spacetime Odyssey", "Wonders of the Universe", "Wonders of the Solar System", "The Universe", "How the Universe Works",
|
||||
@@ -246,6 +255,10 @@ internal val OdysseyDayParts get() = listOf(
|
||||
DayPart(6, 18, OdysseyEngineering + OdysseySpace - setOf("Horizon", "Through the Wormhole", "The Sky at Night"), group = "all"), DayPart(18, 23, OdysseySpace), DayPart(23, 6, OdysseyDisasters))
|
||||
internal val OdysseyMixed get() = setOf("The Universe", "How the Universe Works", "Horizon", "Impossible Engineering", "Engineering the Impossible", "Extreme Engineering", "Megastructures",
|
||||
"Big Bigger Biggest", "How Do They Do It?", "Seconds from Disaster", "Air Crash Investigation", "Mayday", "Through the Wormhole", "The Sky at Night", "Parts Unknown")
|
||||
/** Odyssey's tiers, from docs/channels/odyssey.md: core 3, everything else 2, so Journeys are equal within their weekend block. */
|
||||
internal val OdysseyTiers: Map<String, Double> get() = listOf("The Universe", "How the Universe Works", "Cosmos", "Cosmos: A Spacetime Odyssey", "Wonders of the Universe",
|
||||
"Wonders of the Solar System", "Horizon", "Through the Wormhole", "The Sky at Night", "The Planets (2019)", "Wonders of Life", "Human Universe", "Forces of Nature with Brian Cox",
|
||||
"Brian Cox's Adventures in Space and Time", "When We Left Earth: The NASA Missions", "Impossible Engineering", "Extreme Engineering", "Megastructures").associate { seriesKey(it) to TIER_CORE }
|
||||
|
||||
/** Dark Files: real crime by day, mysteries in the evening, the paranormal at night, and long-form case files at weekends. */
|
||||
private val DarkFilesCaseFiles = listOf("Making a Murderer", "The Staircase", "The Jinx", "The Keepers", "Wild Wild Country", "Conversations with a Killer: The Ted Bundy Tapes",
|
||||
|
||||
@@ -9,7 +9,11 @@ internal data class DayPart(val fromHour: Int, val toHour: Int, val titles: List
|
||||
/** 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,
|
||||
/** The block's or event's presentation, such as "riot.laughs": its own ident on entering it. Empty for ordinary blocks. */
|
||||
val key: String = "") {
|
||||
val key: String = "",
|
||||
/** On a channel with weighted rotation: false keeps this block on equal turns, as Tots' Wind Down and Night (4 November 2026). */
|
||||
val weighted: Boolean = true,
|
||||
/** On a channel with weighted rotation: tier weights for this block only, over the channel's, as ToonZ's teatime trio. */
|
||||
val weights: Map<String, Double> = emptyMap()) {
|
||||
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)
|
||||
@@ -91,15 +95,16 @@ internal val SmartChannels = listOf(
|
||||
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),
|
||||
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = TotsDayParts, shuffleEpisodes = true),
|
||||
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = TotsDayParts, shuffleEpisodes = true,
|
||||
tierWeights = TotsTiers),
|
||||
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(),
|
||||
channelFilms = if (it.number == 401) PpvSunday else emptyList(), tierWeights = SmartChannelTiers[it.number]) }
|
||||
|
||||
/** Editorially weighted rotation, per channel, once its tiers are approved. Orbit Three only for now (4 November 2026). */
|
||||
private val SmartChannelTiers: Map<Int, Map<String, Double>> get() = mapOf(103 to ThreeTiers)
|
||||
/** Editorially weighted rotation, per channel, once its tiers are approved: Orbit Three (0.97.0), then Odyssey, Wild, Orbit X and ToonZ (0.98.0). */
|
||||
private val SmartChannelTiers: Map<Int, Map<String, Double>> get() = mapOf(103 to ThreeTiers, 202 to OdysseyTiers, 203 to WildTiers, 603 to OrbitXTiers, 605 to ToonZTiers)
|
||||
|
||||
/** 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,
|
||||
@@ -373,7 +378,8 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
||||
val why = "$block; weighted: lowest tally for its tier (${"%.0f".format(tally[series.id])})" + if (eligible.size < clear.size) ", others resting or just played" else ""
|
||||
val item = if (series.isFilm) SampleItem(series.title, "Movie", episode.durationMs / 60_000, "", episode.id, episode.durationMs) else scheduledItem(series.title, episode)
|
||||
entries += ScheduleEntry(series.id, episode.mark, ScheduledMedia(item, episode.sourceId, episode.durationMs), start, why, if (series in available) part?.key.orEmpty() else "")
|
||||
tally[series.id] = tally[series.id]!! + episode.durationMs / 60_000.0 / weightOf(series)
|
||||
val weight = part?.takeIf { series in available }?.weights?.get(seriesKey(series.title)) ?: weightOf(series)
|
||||
tally[series.id] = tally[series.id]!! + episode.durationMs / 60_000.0 / weight
|
||||
marks[series.id] = episode.mark
|
||||
aired[episode.id] = start
|
||||
// The start of a run: its first episode in season order, or the first of its shuffled deck.
|
||||
@@ -385,6 +391,41 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
||||
return ChannelPlan(entries, ScheduleCursor(last, marks, shown, cursor.blockLast, tallies, runStarted))
|
||||
}
|
||||
|
||||
/**
|
||||
* Weighted rotation for a channel whose blocks don't all use it: each stretch of weighted blocks goes to [extendWeighted],
|
||||
* each stretch of the others to [extendSchedule], exactly as they'd be planned on their own, carrying the cursor across.
|
||||
* With every block weighted, this is one call to [extendWeighted].
|
||||
*/
|
||||
internal fun extendByBlock(pool: List<PoolSeries>, cursor: ScheduleCursor, fromMs: Long, untilMs: Long, weightOf: (PoolSeries) -> Double,
|
||||
dayParts: List<DayPart>, zone: java.time.ZoneId, avoid: ProgrammeClash, shuffle: Boolean, mixed: (PoolSeries) -> Boolean, finishTogether: Boolean,
|
||||
recentFiles: Map<String, Long> = emptyMap(), runBefore: Int = 0): ChannelPlan {
|
||||
fun weightedAt(at: Long) = dayPartFor(pool, dayParts, at, zone).third?.weighted != false
|
||||
val hour = 60 * 60_000L
|
||||
val entries = mutableListOf<ScheduleEntry>()
|
||||
var tail = cursor
|
||||
var start = fromMs
|
||||
while (start < untilMs) {
|
||||
val weighted = weightedAt(start)
|
||||
// Blocks change on the hour, so the stretch ends at the first hour that changes the rule.
|
||||
var end = java.time.Instant.ofEpochMilli(start).atZone(zone).truncatedTo(java.time.temporal.ChronoUnit.HOURS).toInstant().toEpochMilli() + hour
|
||||
while (end < untilMs && weightedAt(end) == weighted) end += hour
|
||||
val stretch = if (weighted) {
|
||||
val recent = recentFiles + entries.filter { it.startMs >= start - SAME_FILE_MS }.associate { it.media.item.id to it.startMs }
|
||||
extendWeighted(pool, tail, start, minOf(end, untilMs), weightOf, dayParts, zone, avoid, shuffle, mixed, recent)
|
||||
} else {
|
||||
val trailing = entries.lastOrNull()?.let { t -> entries.asReversed().takeWhile { it.seriesId == t.seriesId }.size } ?: runBefore
|
||||
extendSchedule(pool, tail, start, minOf(end, untilMs), null, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing).let { plan ->
|
||||
// Equal turns know nothing of tallies; they wait unchanged for the next weighted stretch.
|
||||
plan.copy(tail = plan.tail.copy(tallies = tail.tallies, runStarted = tail.runStarted))
|
||||
}
|
||||
}
|
||||
entries += stretch.entries
|
||||
tail = stretch.tail
|
||||
start = stretch.entries.lastOrNull()?.endMs ?: break
|
||||
}
|
||||
return ChannelPlan(entries, tail)
|
||||
}
|
||||
|
||||
/** Shows take turns, one episode each, back to back from [fromMs] until [untilMs] is covered. */
|
||||
internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, fromMs: Long, untilMs: 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,
|
||||
@@ -535,7 +576,7 @@ internal fun topUpPlan(existing: ChannelPlan?, aired: ScheduleCursor, pool: List
|
||||
val trailing = kept?.entries?.lastOrNull()?.let { tail -> kept.entries.asReversed().takeWhile { it.seriesId == tail.seriesId }.size } ?: 0
|
||||
val added = if (weightOf != null && filmRestMs == null) {
|
||||
val recent = kept?.entries.orEmpty().filter { it.startMs >= from - SAME_FILE_MS }.associate { it.media.item.id to it.startMs }
|
||||
extendWeighted(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, weightOf, dayParts, zone, avoid, shuffle, mixed, recent)
|
||||
extendByBlock(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, weightOf, dayParts, zone, avoid, shuffle, mixed, finishTogether, recent, trailing)
|
||||
} else 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.97.0\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.98.0\"")
|
||||
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.97.0")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.98.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()) {
|
||||
|
||||
@@ -14,7 +14,11 @@ private val TotsPlaytime = listOf("Peppa Pig", "Ben and Holly's Little Kingdom",
|
||||
internal val TotsWindDown = listOf("CBeebies Bedtime Stories", "In The Night Garden", "Clangers", "BeddyByes")
|
||||
|
||||
internal val TotsShows get() = TotsMorning + TotsPlaytime + TotsWindDown
|
||||
internal val TotsDayParts get() = listOf(DayPart(6, 9, TotsMorning), DayPart(9, 17, TotsMorning + TotsPlaytime), DayPart(17, 21, TotsWindDown), DayPart(21, 6, TotsWindDown))
|
||||
// Wind Down and Night keep equal turns: four shows can't share 13 hours a day fairly without heavy repeats. Their own decision comes later.
|
||||
internal val TotsDayParts get() = listOf(DayPart(6, 9, TotsMorning), DayPart(9, 17, TotsMorning + TotsPlaytime), DayPart(17, 21, TotsWindDown, weighted = false),
|
||||
DayPart(21, 6, TotsWindDown, weighted = false))
|
||||
/** Tots has no tiers: Morning and Playtime share their airtime equally by minutes (4 November 2026). */
|
||||
internal val TotsTiers: Map<String, Double> get() = emptyMap()
|
||||
|
||||
internal enum class TotsMood(val video: Int, val still: Int, val lengthMs: Long, val fadeMs: Int, val sings: Boolean) {
|
||||
Morning(R.raw.ident_614_morning, R.drawable.orbit_tots_still_morning, 5_000, 400, true),
|
||||
|
||||
Reference in New Issue
Block a user