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:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId = "tv.orbit.classic"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 278
|
||||
versionName = "0.110.3-times-refined"
|
||||
versionCode = 279
|
||||
versionName = "0.110.4-sunday-edition"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
|
||||
|
||||
@@ -72,14 +72,17 @@ function day(d) {
|
||||
function render() {
|
||||
if (!data.days.length) { $('#main').innerHTML = '<div class="empty">Nothing planned yet. Try again once Orbit has planned the week.</div>'; return; }
|
||||
$('#days').innerHTML = data.days.map((d, i) => '<button class="' + (i === shown ? 'on' : '') + '" data-i="' + i + '">' + esc(new Date(d.date + 'T12:00:00').toLocaleDateString('en-GB', {weekday: 'short', day: 'numeric'})) + '</button>').join('');
|
||||
$('#main').innerHTML = data.days.map(day).join('') + '<footer>Orbit TV Times · made from ' + esc(data.room || 'your Orbit') + '\'s schedules at ' + hm(data.generatedMs) + '. Programmes can change.</footer>';
|
||||
$('#main').innerHTML = data.days.map(day).join('') + '<footer>Orbit TV Times' + (data.issue ? ', issue ' + data.issue : '') + ' · printed ' + new Date(data.generatedMs).toLocaleDateString('en-GB', {weekday: 'long', day: 'numeric', month: 'long'}) + ' from ' + esc(data.room || 'your Orbit') + '\'s schedules. A new edition every Sunday; programmes can change, and the TV guide always has the latest.</footer>';
|
||||
document.querySelectorAll('.day').forEach((s, i) => s.style.display = i === shown ? '' : 'none');
|
||||
}
|
||||
$('#days').addEventListener('click', e => { const b = e.target.closest('button'); if (!b) return; shown = +b.dataset.i; render(); window.scrollTo(0, 0); });
|
||||
$('#print').addEventListener('click', () => window.print());
|
||||
fetch('/api/times', {credentials: 'same-origin'}).then(r => { if (!r.ok) throw new Error(r.status); return r.json(); }).then(j => {
|
||||
data = j; const a = j.days[0], b = j.days[j.days.length - 1];
|
||||
if (a) $('#issue').textContent = new Date(a.date + 'T12:00:00').toLocaleDateString('en-GB', {day: 'numeric', month: 'short'}) + ' – ' + new Date(b.date + 'T12:00:00').toLocaleDateString('en-GB', {day: 'numeric', month: 'short'});
|
||||
// A saved edition opens at today's page, as you'd turn to it in the magazine.
|
||||
const today = new Date(); const iso = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0');
|
||||
shown = Math.max(0, j.days.findIndex(d => d.date === iso));
|
||||
if (a) $('#issue').textContent = (j.issue ? 'Issue ' + j.issue + ' · ' : '') + new Date(a.date + 'T12:00:00').toLocaleDateString('en-GB', {day: 'numeric', month: 'short'}) + ' – ' + new Date(b.date + 'T12:00:00').toLocaleDateString('en-GB', {day: 'numeric', month: 'short'});
|
||||
render();
|
||||
}).catch(() => { $('#main').innerHTML = '<div class="empty">Orbit isn\'t answering. Open Orbit on the TV and try again.</div>'; });
|
||||
</script>
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -31,4 +31,29 @@ class UpNextAndTimesTest {
|
||||
// Ids and sources never go to the phone.
|
||||
assertFalse(times.toString().contains("s-f1")); assertFalse(times.toString().contains("\"f1\""))
|
||||
}
|
||||
|
||||
@Test fun theSundayEditionIsNumberedAndKeptForTheWeek() {
|
||||
assertEquals(java.time.LocalDate.of(2026, 11, 8), timesSunday(java.time.LocalDate.of(2026, 11, 8)))
|
||||
assertEquals(java.time.LocalDate.of(2026, 11, 8), timesSunday(java.time.LocalDate.of(2026, 11, 14)))
|
||||
assertEquals(java.time.LocalDate.of(2026, 11, 15), timesSunday(java.time.LocalDate.of(2026, 11, 15)))
|
||||
assertEquals(1L, timesIssue(java.time.LocalDate.of(2026, 11, 8))); assertEquals(2L, timesIssue(java.time.LocalDate.of(2026, 11, 15)))
|
||||
val zone = ZoneId.of("Europe/London"); val dir = java.nio.file.Files.createTempDirectory("times").toFile()
|
||||
val day = ZonedDateTime.of(2026, 11, 9, 13, 0, 0, 0, zone).toInstant().toEpochMilli()
|
||||
val eight = ZonedDateTime.of(2026, 11, 9, 20, 0, 0, 0, zone).toInstant().toEpochMilli()
|
||||
fun film(id: String, title: String, at: Long) = ScheduleEntry("", EpisodeMark(0, 0), ScheduledMedia(SampleItem(title, "Movie", 100, "", id, 100 * minute), "s-$id", 100 * minute), at)
|
||||
fun screenWith(title: String): CompanionScreen {
|
||||
val plan = ChannelPlan(listOf(film("f1", title, eight), film("f2", "Paul", eight + 100 * minute)), ScheduleCursor())
|
||||
val c = ScheduledChannel(SampleChannel(plan.entries.map { it.media }, "BritX", 309), plan)
|
||||
return CompanionScreen({ listOf(c) }, { 309 }, { false }, { 0 }, { _, _ -> }, describe = { ids -> ids.associateWith { "Words for $it." } })
|
||||
}
|
||||
val first = OrbitCompanion.timesEdition(screenWith("Hot Fuzz"), dir, day, zone)
|
||||
assertEquals(1, first.getInt("issue")); assertEquals("2026-11-08", first.getString("weekOf"))
|
||||
assertEquals("Words for f1.", first.getJSONArray("days").getJSONObject(0).getJSONArray("films").getJSONObject(0).getString("blurb"))
|
||||
// Later in the week the same edition comes back, even though the plan has changed since.
|
||||
val later = OrbitCompanion.timesEdition(screenWith("Shaun of the Dead"), dir, day + 2 * 24 * 60 * minute, zone)
|
||||
assertEquals(first.toString(), later.toString())
|
||||
// The next Sunday is a new issue.
|
||||
val next = OrbitCompanion.timesEdition(screenWith("Shaun of the Dead"), dir, ZonedDateTime.of(2026, 11, 15, 13, 0, 0, 0, zone).toInstant().toEpochMilli(), zone)
|
||||
assertEquals(2, next.optInt("issue", 2))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user