0.92.0: Joe Bob Saturdays (opt-in series on a film channel, After Dark only)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m52s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m24s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-03 15:04:25 +00:00
co-authored by Claude Opus 5.5
parent 1449628890
commit 06912c33a1
10 changed files with 141 additions and 12 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 112
versionName = "0.91.1-film-nights"
versionCode = 114
versionName = "0.92.0-joe-bob-saturdays"
}
buildFeatures { compose = true }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
@@ -286,4 +286,10 @@ internal val CultClassics = listOf("The Rocky Horror Picture Show", "Repo Man",
* plays, as on any film channel; when none of its films are in the library at all, the channel's usual block carries on.
*/
internal val HorrorDayParts get() = listOf(DayPart(20, 2, SlasherSaturday, days = setOf(DayOfWeek.SATURDAY)))
internal val AfterDarkEvents get() = listOf(DayPart(21, 1, BMovieThrowbacks, days = setOf(DayOfWeek.FRIDAY)), DayPart(21, 1, CultClassics, days = setOf(DayOfWeek.SUNDAY)))
/**
* After Dark's Saturday staple: one whole hosted episode, in order, running its full length however long. Its window opens at 20:00
* because the film before it is usually still running: starting from the first slot after 20:00 lands it around 21:00.
*/
internal const val LAST_DRIVE_IN = "The Last Drive-in with Joe Bob Briggs"
internal val AfterDarkEvents get() = listOf(DayPart(21, 1, BMovieThrowbacks, days = setOf(DayOfWeek.FRIDAY)), DayPart(20, 1, listOf(LAST_DRIVE_IN), days = setOf(DayOfWeek.SATURDAY)),
DayPart(21, 1, CultClassics, days = setOf(DayOfWeek.SUNDAY)))
@@ -24,11 +24,13 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
/** Each show's episodes in a mixed order, all of them before any repeats. Everything else runs in season order. */
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()) {
val shuffleTitles: Set<String> = emptySet(),
/** 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"
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount" + if (filmSeries.isEmpty()) "" else "#series:${filmSeries.joinToString("|")}"
}
/** Expect the unexpected: standalone adventures by day in a mixed order, cult drama in order in prime time, and the strange stuff late. */
@@ -54,7 +56,7 @@ private val AfterDarkFilms = listOf("The Thing (1982)", "The Evil Dead (1983)",
"Army of Darkness", "House (1977)", "The Holy Mountain", "Repo! The Genetic Opera")
internal val SmartChannels = listOf(
ChannelProgramming(AFTER_DARK_NUMBER, "After Dark", AfterDarkFilms, seriesCount = AfterDarkFilms.size, filmRestMs = 7 * 24 * 60 * 60_000L,
ChannelProgramming(AFTER_DARK_NUMBER, "After Dark", AfterDarkFilms, seriesCount = AfterDarkFilms.size, filmSeries = listOf(LAST_DRIVE_IN), filmRestMs = 7 * 24 * 60 * 60_000L,
dayParts = AfterDarkEvents + listOf(DayPart(21, 5), DayPart(5, 21, listOf("The 'Burbs", "'Til Death Do Us Part (2017)", "Tremors (1990)", "The Lost Boys (1987)", "Fright Night (1985)", "Poltergeist (1982)", "Scream (1996)",
"Escape from New York", "They Live", "Repo Man", "Donnie Darko", "From Dusk Till Dawn", "Creepshow", "Near Dark", "Halloween (1978)", "The Fog (1980)", "Blue Velvet",
"The Wicker Man (1973)", "An American Werewolf in London", "Prince of Darkness"), group = "day")),
@@ -235,9 +237,23 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
val entries = mutableListOf<ScheduleEntry>()
var last = cursor.lastSeriesId
var start = fromMs
val marks = cursor.marks.toMutableMap()
while (start < untilMs) {
val (available, block) = dayPartChoice(pool, dayParts, start, zone)
val (film, why) = chooseFilm(available, shown, start, restMs, avoid)
// An event naming only a series plays its next whole episode, once a night. Everywhere else is films only.
val series = available.singleOrNull()?.takeIf { !it.isFilm && block.startsWith("event ") }
if (series != null && shown[series.id]?.let { start - it < SERIES_NIGHT_MS } != true) {
val episode = nextEpisode(series, marks[series.id])
entries += ScheduleEntry(series.id, episode.mark, ScheduledMedia(scheduledItem(series.title, episode), episode.sourceId, episode.durationMs), start,
"$block; next episode in order, played whole")
marks[series.id] = episode.mark
shown[series.id] = start
last = series.id
start += episode.durationMs
continue
}
val films = available.filter { it.isFilm }.ifEmpty { pool.filter { it.isFilm } }.ifEmpty { available }
val (film, why) = chooseFilm(films, shown, start, restMs, avoid)
val copy = film.episodes.first()
val item = SampleItem(film.title, "Movie", copy.durationMs / 60_000, "", copy.id, copy.durationMs)
entries += ScheduleEntry(film.id, copy.mark, ScheduledMedia(item, copy.sourceId, copy.durationMs), start, "$block; $why")
@@ -245,9 +261,12 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
last = film.id
start += copy.durationMs
}
return ChannelPlan(entries, ScheduleCursor(last, cursor.marks, shown))
return ChannelPlan(entries, ScheduleCursor(last, marks, shown))
}
/** 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
/** 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,
@@ -77,7 +77,7 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
* A failed refresh keeps what's there, so a provider outage can't disturb what's committed.
*/
fun topUp(session: EmbySampleSession, userId: String, programming: ChannelProgramming, loop: SampleChannel, checkActive: () -> Unit = {}): SchedulerReport {
SeriesInspection.take()?.let { title -> runCatching { session.inspectSeries(title) }.getOrElse { listOf("inspect failed: ${it.javaClass.simpleName}") }.forEach { Log.i("OrbitSchedule", it) } }
SeriesInspection.take()?.let { title -> runCatching { session.inspectSeries(title) }.getOrElse { listOf("inspect failed: ${it.javaClass.simpleName} ${(it as? EmbyCheckException)?.httpStatus} ${it.message?.take(160)}") }.forEach { Log.i("OrbitSchedule", it) } }
val number = programming.number
val now = clock()
val cached = store.loadPool(userId, number)
@@ -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.91.1\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.92.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -195,7 +195,7 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
val match = searchSeries(transport, userId, ::currentToken, title).candidates.filter { seriesKey(it.title) == seriesKey(title) }
if (match.isEmpty()) return listOf("inspect \"$title\": no series of that name")
return match.flatMap { series ->
val reply = transport.execute(EmbyRequest("GET", "/Shows/${series.id}/Episodes?UserId=$userId&StartIndex=0&Limit=200&Fields=MediaSources,Chapters&EnableImages=false&EnableUserData=false",
val reply = transport.execute(EmbyRequest("GET", "/Shows/${series.id}/Episodes?UserId=$userId&StartIndex=0&Limit=100&Fields=MediaSources,Chapters&EnableImages=false&EnableUserData=false",
token = currentToken(), readTimeoutMs = WHOLE_SERIES_TIMEOUT_MS))
EmbyClient.expectSuccess(reply.status, false)
val body = EmbyClient.parse(reply.body)
@@ -231,6 +231,16 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
val film = lookup.film ?: continue
if (pool.none { it.id == film.id }) { pool += film; found++ }
}
// A series this film channel carries in an event: read whole, like a series channel, kept as one series rather than as films.
for (title in programming.filmSeries) {
checkActive()
requests++
val match = searchSeries(transport, userId, ::currentToken, title).candidates.filter { seriesKey(it.title) == seriesKey(title) }.take(MAX_SERIES_COPIES)
val read = match.map { copy -> readWholeSeries(transport, userId, ::currentToken, copy, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio) }
val best = read.maxByOrNull { it.episodes.size }?.takeIf { it.episodes.isNotEmpty() }
android.util.Log.i("OrbitSchedule", "channel=${programming.number} series=\"$title\" copies=${match.size} episodes=${best?.episodes?.size ?: 0}")
if (best != null) pool += best
}
} else for (search in programming.searches) {
if (pool.size == programming.seriesCount) break
checkActive()
@@ -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.91.1")
next.setRequestProperty("User-Agent", "OrbitTV/0.92.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()) {
@@ -0,0 +1,68 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
import java.time.ZoneId
import java.time.ZonedDateTime
/** After Dark carrying The Last Drive-In: one whole hosted episode each Saturday night, in order, and never as a film. */
class LastDriveInTest {
private val zone = ZoneId.of("Europe/London")
private val minute = 60_000L
private val week = 7 * 24 * 60 * minute
private val monday = ZonedDateTime.of(2026, 11, 9, 0, 0, 0, 0, zone).toInstant().toEpochMilli()
private val after = SmartChannels.first { it.number == AFTER_DARK_NUMBER }
private fun film(i: Int, minutes: Long = 95) = PoolSeries("film$i", "Film $i", listOf(PoolEpisode("film$i", "src$i", EpisodeMark(1, 1), "Film $i", minutes * minute)))
private val films = (1..60).map { film(it, 85L + it % 40) }
private val joeBob = PoolSeries("joebob", LAST_DRIVE_IN, (1..13).map { PoolEpisode("jb$it", "jbsrc$it", EpisodeMark(1, it), "Episode $it", (120L + it * 4) * minute) })
private fun plan(pool: List<PoolSeries>, cursor: ScheduleCursor = ScheduleCursor(), from: Long = monday, until: Long = monday + 3 * week) =
extendSchedule(pool, cursor, from, until, after.filmRestMs, dayParts = after.dayParts, zone = zone)
private fun local(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(zone)
@Test fun oneWholeEpisodeEachSaturdayInOrder() {
val episodes = plan(films + joeBob).entries.filter { it.seriesId == "joebob" }
assertEquals(listOf(1, 2, 3), episodes.map { it.mark.episode })
episodes.forEach { e ->
val start = local(e.startMs)
assertEquals(java.time.DayOfWeek.SATURDAY, start.dayOfWeek)
assertTrue("starts in the first slot after 20:00, so around 21:00: $start", start.hour in 20..21)
assertEquals("played whole", joeBob.episodes[e.mark.episode - 1].durationMs, e.media.durationMs)
}
}
@Test fun neverInTheOrdinaryFilmRotationAndNeverCountedAsAFilmScreening() {
val result = plan(films + joeBob)
val outside = result.entries.filter { it.seriesId == "joebob" && local(it.startMs).dayOfWeek != java.time.DayOfWeek.SATURDAY }
assertTrue(outside.isEmpty())
assertTrue(result.entries.filter { it.seriesId == "joebob" }.all { it.media.item.type == "Episode" })
}
@Test fun theNextWeekCarriesOnAfterARestart() {
val first = plan(films + joeBob, until = monday + week)
val store = ScheduleStore(kotlin.io.path.createTempDirectory().toFile())
store.savePlan("u", AFTER_DARK_NUMBER, first)
val restored = store.loadPlan("u", AFTER_DARK_NUMBER)!!
val next = plan(films + joeBob, restored.tail, from = first.endMs, until = first.endMs + week)
assertEquals(listOf(2), next.entries.filter { it.seriesId == "joebob" }.map { it.mark.episode })
}
@Test fun withoutTheSeriesSaturdayNightIsFilmsWithNoGap() {
val result = plan(films)
assertTrue(result.entries.zipWithNext().all { (a, b) -> a.endMs == b.startMs })
assertTrue(result.entries.all { it.media.item.type == "Movie" })
}
@Test fun aFilmRunningPastNineStillLeadsIntoTheEpisode() {
// A long film before the window: the episode starts when it ends, still on Saturday night.
val long = PoolSeries("long", "Long Film", listOf(PoolEpisode("long", "srclong", EpisodeMark(1, 1), "Long Film", 200 * minute)))
val saturdayEvening = ZonedDateTime.of(2026, 11, 14, 19, 30, 0, 0, zone).toInstant().toEpochMilli()
val result = extendSchedule(listOf(long) + joeBob, ScheduleCursor(), saturdayEvening, saturdayEvening + 12 * 60 * minute, after.filmRestMs, dayParts = after.dayParts, zone = zone)
val episode = result.entries.first { it.seriesId == "joebob" }
assertEquals(result.entries.first().endMs, episode.startMs)
assertEquals(1, result.entries.count { it.seriesId == "joebob" })
}
@Test fun onlyAfterDarkCarriesASeries() {
assertEquals(listOf(AFTER_DARK_NUMBER), SmartChannels.filter { it.filmSeries.isNotEmpty() }.map { it.number })
}
}
+24
View File
@@ -0,0 +1,24 @@
# Orbit TV 0.92.0: Joe Bob Saturdays
A separate, opt-in engine change: a film channel can carry a named series in an event. Only After Dark uses it, for The Last Drive-In with Joe Bob Briggs.
## What Emby holds (read-only inspection with 0.91.2, 3 November 2026)
- One series, 228 episodes (the first 100 read in detail). Every hosted episode is a single playable file (one media source, mkv or mp4), 94 to 183 minutes, median 137, named after its featured film, with about one chapter every five minutes. A film runs about 85 to 110 minutes, so each file carries the film and Joe Bob's segments together.
- Specials sit in season 0 (some aren't hosted episodes, such as Walking Dead promotions). The series reader already leaves season 0 out.
## What changed
- ChannelProgramming.filmSeries: series a film channel may carry. Empty for every channel but After Dark. It's part of the pool signature, so After Dark reads it once.
- The series is read whole with the existing series reader (fullest copy of up to four, playable files only) and held as one series, not as films.
- After Dark's Saturday event (20:00 to 01:00) names only the series. The planner plays its next episode in order, whole, once a night (12-hour guard). Everywhere else After Dark chooses films only. The episode isn't counted as a film screening and its featured film isn't touched.
- The window opens at 20:00 because the film before it is usually still running; the first slot after 20:00 lands it around 21:00.
- The episode's place is saved in the channel's cursor and survives restarts.
- If the series can't be read or played, the event has nothing to show and After Dark's usual late films carry on with no gap.
## Tests and replay
- New LastDriveInTest: one whole episode each Saturday in order, never outside its event, never as a film, continues after a restart, no gap without the series, starts straight after a long film that runs past the hour, and only After Dark opts in. All 352 tests pass, including the unchanged plan fingerprints, so every other channel plans exactly as before. Lint passed.
- Six-week replay from the box's real files with the real episode runtimes: committed plans unchanged, no gaps. Episodes 1 to 5 aired one a Saturday, starting between 20:13 and 21:18 and running their full 109 to 131 minutes; films followed each one. After Dark's existing rest-period shortfall is unchanged.
## Rollback
Remove the series from After Dark's filmSeries; the next top-up plans films again. Nothing else depends on it.
Not installed.
+2
View File
@@ -9,3 +9,5 @@ Softer cult films by day, harder ones from 21:00. Corrected: Halloween (1978), F
**Rest period:** films rest 7 days between showings. In a four-week replay, this channel cannot always keep it, because its list runs out of films before the week does, so the film that has waited longest returns early; see VERIFICATION-0.90.0.md.
**Built in 0.91.0:** B-Movie Throwbacks, Friday 21:00 to 01:00 (27 films), and Cult Classics, Sunday 21:00 to 01:00 (26 films), each a preferred window whose last film runs to its natural end. 39 films are new to After Dark's list, which it now reads in full. In a four-week replay each night had 2 or 3 films with no fallbacks, but some favourites came back weekly (Big Trouble in Little China on three of four Sundays), because After Dark's everyday rotation already runs short of rested films; that belongs to the rest-period investigation. The Last Drive-In waits for its own engine change.
**Joe Bob Saturdays** (0.92.0): The Last Drive-In with Joe Bob Briggs, one whole hosted episode each Saturday, in order, from the first slot after 20:00 so it lands around 21:00, running its full length (about 2 to 3 hours). Each episode is one file in Emby with the film and Joe Bob's segments together; season 0 specials are left out. It never appears in the ordinary film rotation, and if it's unavailable Saturday stays films with no gap.