diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index f7a4ee40..d35f230e 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 277 - versionName = "0.110.2-phone-remembered" + versionCode = 278 + versionName = "0.110.3-times-refined" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/assets/phone/times.html b/android/app/src/main/assets/phone/times.html index e139ce7f..80144ec6 100644 --- a/android/app/src/main/assets/phone/times.html +++ b/android/app/src/main/assets/phone/times.html @@ -15,15 +15,16 @@ body{margin:0;background:var(--paper);color:var(--ink);font-family:Georgia,'Time main{max-width:980px;margin:0 auto;padding:12px 14px 40px} .day h2{font-size:30px;margin:14px 0 4px;border-bottom:3px solid var(--red);padding-bottom:4px} .day h2 small{font:600 14px system-ui,sans-serif;color:var(--muted);margin-left:8px} -.pick{display:grid;grid-template-columns:auto 1fr;gap:12px;background:var(--navy);color:#fff;border-radius:6px;padding:14px;margin:12px 0} +.pick{display:grid;grid-template-columns:auto 1fr;gap:12px;line-height:1.45;background:var(--navy);color:#fff;border-radius:6px;padding:14px;margin:12px 0} .pick .badge{background:var(--gold);color:var(--navy);font:900 13px/1 system-ui,sans-serif;padding:8px 10px;border-radius:4px;align-self:start;letter-spacing:1px} .pick h3{margin:0;font-size:24px;color:var(--gold)} .pick p{margin:4px 0 0} .sec{font:900 14px system-ui,sans-serif;letter-spacing:2px;color:var(--red);margin:18px 0 6px;text-transform:uppercase} -.cols{columns:2 300px;column-gap:24px;column-rule:1px solid var(--rule)} -.row{break-inside:avoid;padding:6px 0;border-bottom:1px dotted var(--rule)} +.cols{columns:2 320px;column-gap:20px} +.row{break-inside:avoid;background:#fff;border:1px solid var(--rule);border-left:4px solid var(--red);border-radius:6px;padding:10px 12px;margin:0 0 10px} +.blurb{margin:5px 0 4px;font-size:15px;line-height:1.4} .t{font:700 15px system-ui,sans-serif;color:var(--red);margin-right:6px} -.title{font-weight:700;font-size:17px} +.title{font-weight:700;font-size:18px;line-height:1.25} .sub{font-style:italic;color:var(--muted)} .meta{font:600 12px system-ui,sans-serif;color:var(--muted)} .tag{display:inline-block;font:800 10px system-ui,sans-serif;letter-spacing:1px;background:var(--gold);color:var(--navy);padding:2px 5px;border-radius:3px;margin-left:4px;vertical-align:2px} @@ -41,7 +42,7 @@ footer{font:12px system-ui,sans-serif;color:var(--muted);text-align:center;margi } -
ORBIT TV Times THE WEEK'S PROGRAMMES · EVERY CHANNEL FREE WITH YOUR ORBIT PICKS · FILMS · DRIVE-IN
+
ORBIT TV Times THE WEEK'S PROGRAMMES · EVERY CHANNEL FREE WITH YOUR ORBIT PICKS · FILMS · DRIVE-IN
‹ Back to Orbit
Loading this week's listings…
@@ -52,13 +53,16 @@ const hm = ms => new Date(ms).toLocaleTimeString('en-GB', {hour: '2-digit', minu const dayName = iso => new Date(iso + 'T12:00:00').toLocaleDateString('en-GB', {weekday: 'long', day: 'numeric', month: 'long'}); let data = null, shown = 0; function row(i) { - return '
' + hm(i.startMs) + '' + esc(i.title) + '' + (i.tag ? '' + esc(i.tag).toUpperCase() + '' : '') + - (i.sub ? '
' + esc(i.sub) + '
' : '') + '
' + i.channel + ' ' + esc(i.name) + ' · until ' + hm(i.endMs) + (i.reason ? ' · ' + esc(i.reason) : '') + '
'; + // Programme first, then the library's own words for it, then where and when (Paul, 8 November 2026: more editorial, more room). + return '
' + hm(i.startMs) + '' + (i.tag ? '' + esc(i.tag).toUpperCase() + '' : '') + '
' + + '
' + esc(i.title) + '
' + (i.sub ? '
' + esc(i.sub) + '
' : '') + + (i.blurb ? '

' + esc(i.blurb) + '

' : '') + + '
' + i.channel + ' ' + esc(i.name) + ' · until ' + hm(i.endMs) + '
'; } function day(d) { let h = '

' + esc(dayName(d.date)) + '

'; if (d.pick) h += '
PICK OF
THE DAY

' + esc(d.pick.title) + '

' + (d.pick.sub ? '' + esc(d.pick.sub) + '
' : '') + - hm(d.pick.startMs) + ' on ' + d.pick.channel + ' ' + esc(d.pick.name) + (d.pick.reason ? ' · ' + esc(d.pick.reason) : '') + '

'; + (d.pick.blurb ? esc(d.pick.blurb) + '
' : '') + '' + hm(d.pick.startMs) + ' on ' + d.pick.channel + ' ' + esc(d.pick.name) + '' + '

'; if (d.highlights.length) h += '
Tonight\'s highlights
' + d.highlights.map(row).join('') + '
'; if (d.films.length) h += '
Films this evening
' + d.films.map(row).join('') + '
'; if (d.drivein.length) h += '
At the Drive-In
' + d.drivein.map(b => '
' + esc(b.event || b.kind) + ' · ' + hm(b.startMs) + '–' + hm(b.endMs) + diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index 89f4ebff..2c0b6004 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -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 = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.2\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.3\"") + (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.2\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.3\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index 942c4208..ecbfdc79 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -748,7 +748,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea decision == "deferred" -> "${idea.theme} deferred: it can come back in four weeks." else -> "${idea.theme} dismissed: it won't be proposed again unless its films change." } }, - reminders = { companionReminders }, remind = { number, startMs, title, on -> companionRemind(number, startMs, title, on) }) + reminders = { companionReminders }, remind = { number, startMs, title, on -> companionRemind(number, startMs, title, on) }, + describe = { ids -> TimesBlurbs.get(session, ids) }) } DisposableEffect(Unit) { PhoneLink.screen = companionScreen diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt index 06734805..d5bef77c 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt @@ -267,6 +267,22 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v return films.associate { (film, person) -> film.itemId to checkEventFilm(film, byId[film.itemId], person, BoxDecoders::canDecode) } } + /** Orbit TV Times' short descriptions for [ids], read only, in one request: see [timesBlurb]. */ + fun readBlurbs(ids: List): Map { + val valid = ids.filter(EmbyClient::validId).distinct().take(60) + if (valid.isEmpty()) return emptyMap() + val reply = transport.execute(EmbyRequest("GET", "/Items?UserId=$userId&Ids=${valid.joinToString(",")}&Fields=Overview,Taglines,People" + + "&EnableImages=false&EnableUserData=false", token = currentToken(), readTimeoutMs = WHOLE_SERIES_TIMEOUT_MS)) + EmbyClient.expectSuccess(reply.status, false) + val rows = EmbyClient.parse(reply.body).optJSONArray("Items") + return (0 until (rows?.length() ?: 0)).mapNotNull { rows!!.optJSONObject(it) }.mapNotNull { row -> + val id = row.optString("Id").takeIf(EmbyClient::validId) ?: return@mapNotNull null + val leads = row.optJSONArray("People")?.let { a -> (0 until a.length()).mapNotNull { a.optJSONObject(it) } }.orEmpty() + .filter { it.optString("Type") == "Actor" }.take(2).map { EmbyClient.clean(it.optString("Name"), 50) }.filter { it.isNotBlank() } + timesBlurb(row.optJSONArray("Taglines")?.optString(0), row.optString("Overview"), leads, row.optString("Type"))?.let { id to it } + }.toMap() + } + /** Stage D evidence for [ids], read only, in one request: see [evidenceLine]. */ fun readEvidence(ids: List): List { val valid = ids.filter(EmbyClient::validId) @@ -514,3 +530,22 @@ internal object EmbyCleanup { private val executor = java.util.concurrent.Executors.newSingleThreadExecutor { task -> Thread(task, "Orbit-session-cleanup").apply { isDaemon = true } } fun run(task: () -> Unit) { executor.execute { try { task() } catch (_: Exception) { } } } } + + +/** + * A listings line for Orbit TV Times (Paul, 8 November 2026: "make the descriptions more editorial"), from the library's own + * words: the film's tagline when it has a short one, otherwise the first sentence of its synopsis, with its two leads for a + * film. Never longer than about two lines on a phone. + */ +internal fun timesBlurb(tagline: String?, overview: String?, leads: List, type: String): String? { + fun tidy(s: String?) = s?.filter { !it.isISOControl() }?.replace(Regex("\\s+"), " ")?.trim().orEmpty() + val tag = tidy(tagline).takeIf { it.length in 8..TIMES_BLURB_MAX } + val first = tidy(overview).let { o -> Regex("^(.{20,}?[.!?])(\\s|$)").find(o)?.groupValues?.get(1) ?: o }.let { s -> + if (s.length <= TIMES_BLURB_MAX) s else s.take(TIMES_BLURB_MAX).substringBeforeLast(' ').trimEnd(',', ';', ':') + "…" + }.takeIf { it.isNotBlank() } + val line = tag ?: first ?: return leads.takeIf { type == "Movie" && it.isNotEmpty() }?.let { "Starring ${it.joinToString(" and ")}." } + val star = if (type == "Movie" && leads.isNotEmpty() && leads.none { line.contains(it) }) " With ${leads.joinToString(" and ")}." else "" + return line + star +} + +internal const val TIMES_BLURB_MAX = 150 diff --git a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt index f4fa0a5c..45f7e9f2 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt @@ -48,7 +48,9 @@ internal class CompanionScreen( val decideIdea: (DeskEventIdea, String) -> String = { _, _ -> "" }, /** Programme reminders, the same ones the TV guide and What's On set (8 November 2026). */ val reminders: () -> List = { emptyList() }, - val remind: (number: Int, startMs: Long, title: String, on: Boolean) -> Unit = { _, _, _, _ -> }) + val remind: (number: Int, startMs: Long, title: String, on: Boolean) -> Unit = { _, _, _, _ -> }, + /** Short descriptions for Orbit TV Times, by item id, from the library (cached); empty when the library can't be reached. */ + val describe: (List) -> Map = { emptyMap() }) /** * Phase 2's queue (Paul, 6 November 2026): what plays when the programme on now ends. A channel, live from then ("switch @@ -231,10 +233,11 @@ internal object OrbitCompanion { val channels = screen.channels() val plans = channels.mapNotNull { c -> (c as? ScheduledChannel)?.let { c.number to it.plan } }.toMap() val names = channels.associate { it.number to ChannelBrands.displayName(it) } + val blurbs = HashMap() fun item(channel: Int, e: ScheduleEntry, tag: String?, reason: String?) = guideTitleParts(e.media.item.title).let { (title, sub) -> JSONObject().put("channel", channel).put("name", names[channel] ?: channel.toString()).put("title", title).put("sub", sub ?: JSONObject.NULL) .put("startMs", e.startMs).put("endMs", e.endMs).put("type", e.media.item.type) - .put("tag", tag ?: JSONObject.NULL).put("reason", reason ?: JSONObject.NULL) + .put("tag", tag ?: JSONObject.NULL).put("reason", reason ?: JSONObject.NULL).put("blurb", blurbs[e.media.item.id] ?: JSONObject.NULL) } val first = whatsOnEdition(nowMs, zone) val days = JSONArray() @@ -248,6 +251,8 @@ internal object OrbitCompanion { .sortedBy { it.second.startMs }.distinctBy { it.second.media.item.id }.take(TIMES_FILMS) val bills = screen.driveIn().filter { it.startMs in noon until end } if (page.pick == null && page.tonight.isEmpty() && films.isEmpty() && bills.isEmpty()) continue + val wanted = (listOfNotNull(page.pick) + page.tonight).map { it.entry.media.item.id } + films.map { it.second.media.item.id } + wanted.filter { it !in blurbs }.takeIf { it.isNotEmpty() }?.let { ids -> runCatching { blurbs.putAll(screen.describe(ids)) } } days.put(JSONObject().put("date", date.toString()).put("noonMs", noon) .put("pick", page.pick?.let { item(it.channel, it.entry, it.tag, it.reason) } ?: JSONObject.NULL) .put("highlights", JSONArray(page.tonight.map { item(it.channel, it.entry, it.tag, it.reason) })) @@ -316,3 +321,13 @@ internal object OrbitCompanion { } @Synchronized fun stopLooking() { finder?.stop(); finder = null } } + +/** Orbit TV Times' descriptions, kept while Orbit is open so each edition asks the library only for what's new. */ +internal object TimesBlurbs { + private val cache = object : LinkedHashMap(256, .75f, true) { override fun removeEldestEntry(e: MutableMap.MutableEntry?) = size > 600 } + @Synchronized fun get(session: EmbySampleSession?, ids: List): Map { + val missing = ids.filter { it !in cache }.distinct() + if (session != null && missing.isNotEmpty()) runCatching { missing.chunked(60).forEach { cache.putAll(session.readBlurbs(it)) } } + return ids.mapNotNull { id -> cache[id]?.let { id to it } }.toMap() + } +} diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index 90d788e9..e0391b00 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -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.2") + next.setRequestProperty("User-Agent", "OrbitTV/0.110.3") 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()) { diff --git a/android/app/src/test/java/tv/orbit/classic/TimesBlurbTest.kt b/android/app/src/test/java/tv/orbit/classic/TimesBlurbTest.kt new file mode 100644 index 00000000..2d514833 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/TimesBlurbTest.kt @@ -0,0 +1,24 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Test + +/** 8 November 2026: Orbit TV Times describes programmes in the library's own words, briefly. */ +class TimesBlurbTest { + @Test fun aShortTaglineWinsWithTheLeads() { + assertEquals("Long live the king. With Chadwick Boseman and Michael B. Jordan.", + timesBlurb("Long live the king.", "T'Challa returns home to Wakanda to take his rightful place as king. More text.", listOf("Chadwick Boseman", "Michael B. Jordan"), "Movie")) + } + @Test fun otherwiseTheSynopsisFirstSentence() { + assertEquals("Del and Rodney take on a job restoring a chandelier.", + timesBlurb(null, "Del and Rodney take on a job restoring a chandelier. It doesn't go well.", emptyList(), "Episode")) + } + @Test fun longTextIsCutAtAWord() { + val b = timesBlurb(null, "word ".repeat(80), emptyList(), "Episode")!! + assertTrue(b.length <= TIMES_BLURB_MAX + 1); assertTrue(b.endsWith("…")) + } + @Test fun nothingToSayStaysEmpty() { + assertNull(timesBlurb(null, "", emptyList(), "Episode")) + assertEquals("Starring Bill Murray.", timesBlurb("", null, listOf("Bill Murray"), "Movie")) + } +} diff --git a/design/times/masthead-preview.png b/design/times/masthead-preview.png index aa307688..e689867b 100644 Binary files a/design/times/masthead-preview.png and b/design/times/masthead-preview.png differ diff --git a/design/times/masthead.svg b/design/times/masthead.svg index 1f3e0c9a..1a09c4e6 100644 --- a/design/times/masthead.svg +++ b/design/times/masthead.svg @@ -7,8 +7,8 @@ - ORBIT - TV Times + ORBIT + TV Times THE WEEK'S PROGRAMMES · EVERY CHANNEL FREE WITH YOUR ORBIT PICKS · FILMS · DRIVE-IN