Quicker open; Tonight on Orbit 2 with a picture (0.108.55)
- validId built a Regex on every call. It runs thousands of times as the saved sign-in is read and checked (4.3 s of decoding on the box), so it's now a plain loop. The catalogue title key's pattern is compiled once too. - Promos: "Tonight on Orbit 2" rather than "on 2"; the picture tries the show's backdrop and poster as well as the episode's, and with none the channel's logo shows, not an empty box. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId = "tv.orbit.classic"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 214
|
||||
versionName = "0.108.54-setup-once"
|
||||
versionCode = 215
|
||||
versionName = "0.108.55-quicker-open"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
// Android logging and the like do nothing in unit tests, so whole flows (a channel read from a fake server) can run.
|
||||
|
||||
@@ -17,9 +17,12 @@ internal fun catalogueIdKey(type: String, providerIds: String): String? {
|
||||
return "$type|$match"
|
||||
}
|
||||
|
||||
// Compiled once: this runs for every title in the catalogue.
|
||||
private val TitleSpaces = Regex(" +")
|
||||
|
||||
/** Case, punctuation and a leading article don't make a different title. The year keeps remakes apart. */
|
||||
internal fun catalogueTitleKey(type: String, title: String, year: Int?): String {
|
||||
val letters = title.lowercase(Locale.ROOT).map { if (it.isLetterOrDigit()) it else ' ' }.joinToString("").trim().replace(Regex(" +"), " ")
|
||||
val letters = title.lowercase(Locale.ROOT).map { if (it.isLetterOrDigit()) it else ' ' }.joinToString("").trim().replace(TitleSpaces, " ")
|
||||
return "$type|${letters.removePrefix("the ")}|${year ?: "?"}"
|
||||
}
|
||||
|
||||
|
||||
@@ -261,13 +261,13 @@ internal fun liveTickets(tickets: Map<Long, Int>, nowMs: Long) = tickets.filterK
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
|
||||
@Composable
|
||||
internal fun rememberFilmPicture(session: EmbySampleSession, itemId: String?): Bitmap? {
|
||||
internal fun rememberFilmPicture(session: EmbySampleSession, itemId: String?, seriesId: String? = null): Bitmap? {
|
||||
val context = LocalContext.current
|
||||
val picture by produceState<Bitmap?>(null, itemId) {
|
||||
value = null
|
||||
if (itemId != null) value = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
loadArtwork(ArtworkCache(Workspaces.current(context).artworkDir), itemId, null, session::fetchArtwork)?.let { BitmapFactory.decodeByteArray(it, 0, it.size) }
|
||||
loadArtwork(ArtworkCache(Workspaces.current(context).artworkDir), itemId, seriesId, session::fetchArtwork)?.let { BitmapFactory.decodeByteArray(it, 0, it.size) }
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.108.54\"") +
|
||||
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.55\"") +
|
||||
(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.108.54\"" +
|
||||
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.55\"" +
|
||||
(token?.let { ", Token=\"$it\"" } ?: ""))
|
||||
}
|
||||
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
|
||||
@@ -196,7 +196,13 @@ internal class EmbyClient(private val transport: EmbyTransport = HttpsEmbyTransp
|
||||
return EmbySampleSession(transport, token, identity.userId, saved.sample).also { it.restoreRemembered(saved) }
|
||||
}
|
||||
companion object {
|
||||
internal fun validId(value: String) = Regex("[A-Za-z0-9_-]{1,128}").matches(value)
|
||||
// A plain loop, not a Regex built on every call: it's checked thousands of times as Orbit opens, and building the
|
||||
// pattern each time cost seconds on the box (6 November 2026).
|
||||
internal fun validId(value: String): Boolean {
|
||||
if (value.isEmpty() || value.length > 128) return false
|
||||
for (c in value) if (!(c in 'A'..'Z' || c in 'a'..'z' || c in '0'..'9' || c == '_' || c == '-')) return false
|
||||
return true
|
||||
}
|
||||
internal fun parse(body: String): JSONObject = try { JSONObject(body) }
|
||||
catch (_: Exception) { throw EmbyCheckException("The provider returned a response this version cannot read.") }
|
||||
internal fun clean(value: String, limit: Int) = value.filter { !it.isISOControl() }.take(limit)
|
||||
|
||||
@@ -20,7 +20,8 @@ private const val ARTWORK_KEEP_FILES = 150
|
||||
/** Where a programme's picture may be: its show's wide artwork first, as that suits a full screen, then its own. */
|
||||
internal fun artworkPaths(itemId: String, seriesId: String?): List<String> =
|
||||
(listOfNotNull(seriesId, itemId).distinct().filter { EmbyClient.validId(it) }.map { "/Items/$it/Images/Backdrop?maxWidth=1280&quality=80" } +
|
||||
listOf(itemId).filter { EmbyClient.validId(it) }.map { "/Items/$it/Images/Primary?maxWidth=1280&quality=80" })
|
||||
// Then the episode's own still, and last the show's poster: a promo or guide card is never left empty if the show has any picture.
|
||||
listOfNotNull(itemId, seriesId).distinct().filter { EmbyClient.validId(it) }.map { "/Items/$it/Images/Primary?maxWidth=1280&quality=80" })
|
||||
|
||||
/** Keeps artwork on the box between visits, within a fixed number of files, so a show's picture is only fetched once. */
|
||||
internal class ArtworkCache(private val directory: File) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@@ -65,7 +66,10 @@ internal fun promoHeadline(item: WhatsOnItem, nowMs: Long, zone: ZoneId = ZoneId
|
||||
val hour = Instant.ofEpochMilli(item.startMs).atZone(zone).hour
|
||||
val evening = day == today || (day == today.plusDays(1) && hour < 6)
|
||||
val whenWord = if (evening) (if (hour in 6..16 && day == today) "LATER" else "TONIGHT") else "TOMORROW"
|
||||
val where = if (item.channel == DRIVE_IN_NUMBER) "AT THE DRIVE-IN" else "ON " + (ChannelBrands.forNumber(item.channel)?.displayName ?: "ORBIT").removePrefix("Orbit ").uppercase()
|
||||
// "On Gold", "On Paradox", but "On Orbit 2" (Paul, 6 November 2026: "Tonight on 2" didn't look right).
|
||||
val name = ChannelBrands.forNumber(item.channel)?.displayName ?: "Orbit"
|
||||
val short = name.removePrefix("Orbit ")
|
||||
val where = if (item.channel == DRIVE_IN_NUMBER) "AT THE DRIVE-IN" else "ON " + (if (short.length <= 3 || short.all { it.isDigit() }) name else short).uppercase()
|
||||
return "$whenWord $where"
|
||||
}
|
||||
|
||||
@@ -77,7 +81,7 @@ internal fun PromoOverlay(session: EmbySampleSession, item: WhatsOnItem) {
|
||||
val castOn = remember { settings.castOn }
|
||||
var t by remember { mutableLongStateOf(if (calm) 5_000L else 0L) }
|
||||
LaunchedEffect(calm) { if (!calm) { val start = withFrameMillis { it }; while (true) withFrameMillis { t = it - start } } }
|
||||
val picture = rememberFilmPicture(session, item.entry.media.item.id)
|
||||
val picture = rememberFilmPicture(session, item.entry.media.item.id, item.entry.seriesId)
|
||||
val now = remember { System.currentTimeMillis() }
|
||||
Box(Modifier.fillMaxSize().background(Navy)) {
|
||||
StarrySky()
|
||||
@@ -86,6 +90,8 @@ internal fun PromoOverlay(session: EmbySampleSession, item: WhatsOnItem) {
|
||||
Text(promoHeadline(item, now), color = Yellow, fontFamily = Anton, fontSize = 34.sp)
|
||||
Box(Modifier.width(500.dp).height(190.dp).clip(RoundedCornerShape(12.dp)).background(Panel)) {
|
||||
if (picture != null) Image(picture.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
|
||||
// No picture at all: the channel's logo, large and soft, rather than an empty panel.
|
||||
else ChannelBrands.forNumber(item.channel)?.let { Image(painterResource(it.logo), null, Modifier.align(Alignment.Center).width(260.dp).height(80.dp).alpha(.35f)) }
|
||||
Box(Modifier.fillMaxSize().background(Color.Black.copy(alpha = .3f)))
|
||||
Text(item.title.uppercase(), Modifier.align(Alignment.BottomStart).padding(14.dp), color = Color.White, fontFamily = Anton, fontSize = 26.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
|
||||
@@ -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.108.54")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.108.55")
|
||||
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()) {
|
||||
|
||||
@@ -12,7 +12,7 @@ class ProgrammeArtworkTest {
|
||||
private val png = byteArrayOf(1, 2, 3)
|
||||
|
||||
@Test fun theShowsWideArtworkIsTriedFirst() {
|
||||
assertEquals(listOf("/Items/show/Images/Backdrop?maxWidth=1280&quality=80", "/Items/ep/Images/Backdrop?maxWidth=1280&quality=80", "/Items/ep/Images/Primary?maxWidth=1280&quality=80"), artworkPaths("ep", "show"))
|
||||
assertEquals(listOf("/Items/show/Images/Backdrop?maxWidth=1280&quality=80", "/Items/ep/Images/Backdrop?maxWidth=1280&quality=80", "/Items/ep/Images/Primary?maxWidth=1280&quality=80", "/Items/show/Images/Primary?maxWidth=1280&quality=80"), artworkPaths("ep", "show"))
|
||||
}
|
||||
|
||||
@Test fun aFilmOnlyAsksForItsOwnArtwork() {
|
||||
|
||||
@@ -32,6 +32,7 @@ class PromosTest {
|
||||
val now = at(6, 18)
|
||||
assertEquals("TONIGHT AT THE DRIVE-IN", promoHeadline(item(DRIVE_IN_NUMBER, at(6, 20)), now, london))
|
||||
assertEquals("TONIGHT ON ACTION", promoHeadline(item(302, at(6, 21)), now, london))
|
||||
assertEquals("TONIGHT ON ORBIT 2", promoHeadline(item(102, at(6, 21)), now, london)) // not "on 2"
|
||||
assertEquals("TONIGHT ON ACTION", promoHeadline(item(302, at(7, 1)), now, london))
|
||||
assertEquals("TOMORROW ON ACTION", promoHeadline(item(302, at(7, 20)), now, london))
|
||||
assertEquals("LATER ON ACTION", promoHeadline(item(302, at(6, 15)), at(6, 12), london))
|
||||
|
||||
Reference in New Issue
Block a user