Orbit TV Times: library descriptions, more room, masthead fits phones (0.110.3)
Paul, 8 November 2026: the stock reasons ('An evening film on a film channel') are replaced by each programme's own
words from the library: a short tagline, else the synopsis's first sentence, with a film's two leads (one request
per edition for new items, cached). Each listing is its own card with more space; the masthead's titles have a fixed
width so a phone's serif can't push 'TV Times' off the edge.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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.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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String>): Map<String, String> {
|
||||
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<String>): List<JSONObject> {
|
||||
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<String>, 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
|
||||
|
||||
@@ -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<ProgrammeReminder> = { 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<String>) -> Map<String, String> = { 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<String, String>()
|
||||
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<String, String>(256, .75f, true) { override fun removeEldestEntry(e: MutableMap.MutableEntry<String, String>?) = size > 600 }
|
||||
@Synchronized fun get(session: EmbySampleSession?, ids: List<String>): Map<String, String> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user