|
|
|
@@ -78,7 +78,9 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
|
|
|
|
* Multi-part stories booked whole, in order and back to back ([storiesOf], [extendWeighted]); weighted blocks only. Paradox
|
|
|
|
|
* only (Living Network Stage A, approved 4 November 2026).
|
|
|
|
|
*/
|
|
|
|
|
val storyGrouping: Boolean = false) {
|
|
|
|
|
val storyGrouping: Boolean = false,
|
|
|
|
|
/** Shorts grouping (Paul, 6 November 2026): short episodes gathered into slots of about half an hour. Null for none. */
|
|
|
|
|
val shorts: ShortsRule? = null) {
|
|
|
|
|
/** The items taken off this channel on the server signed in to: [withdrawnOnOriginal] there, none anywhere else. */
|
|
|
|
|
val withdrawn: Set<String> get() = if (Workspaces.originalOpen) withdrawnOnOriginal else emptySet()
|
|
|
|
|
/** A show's weight here, by its tier (a show the brief doesn't name counts as supporting), scaled by [catalogueScaleHours]. */
|
|
|
|
@@ -201,7 +203,7 @@ internal val SmartChannels = listOf(
|
|
|
|
|
// 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,
|
|
|
|
|
tierWeights = TotsTiers, catalogueScaleHours = CATALOGUE_SCALE_HOURS, storyGrouping = 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(),
|
|
|
|
|
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,
|
|
|
|
@@ -209,7 +211,8 @@ internal val SmartChannels = listOf(
|
|
|
|
|
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], adaptiveFilmRest = it.number in AdaptiveFilmRestChannels,
|
|
|
|
|
catalogueScaleHours = if (it.number in CatalogueScaledChannels) CATALOGUE_SCALE_HOURS else null,
|
|
|
|
|
catalogueScaleFloor = CatalogueScaleFloors[it.number] ?: MIN_CATALOGUE_SCALE, storyGrouping = it.number in StoryGroupingChannels) }
|
|
|
|
|
catalogueScaleFloor = CatalogueScaleFloors[it.number] ?: MIN_CATALOGUE_SCALE, storyGrouping = it.number in StoryGroupingChannels,
|
|
|
|
|
shorts = if (it.number == 605) ToonZShorts else null) }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Living Network Stage E: story grouping beyond Paradox, one channel at a time. Heroes first (4 November 2026): 119 story parts a
|
|
|
|
@@ -291,7 +294,9 @@ internal data class ScheduleEntry(val seriesId: String, val mark: EpisodeMark, v
|
|
|
|
|
/** Why the planner chose this, for diagnostics only. Empty for programmes planned before reasons were kept. */
|
|
|
|
|
val why: String = "",
|
|
|
|
|
/** The block's or event's presentation key, saved when the programme is booked (see [DayPart.key]). Empty for ordinary programmes and older bookings. */
|
|
|
|
|
val presentation: String = "") {
|
|
|
|
|
val presentation: String = "",
|
|
|
|
|
/** The shorts slot this programme was booked in ([shortsTag]), or empty. Presentation only: the programme is still its own entry. */
|
|
|
|
|
val group: String = "") {
|
|
|
|
|
val endMs get() = startMs + media.durationMs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -654,8 +659,11 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
/** How long a file rests before it may air again while another show could play. [SAME_FILE_MS] unless a channel asks for longer. */
|
|
|
|
|
fileRestMs: Long = SAME_FILE_MS,
|
|
|
|
|
/** Story-aware grouping ([ChannelProgramming.storyGrouping]): multi-part stories are booked whole, in order, back to back. */
|
|
|
|
|
stories: Boolean = false): ChannelPlan {
|
|
|
|
|
stories: Boolean = false,
|
|
|
|
|
/** Shorts grouping ([ShortsRule]), or null for none. */
|
|
|
|
|
shorts: ShortsRule? = null): ChannelPlan {
|
|
|
|
|
val marks = cursor.marks.toMutableMap()
|
|
|
|
|
var slot: ShortsSlot? = null
|
|
|
|
|
val shown = cursor.filmShown.toMutableMap()
|
|
|
|
|
val tallies = cursor.tallies.mapValues { it.value.toMutableMap() }.toMutableMap()
|
|
|
|
|
val runStarted = cursor.runStarted.toMutableMap()
|
|
|
|
@@ -762,7 +770,11 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
}
|
|
|
|
|
return appointmentAhead == null || at <= appointmentAhead + ON_TIME_GRACE_MS
|
|
|
|
|
}
|
|
|
|
|
val clear = unclashed.ifEmpty { available }.let { shows -> if (stories) shows.filter(::storyFits).ifEmpty { shows } else shows }
|
|
|
|
|
val open = unclashed.ifEmpty { available }.let { shows -> if (stories) shows.filter(::storyFits).ifEmpty { shows } else shows }
|
|
|
|
|
// Inside a shorts slot only the shorts that fit it take part; none fits, and the slot closes where it is.
|
|
|
|
|
val inSlot = slot?.let { s -> unclashed.filter { it.id != last && s.takes(start, following(it).durationMs) } }.orEmpty()
|
|
|
|
|
if (inSlot.isEmpty()) slot = null
|
|
|
|
|
val clear = if (continuing == null && inSlot.isNotEmpty()) inSlot else open
|
|
|
|
|
val rules = listOf<(PoolSeries) -> Boolean>(
|
|
|
|
|
{ it.id != last }, { aired[following(it).id]?.let { at -> start - at < fileRestMs } != true }, { following(it).mark != running(it).first().mark || runStarted[it.id]?.let { at -> start - at < RUN_REST_MS } != true })
|
|
|
|
|
// Drop the softest rules first, only as far as needed to leave a choice.
|
|
|
|
@@ -789,7 +801,8 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
(if (story != null) "; story: part 1 of ${story.first}, booked whole" else "") +
|
|
|
|
|
(if (part?.premiere == true && series in available) "; premiere: first airing on Orbit" 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 "")
|
|
|
|
|
val tag = shortsTagFor(shorts, slot, series, episode, series in available, start, zone).also { slot = it.second }.first
|
|
|
|
|
entries += ScheduleEntry(series.id, episode.mark, ScheduledMedia(item, episode.sourceId, episode.durationMs), start, why + if (tag.isEmpty()) "" else "; shorts slot", if (series in available) part?.key.orEmpty() else "", tag)
|
|
|
|
|
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
|
|
|
|
@@ -803,7 +816,7 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
last = series.id
|
|
|
|
|
start += episode.durationMs
|
|
|
|
|
}
|
|
|
|
|
return ChannelPlan(entries, ScheduleCursor(last, marks, shown, cursor.blockLast, tallies, runStarted))
|
|
|
|
|
return ChannelPlan(withoutLoneShorts(entries), ScheduleCursor(last, marks, shown, cursor.blockLast, tallies, runStarted))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -813,7 +826,7 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
*/
|
|
|
|
|
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, fileRestMs: Long = SAME_FILE_MS, stories: Boolean = false): ChannelPlan {
|
|
|
|
|
recentFiles: Map<String, Long> = emptyMap(), runBefore: Int = 0, fileRestMs: Long = SAME_FILE_MS, stories: Boolean = false, shorts: ShortsRule? = null): ChannelPlan {
|
|
|
|
|
fun weightedAt(at: Long) = dayPartFor(pool, dayParts, at, zone).third?.weighted != false
|
|
|
|
|
val hour = 60 * 60_000L
|
|
|
|
|
val entries = mutableListOf<ScheduleEntry>()
|
|
|
|
@@ -826,10 +839,10 @@ internal fun extendByBlock(pool: List<PoolSeries>, cursor: ScheduleCursor, fromM
|
|
|
|
|
while (end < untilMs && weightedAt(end) == weighted) end += hour
|
|
|
|
|
val stretch = if (weighted) {
|
|
|
|
|
val recent = recentFiles + entries.filter { it.startMs >= start - fileRestMs }.associate { it.media.item.id to it.startMs }
|
|
|
|
|
extendWeighted(pool, tail, start, minOf(end, untilMs), weightOf, dayParts, zone, avoid, shuffle, mixed, recent, fileRestMs, stories)
|
|
|
|
|
extendWeighted(pool, tail, start, minOf(end, untilMs), weightOf, dayParts, zone, avoid, shuffle, mixed, recent, fileRestMs, stories, shorts)
|
|
|
|
|
} 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, stories = stories).let { plan ->
|
|
|
|
|
extendSchedule(pool, tail, start, minOf(end, untilMs), null, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing, stories = stories, shorts = shorts).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))
|
|
|
|
|
}
|
|
|
|
@@ -855,7 +868,9 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
/** Film channels only: see [ChannelProgramming.adaptiveFilmRest]. */
|
|
|
|
|
adaptiveRest: Boolean = false,
|
|
|
|
|
/** Story-aware mixing (Paul, 5 November 2026: part ones first, everywhere): a mixed show keeps each multi-part story whole and in order in its deck. */
|
|
|
|
|
stories: Boolean = false): ChannelPlan {
|
|
|
|
|
stories: Boolean = false,
|
|
|
|
|
/** Shorts grouping ([ShortsRule]), or null for none. */
|
|
|
|
|
shorts: ShortsRule? = null): ChannelPlan {
|
|
|
|
|
require(pool.isNotEmpty() && pool.all { it.episodes.isNotEmpty() })
|
|
|
|
|
if (filmRestMs != null) return extendFilmSchedule(pool, cursor, fromMs, untilMs, filmRestMs, dayParts, zone, avoid, adaptiveRest)
|
|
|
|
|
val marks = cursor.marks.toMutableMap()
|
|
|
|
@@ -892,6 +907,7 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
val mix = running(show)
|
|
|
|
|
return mix[(mix.indexOfFirst { it.mark == marks[show.id] } + 1) % mix.size]
|
|
|
|
|
}
|
|
|
|
|
var slot: ShortsSlot? = null
|
|
|
|
|
while (start < untilMs) {
|
|
|
|
|
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.
|
|
|
|
@@ -902,7 +918,10 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
val waiting = mutableListOf<String>(); val elsewhere = mutableListOf<String>()
|
|
|
|
|
// 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 ->
|
|
|
|
|
// Inside a shorts slot, the next short in turn that fits it; none fits, and the slot closes where it is.
|
|
|
|
|
val inSlot = slot?.let { open -> turnOrder(pool, after).firstOrNull { show -> show.id != last && allowed(show) && open.takes(start, following(show).durationMs) && !avoid(show, start, start + following(show).durationMs) } }
|
|
|
|
|
if (inSlot == null) slot = null
|
|
|
|
|
val picked = inSlot ?: 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 }
|
|
|
|
@@ -952,7 +971,8 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
}
|
|
|
|
|
val item = if (series.isFilm) SampleItem(series.title, "Movie", episode.durationMs / 60_000, "", episode.id, episode.durationMs) else scheduledItem(series.title, episode)
|
|
|
|
|
val media = ScheduledMedia(item, episode.sourceId, episode.durationMs)
|
|
|
|
|
entries += ScheduleEntry(series.id, episode.mark, media, start, why, if (series in available) part?.key.orEmpty() else "")
|
|
|
|
|
val tag = shortsTagFor(shorts, slot, series, episode, series in available, start, zone).also { slot = it.second }.first
|
|
|
|
|
entries += ScheduleEntry(series.id, episode.mark, media, start, why + if (tag.isEmpty()) "" else "; shorts slot", if (series in available) part?.key.orEmpty() else "", tag)
|
|
|
|
|
marks[series.id] = episode.mark
|
|
|
|
|
run = if (series.id == last) run + 1 else 1
|
|
|
|
|
last = series.id
|
|
|
|
@@ -960,7 +980,7 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
if (series.isFilm) shown[series.id] = start
|
|
|
|
|
start += episode.durationMs
|
|
|
|
|
}
|
|
|
|
|
return ChannelPlan(entries, ScheduleCursor(last, marks, shown, blockLast))
|
|
|
|
|
return ChannelPlan(withoutLoneShorts(entries), ScheduleCursor(last, marks, shown, blockLast))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal fun scheduledItem(seriesTitle: String, episode: PoolEpisode) = SampleItem(
|
|
|
|
@@ -993,7 +1013,9 @@ internal fun topUpPlan(existing: ChannelPlan?, aired: ScheduleCursor, pool: List
|
|
|
|
|
/** Weighted channels only: see [extendWeighted]. */
|
|
|
|
|
fileRestMs: Long = SAME_FILE_MS,
|
|
|
|
|
/** Weighted channels only: see [ChannelProgramming.storyGrouping]. */
|
|
|
|
|
stories: Boolean = false): ChannelPlan? {
|
|
|
|
|
stories: Boolean = false,
|
|
|
|
|
/** See [ChannelProgramming.shorts]. */
|
|
|
|
|
shorts: ShortsRule? = null): 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
|
|
|
|
@@ -1001,8 +1023,8 @@ 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 - fileRestMs }.associate { it.media.item.id to it.startMs }
|
|
|
|
|
extendByBlock(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, weightOf, dayParts, zone, avoid, shuffle, mixed, finishTogether, recent, trailing, fileRestMs, stories)
|
|
|
|
|
} else extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing, noThirdInARow, blockRotation, adaptiveRest, stories = stories)
|
|
|
|
|
extendByBlock(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, weightOf, dayParts, zone, avoid, shuffle, mixed, finishTogether, recent, trailing, fileRestMs, stories, shorts)
|
|
|
|
|
} else extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing, noThirdInARow, blockRotation, adaptiveRest, stories = stories, shorts = shorts)
|
|
|
|
|
return ChannelPlan(kept?.entries.orEmpty() + added.entries, added.tail)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|