|
|
|
@@ -21,11 +21,22 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
|
|
|
|
/** Leave out episodes with no English sound. Off where subtitled shows belong, like Vortex's anime. */
|
|
|
|
|
val englishAudio: Boolean = true,
|
|
|
|
|
/** Each show's episodes in a mixed order, all of them before any repeats. Everything else runs in season order. */
|
|
|
|
|
val shuffleEpisodes: Boolean = false) {
|
|
|
|
|
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()) {
|
|
|
|
|
/** 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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Expect the unexpected: standalone adventures by day in a mixed order, cult drama in order in prime time, and the strange stuff late. */
|
|
|
|
|
private val ParadoxStandalones = listOf("Doctor Who (2005)", "Star Trek: The Next Generation", "The X-Files", "The Twilight Zone", "Stargate SG-1", "Sliders", "Warehouse 13", "Eureka")
|
|
|
|
|
private val ParadoxPrimeTime = listOf("Buffy the Vampire Slayer", "Angel", "Supernatural", "Fringe")
|
|
|
|
|
private val ParadoxLate = listOf("Twin Peaks", "The Outer Limits", "The Outer Limits (1995)", "Torchwood", "Farscape", "The X-Files")
|
|
|
|
|
private val ParadoxShows get() = (ParadoxStandalones + ParadoxPrimeTime + ParadoxLate).distinct()
|
|
|
|
|
private val ParadoxDayParts get() = listOf(DayPart(6, 18, ParadoxStandalones), DayPart(18, 23, ParadoxPrimeTime), DayPart(23, 6, ParadoxLate))
|
|
|
|
|
|
|
|
|
|
/** Toonami-inspired: Paul's picks and the earlier shortlist, split into cartoons by day and anime from the evening. */
|
|
|
|
|
private val VortexDaytime = listOf("Batman Beyond", "Batman: The Animated Series", "Superman: The Animated Series", "ThunderCats", "The Powerpuff Girls", "Jonny Quest",
|
|
|
|
|
"Samurai Jack", "Justice League", "Justice League Unlimited", "Voltron", "Voltron: Defender of the Universe", "ReBoot", "Beast Wars: Transformers")
|
|
|
|
@@ -61,7 +72,7 @@ internal val SmartChannels = listOf(
|
|
|
|
|
"Hostile Planet", "Africa", "Wild China", "South Pacific", "Great Barrier Reef", "The Hunt", "The Life of Mammals", "The Life of Birds", "Nature's Great Events", "Green Planet", "Prehistoric Planet"),
|
|
|
|
|
seriesCount = 20, finishTogether = true, exactTitles = true),
|
|
|
|
|
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = TotsDayParts, shuffleEpisodes = true),
|
|
|
|
|
ChannelProgramming(106, "Paradox", ChannelPresets.first { it.number == 106 }.searches)) +
|
|
|
|
|
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()) }
|
|
|
|
@@ -229,6 +240,8 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
|
|
|
|
|
/** 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,
|
|
|
|
|
/** Shows to mix even when [shuffle] is off. */
|
|
|
|
|
mixed: (PoolSeries) -> Boolean = { false },
|
|
|
|
|
/** 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. */
|
|
|
|
@@ -242,9 +255,10 @@ 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
|
|
|
|
|
fun running(show: PoolSeries) = if (shuffle) mixes.getOrPut(show.id) { shuffledEpisodes(show) } else show.episodes
|
|
|
|
|
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 {
|
|
|
|
|
if (!shuffle) return nextEpisode(show, marks[show.id])
|
|
|
|
|
if (!isMixed(show)) return nextEpisode(show, marks[show.id])
|
|
|
|
|
val mix = running(show)
|
|
|
|
|
return mix[(mix.indexOfFirst { it.mark == marks[show.id] } + 1) % mix.size]
|
|
|
|
|
}
|
|
|
|
@@ -278,7 +292,7 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
|
|
|
|
picked != null -> "; next in turn"
|
|
|
|
|
else -> "; fallback: every show in turn airs elsewhere then"
|
|
|
|
|
})
|
|
|
|
|
if (shuffle) append(", episode from its shuffled order")
|
|
|
|
|
if (isMixed(series)) append(", episode from its shuffled order")
|
|
|
|
|
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)}")
|
|
|
|
@@ -315,13 +329,14 @@ internal fun airedCursor(base: ScheduleCursor, entries: List<ScheduleEntry>, now
|
|
|
|
|
* With no usable plan it starts from now at the aired position.
|
|
|
|
|
*/
|
|
|
|
|
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): ChannelPlan? {
|
|
|
|
|
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? {
|
|
|
|
|
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, trailing, noThirdInARow)
|
|
|
|
|
val added = extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid, shuffle, mixed, trailing, noThirdInARow)
|
|
|
|
|
return ChannelPlan(kept?.entries.orEmpty() + added.entries, added.tail)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|