Orbit TV Times: the Sunday edition (0.110.4)

Each week's issue is made the first time it's opened from Sunday on, numbered (issue 1 = week of 8 November 2026) and
kept for the week, so it reads like a printed magazine; it opens at today's page. One edition per profile, and a
separate one while the After Dark lock is on. Saved safely beside the schedules; the last five weeks are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 14:39:48 +00:00
co-authored by Claude Opus 5.5
parent a151db4d64
commit 0d3a9714d4
7 changed files with 63 additions and 8 deletions
@@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
}
/** The sign-in headers for this kind of server. */
internal fun authHeaders(token: String?): Map<String, String> = when (kind) {
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.3\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.4\"") +
(token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap())
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.3\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.4\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -164,6 +164,8 @@ internal object OrbitCompanion {
const val QUEUE_MAX = 5
const val TIMES_DAYS = 7
const val TIMES_EDITION_V = 1
const val TIMES_KEEP_WEEKS = 5L
const val TIMES_FILMS = 12
/** How long before the programme's end the queue takes over. */
const val QUEUE_LEAD_MS = 2_500L
@@ -224,6 +226,25 @@ internal object OrbitCompanion {
})
}
/**
* The Sunday edition (Paul, 8 November 2026): each week's Orbit TV Times is made once, the first time it's opened from
* Sunday on, numbered, and kept for the week, so it reads like a printed magazine rather than changing under you. One
* edition per profile, and a separate one while the After Dark lock is on, so a locked TV never shows a listing an
* unlocked one saved. Live listings stay in the guide. The last five weeks are kept.
*/
fun timesEdition(screen: CompanionScreen, dir: java.io.File?, nowMs: Long, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): JSONObject {
val sunday = timesSunday(whatsOnEdition(nowMs, zone))
val who = (Profiles.current?.id ?: "all").filter { it.isLetterOrDigit() }.take(20).ifEmpty { "all" } + if (AfterDarkLock.locked) "-locked" else ""
val file = dir?.let { java.io.File(it, "times-$sunday-$who.json") }
file?.takeIf { it.isFile }?.let { f -> runCatching { JSONObject(f.readText()) }.getOrNull()?.takeIf { it.optInt("v") == TIMES_EDITION_V } }?.let { return it }
val fresh = times(screen, nowMs, zone).put("v", TIMES_EDITION_V).put("issue", timesIssue(sunday)).put("weekOf", sunday.toString())
if (file != null && fresh.getJSONArray("days").length() > 0) runCatching {
writeSafely(file, fresh.toString())
dir.listFiles { f -> f.name.startsWith("times-") && f.name.endsWith(".json") }?.filter { it.name.substring(6, 16) < sunday.minusWeeks(TIMES_KEEP_WEEKS).toString() }?.forEach { it.delete() }
}
return fresh
}
/**
* Orbit TV Times (Paul, 8 November 2026): the week ahead as a listings magazine, from the real schedules. Each day is
* What's On's choice for that evening (its pick and highlights), the evening's films across the channels, and the
@@ -331,3 +352,9 @@ internal object TimesBlurbs {
return ids.mapNotNull { id -> cache[id]?.let { id to it } }.toMap()
}
}
/** The Sunday an edition belongs to: the Sunday on or before [day]. */
internal fun timesSunday(day: java.time.LocalDate): java.time.LocalDate = day.minusDays((day.dayOfWeek.value % 7).toLong())
/** Issue 1 is the week of Sunday 8 November 2026, when Orbit TV Times began. */
internal fun timesIssue(sunday: java.time.LocalDate): Long = java.time.temporal.ChronoUnit.WEEKS.between(java.time.LocalDate.of(2026, 11, 8), sunday) + 1
@@ -537,7 +537,7 @@ internal object PhoneLink {
val number = body().optInt("number").takeIf { n -> s.channels().any { it.number == n } } ?: return json(out, 404, JSONObject().put("error", "That channel isn't on this TV right now."))
onScreen { s.tune(number, 0) }; json(out, 200, JSONObject().put("number", number))
}
"GET /api/times" -> json(out, 200, OrbitCompanion.times(s, now))
"GET /api/times" -> json(out, 200, OrbitCompanion.timesEdition(s, appContext?.let { runCatching { Workspaces.current(it).scheduleDir }.getOrNull() }, now))
"POST /api/remind" -> {
val o = body(); var done = false
onScreen { done = OrbitCompanion.remind(s, o.optInt("number"), o.optLong("startMs"), o.optBoolean("on", true), now) }
@@ -39,7 +39,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.110.3")
next.setRequestProperty("User-Agent", "OrbitTV/0.110.4")
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()) {