Add Orbit Gold, Heroes and Evidence, with a fallback made from each pool (0.49.0 in testing)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m54s
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-02 08:58:06 +00:00
co-authored by Claude Opus 5.5
parent 3039235d13
commit 1a5b6d67f2
20 changed files with 87 additions and 16 deletions
@@ -7,6 +7,9 @@ internal object ChannelBrands {
101 to ChannelBranding("orbit-1", "Orbit 1", R.drawable.orbit_one_epg, R.drawable.orbit_one_background, R.drawable.orbit_one_bug, ChannelCategory.Entertainment),
102 to ChannelBranding("orbit-after-dark", "Orbit After Dark", R.drawable.orbit_after_dark_epg, R.drawable.orbit_after_dark_background, R.drawable.orbit_after_dark_bug, ChannelCategory.Movies),
103 to ChannelBranding("vortex", "Vortex", R.drawable.vortex_epg, R.drawable.vortex_background, R.drawable.vortex_bug, ChannelCategory.Entertainment),
111 to ChannelBranding("orbit-gold", "Orbit Gold", R.drawable.orbit_gold_epg, R.drawable.orbit_gold_background, R.drawable.orbit_gold_bug, ChannelCategory.Comedy),
121 to ChannelBranding("heroes", "Orbit Heroes", R.drawable.heroes_epg, R.drawable.heroes_background, R.drawable.heroes_bug, ChannelCategory.Entertainment),
141 to ChannelBranding("evidence", "Orbit Evidence", R.drawable.evidence_epg, R.drawable.evidence_background, R.drawable.evidence_bug, ChannelCategory.Entertainment),
140 to ChannelBranding("orbit-terra", "Orbit Terra", R.drawable.orbit_terra_epg, R.drawable.orbit_terra_background, R.drawable.orbit_terra_bug, ChannelCategory.Documentaries),
152 to ChannelBranding("paradox", "Orbit Paradox", R.drawable.paradox_epg, R.drawable.paradox_background, R.drawable.paradox_bug, ChannelCategory.Entertainment))
fun forNumber(number: Int): ChannelBranding? = brands[number]
@@ -1,11 +1,27 @@
package tv.orbit.classic
/** A channel the app can build from named shows. Numbers follow the design and may change with the generic channel list. */
internal data class ChannelPreset(val number: Int, val name: String, val searches: List<String>)
internal data class ChannelPreset(val number: Int, val name: String, val searches: List<String>,
/** Started from its smart schedule alone, with no separate loop to build first. */
val smartOnly: Boolean = false)
internal val ChannelPresets = listOf(
ChannelPreset(140, "Terra", listOf("Blue Planet", "Planet Earth", "Frozen Planet", "Life", "Our Planet")),
ChannelPreset(152, "Paradox", listOf("X-Files", "Buffy the Vampire Slayer", "Supernatural", "Fringe", "Doctor Who")))
ChannelPreset(152, "Paradox", listOf("X-Files", "Buffy the Vampire Slayer", "Supernatural", "Fringe", "Doctor Who")),
ChannelPreset(111, "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"), smartOnly = true),
ChannelPreset(121, "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"), smartOnly = true),
ChannelPreset(141, "Evidence", listOf("CSI: Crime Scene Investigation", "NCIS", "CSI: Miami", "CSI: NY", "Law & Order", "Law & Order: Special Victims Unit", "Criminal Minds", "Bones",
"Castle", "The Mentalist", "Monk", "Columbo", "Midsomer Murders", "Vera", "Luther", "Line of Duty", "Taggart", "Silent Witness", "Waking the Dead", "A Touch of Frost"), smartOnly = true))
/** A fallback for a channel with no old loop: its first episodes, in turn. Used only outside its plan. */
internal fun loopFromPool(pool: List<PoolSeries>, programming: ChannelProgramming): SampleChannel? {
val turns = (0 until (pool.maxOfOrNull { it.episodes.size } ?: 0)).asSequence().flatMap { round -> pool.asSequence().mapNotNull { show -> show.episodes.getOrNull(round)?.let { show to it } } }
val media = turns.take(15).map { (show, episode) -> ScheduledMedia(scheduledItem(show.title, episode), episode.sourceId, episode.durationMs) }.toList()
return if (media.size < 2) null else SampleChannel(media, programming.name, programming.number)
}
/** What a build used, so the viewer can see what the library did and didn't have. */
internal class PresetBuild(val channel: SampleChannel, val shows: List<String>, val missing: List<String>)
@@ -19,7 +19,7 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
val dayParts: List<DayPart> = emptyList(),
val suggestionRules: List<SuggestionRule> = emptyList()) {
/** Changes when the list does, so the episode cache is read again. What's already committed stays. */
val signature get() = "${searches.joinToString("|")}#$seriesCount"
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount"
}
/** Toonami-inspired: Paul's picks and the earlier shortlist, split into cartoons by day and anime from the evening. */
@@ -56,7 +56,8 @@ internal val SmartChannels = listOf(
"Life on Earth", "The Living Planet", "The Trials of Life", "Our Planet", "Our Planet II", "Dynasties", "Dynasties II", "Seven Worlds, One Planet", "A Perfect Planet",
"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(152, "Paradox", ChannelPresets.first { it.number == 152 }.searches))
ChannelProgramming(152, "Paradox", ChannelPresets.first { it.number == 152 }.searches)) +
ChannelPresets.filter { it.smartOnly }.map { ChannelProgramming(it.number, it.name, it.searches, seriesCount = 25, finishTogether = true, exactTitles = true) }
internal data class EpisodeMark(val season: Int, val episode: Int) : Comparable<EpisodeMark> {
override fun compareTo(other: EpisodeMark) = compareValuesBy(this, other, { it.season }, { it.episode })
@@ -81,6 +82,9 @@ internal data class ChannelPlan(val entries: List<ScheduleEntry>, val tail: Sche
val endMs get() = entries.lastOrNull()?.endMs ?: Long.MIN_VALUE
}
/** Bump when the way pools are read changes, so each channel reads its once again. */
private const val CHANNEL_POOL_VERSION = 2
internal const val SCHEDULE_AHEAD_MS = 7 * 24 * 60 * 60_000L
internal const val SCHEDULE_TOP_UP_MS = 6 * 24 * 60 * 60_000L
internal const val SCHEDULE_KEEP_PAST_MS = 24 * 60 * 60_000L
@@ -26,6 +26,15 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
store.saveProgress(userId, number, ScheduleStore.SavedProgress(enabled, progress?.aired ?: ScheduleCursor()))
}
/** Starts a channel that has no loop yet: reads its pool, then gives it a small fallback made from that pool. */
fun seedLoop(session: EmbySampleSession, userId: String, programming: ChannelProgramming, checkActive: () -> Unit = {}): SampleChannel {
val choices = store.loadChoices(userId, programming.number)
val read = session.readChannelPool(programming, null, choices, checkActive)
val loop = loopFromPool(read.series, programming) ?: throw EmbyCheckException("None of ${programming.name}'s shows were found with episodes to schedule.")
store.savePool(userId, programming.number, ScheduleStore.SavedPool(read.series, clock(), "${programming.signature}#${choices.tag}"))
return loop
}
/**
* Brings a channel's plan up to seven days ahead, reading the provider only if the cached pool is missing or old.
* A failed refresh keeps what's there, so a provider outage can't disturb what's committed.
@@ -41,7 +41,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.48.0\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.49.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -448,7 +448,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
}
fun setSmartSchedule(programming: ChannelProgramming, turnOn: Boolean) {
val active = session ?: return
val loop = smartLoop(programming) ?: return
val existing = smartLoop(programming)
if (existing == null && ChannelPresets.none { it.number == programming.number }) return
// A second press straight after the first is taken as a slip.
if (busy || now - lastSmartPress < 5_000) return
lastSmartPress = now
@@ -459,10 +460,12 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
val report = withContext(Dispatchers.IO) {
val context = coroutineContext
scheduler.setEnabled(active.accountId, programming.number, true)
val loop = existing ?: scheduler.seedLoop(active, active.accountId, programming) { context.ensureActive() }.also { extraChannels = extraChannels + it }
scheduler.topUp(active, active.accountId, programming, loop) { context.ensureActive() }.also {
scheduler.load(active.accountId, loop)?.let { on -> scheduledChannels = scheduledChannels + (programming.number to on) }
}
}
onChannelAvailable(true)
message = "${programming.name} is scheduled: ${report.programmes} programmes from ${report.episodes} titles: ${report.shows.take(10).joinToString()}${if (report.shows.size > 10) " and ${report.shows.size - 10} more" else ""}. " +
"${report.requests} requests, ${report.fetchMs / 1000} s to read, ${report.planMs} ms to plan, ${report.bytes / 1024} KB stored."
} else {
@@ -719,7 +722,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
Modifier.fillMaxWidth(), enabled = !busy && session != null, onClick = {
if (seriesMatches != null) reviewingSeries = true else checkMoreSeries()
})
ChannelPresets.forEach { preset ->
ChannelPresets.filterNot { it.smartOnly }.forEach { preset ->
val built = extraChannels.any { it.number == preset.number }
OrbitButton("${preset.number} ${preset.name} — ${if (built) "rebuild" else "build"}", Modifier.fillMaxWidth(),
enabled = !busy && session != null, onClick = { buildPreset(preset) })
@@ -727,7 +730,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
SmartChannels.forEach { programming ->
val on = scheduledChannels.containsKey(programming.number)
OrbitButton("${programming.number} ${programming.name} — smart schedule is ${if (on) "ON. Press to go back to its loop" else "OFF. Press to turn on"}", Modifier.fillMaxWidth(),
enabled = !busy && session != null && smartLoop(programming) != null, onClick = { setSmartSchedule(programming, !on) })
enabled = !busy && session != null && (smartLoop(programming) != null || ChannelPresets.any { it.number == programming.number }), onClick = { setSmartSchedule(programming, !on) })
if (programming.suggestionRules.isNotEmpty()) OrbitButton("${programming.number} ${programming.name} — bigger pool: review suggestions", Modifier.fillMaxWidth(),
enabled = !busy && session != null && smartLoop(programming) != null, onClick = { openSuggestions(programming) })
}
@@ -186,12 +186,12 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
internal class PoolRead(val series: List<PoolSeries>, val requests: Int)
/** The first shows in the channel's list that have episodes to schedule. */
fun readChannelPool(programming: ChannelProgramming, loop: SampleChannel, choices: ChannelChoices = ChannelChoices(), checkActive: () -> Unit = {}): PoolRead {
fun readChannelPool(programming: ChannelProgramming, loop: SampleChannel?, choices: ChannelChoices = ChannelChoices(), checkActive: () -> Unit = {}): PoolRead {
var requests = 0
val pool = mutableListOf<PoolSeries>()
if (programming.filmRestMs != null) {
// Films you've already chosen for this channel stay in it.
loop.lineup.filter { it.item.type == "Movie" }.forEach { pool += PoolSeries(it.item.id, it.item.title, listOf(PoolEpisode(it.item.id, it.sourceId, EpisodeMark(1, 1), it.item.title, it.durationMs))) }
loop?.lineup.orEmpty().filter { it.item.type == "Movie" }.forEach { pool += PoolSeries(it.item.id, it.item.title, listOf(PoolEpisode(it.item.id, it.sourceId, EpisodeMark(1, 1), it.item.title, it.durationMs))) }
for (title in programming.searches) {
if (pool.size >= programming.seriesCount) break
checkActive()
@@ -205,13 +205,14 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
requests++
val candidates = searchSeries(transport, userId, ::currentToken, search).candidates
val match = bestSeriesMatch(search, if (programming.exactTitles) candidates.filter { seriesKey(it.title) == seriesKey(search) } else candidates) ?: continue
if (pool.any { it.id == match.id }) continue
// A second copy of a show in the library counts as the same show.
if (pool.any { it.id == match.id || seriesKey(it.title) == seriesKey(match.title) }) continue
val whole = readWholeSeries(transport, userId, ::currentToken, match, checkActive, onRequest = { requests++ })
if (whole.episodes.isNotEmpty()) pool += whole
}
for (accepted in choices.accepted) {
checkActive()
if (pool.any { it.id == accepted.id }) continue
if (pool.any { it.id == accepted.id || seriesKey(it.title) == seriesKey(accepted.title) }) continue
if (accepted.type == "Movie") {
val source = accepted.sourceId ?: continue
val duration = accepted.durationMs ?: 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.48.0")
next.setRequestProperty("User-Agent", "OrbitTV/0.49.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()) {