Orbit TV Times: every TV starts at Issue 1 (0.110.5)

Issues count from each TV's own first edition (kept in times-first; for a TV with editions already, the oldest one),
so a household starting later begins at Issue 1. The page says 'Week of' the edition's first day, so a first edition
made mid-week reads right. Existing editions keep their numbers (these TVs stay on Issue 1 this week).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 14:57:58 +00:00
co-authored by Claude Opus 5.5
parent 0d3a9714d4
commit 84b28b6f34
6 changed files with 38 additions and 11 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.4\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.5\"") +
(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.4\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.5\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -237,7 +237,9 @@ internal object OrbitCompanion {
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())
// Issues count from this TV's own first edition (8 November 2026), so every household starts at Issue 1.
val firstSunday = dir?.let { timesFirstSunday(it, sunday) } ?: sunday
val fresh = times(screen, nowMs, zone).put("v", TIMES_EDITION_V).put("issue", timesIssue(sunday, firstSunday)).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() }
@@ -356,5 +358,20 @@ internal object TimesBlurbs {
/** 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
/** The issue for the week of [sunday], counting this TV's first edition (the week of [firstSunday]) as Issue 1. */
internal fun timesIssue(sunday: java.time.LocalDate, firstSunday: java.time.LocalDate): Long =
maxOf(0L, java.time.temporal.ChronoUnit.WEEKS.between(firstSunday, sunday)) + 1
/**
* The Sunday of this TV's first edition, kept in times-first; set the first time an edition is made (or, for a TV that
* already had editions before this was kept, the oldest one still there).
*/
internal fun timesFirstSunday(dir: java.io.File, sunday: java.time.LocalDate): java.time.LocalDate {
val marker = java.io.File(dir, "times-first")
runCatching { java.time.LocalDate.parse(marker.readText().trim()) }.getOrNull()?.let { return it }
val oldest = dir.listFiles { f -> Regex("times-\\d{4}-\\d{2}-\\d{2}-.+\\.json").matches(f.name) }.orEmpty()
.mapNotNull { runCatching { java.time.LocalDate.parse(it.name.substring(6, 16)) }.getOrNull() }.minOrNull()
val first = listOfNotNull(oldest, sunday).min()
runCatching { writeSafely(marker, first.toString()) }
return first
}
@@ -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.4")
next.setRequestProperty("User-Agent", "OrbitTV/0.110.5")
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()) {