From b96b1ec195f9b238b4973763b12e03239a302330 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Fri, 13 Nov 2026 00:21:30 +0000 Subject: [PATCH] 1.0 RC1: functional reliability - Release signing: tools/sign-household.sh signs only the newest build folder (or an older one if its name is typed back), shows name, version, commit and changes, and asks first; tools/make-build-folder.sh writes BUILD.txt. Old per-build scripts retired (12 Nov: r5 was re-signed instead of r6). - Version 1.0.0-rc1, build 43. - Onboarding: when no ready-made channel matches the library, offer Create your own or Try other channels instead of an empty TV; a channel of your own is enough to carry on. - Re-filed episodes found again by series name, season and number (two small requests, only when a booked episode has gone). - TV guide footer says what Back does (to now, then main menu). Co-Authored-By: Claude Opus 5.5 --- android/app/build.gradle.kts | 4 +- .../tv/orbit/classic/EmbyPlaybackProtocol.kt | 28 ++++++++++ .../java/tv/orbit/classic/EpisodeDiscovery.kt | 2 +- .../main/java/tv/orbit/classic/GuideGrid.kt | 3 +- .../main/java/tv/orbit/classic/Onboarding.kt | 15 ++++- .../java/tv/orbit/classic/ProgrammeLengths.kt | 6 +- .../test/java/tv/orbit/classic/RefiledTest.kt | 51 +++++++++++++++++ tools/make-build-folder.sh | 35 ++++++++++++ tools/sign-household.sh | 55 +++++++++++++++++++ 9 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 android/app/src/test/java/tv/orbit/classic/RefiledTest.kt create mode 100755 tools/make-build-folder.sh create mode 100755 tools/sign-household.sh diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index dad8b632..db1a91a4 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("org.jetbrains.kotlin.plugin.compose") } /** The release's build number: versionCode is this x 10 plus the edition's channel. */ -val ORBIT_BUILD = 42 +val ORBIT_BUILD = 43 android { namespace = "tv.orbit.classic" compileSdk = 36 @@ -11,7 +11,7 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionName = "0.129.0" + versionName = "1.0.0-rc1" } // Two editions of the same app (Paul, 10 November 2026): the household build, which updates itself between rooms, and the // Play build, which only Google Play updates. Both are tv.orbit.classic, so a TV can move between them keeping its data. 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 15927a20..b18e23aa 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt @@ -511,6 +511,34 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v return ScheduledMedia(found, copy.sourceId, copy.durationMs) } + /** + * The same for an episode (1.0 RC1): the series found again by its exact name, then that season's episode with the same + * number. Two small requests, only when a booked episode has gone; null when the series or the episode isn't there. + */ + fun refiledEpisode(item: SampleItem): ScheduledMedia? { + if (item.type != "Episode") return null + val (series, season, number) = Regex("""^(.*) / S(\d+) E(\d+) / """).find(item.title)?.destructured ?: return null + val term = java.net.URLEncoder.encode(series, "UTF-8") + val reply = transport.execute(EmbyRequest("GET", "/Items?UserId=$userId&Recursive=true&IncludeItemTypes=Series&SearchTerm=$term&StartIndex=0&Limit=10&EnableImages=false&EnableUserData=false", token = currentToken())) + EmbyClient.expectSuccess(reply.status, false) + val rows = EmbyClient.parse(reply.body).optJSONArray("Items") ?: return null + val named = (0 until minOf(rows.length(), 10)).mapNotNull { rows.optJSONObject(it) } + .filter { seriesKey(it.optString("Name")) == seriesKey(series) && EmbyClient.validId(it.optString("Id")) }.take(2) + for (show in named) { + val episodes = transport.execute(EmbyRequest("GET", "/Shows/${show.optString("Id")}/Episodes?UserId=$userId&Season=$season&Fields=MediaSources&EnableImages=false&EnableUserData=false", token = currentToken())) + EmbyClient.expectSuccess(episodes.status, false) + val list = EmbyClient.parse(episodes.body).optJSONArray("Items") ?: continue + val episode = (0 until minOf(list.length(), 200)).mapNotNull { list.optJSONObject(it) } + .firstOrNull { it.optInt("ParentIndexNumber", -1) == season.toInt() && it.optInt("IndexNumber", -1) == number.toInt() } + ?.let { poolEpisode(it, BoxDecoders::canDecode, englishAudio = false) } ?: continue + if (episode.id == item.id) return null + val found = scheduledItem(series, episode) + rememberScheduledItems(listOf(found)) + return ScheduledMedia(found, episode.sourceId, episode.durationMs) + } + return null + } + fun checkMetadataCoverage(checkActive: () -> Unit = {}): List = auditMetadataCoverage(transport, userId, ::currentToken, checkActive) fun importCatalogue(sink: CatalogueSink, maxPages: Int = CATALOGUE_PAGES_PER_RUN, pause: () -> Unit = {}, checkActive: () -> Unit = {}, onPage: () -> Unit = {}, diff --git a/android/app/src/main/java/tv/orbit/classic/EpisodeDiscovery.kt b/android/app/src/main/java/tv/orbit/classic/EpisodeDiscovery.kt index bd8cd45a..8995caac 100644 --- a/android/app/src/main/java/tv/orbit/classic/EpisodeDiscovery.kt +++ b/android/app/src/main/java/tv/orbit/classic/EpisodeDiscovery.kt @@ -75,7 +75,7 @@ internal fun readWholeSeries(transport: EmbyTransport, userId: String, token: () return PoolSeries(series.id, series.title, episodes.sortedBy { it.mark }.distinctBy { it.mark }) } -private fun poolEpisode(item: org.json.JSONObject, canDecode: (String) -> Boolean, englishAudio: Boolean): PoolEpisode? { +internal fun poolEpisode(item: org.json.JSONObject, canDecode: (String) -> Boolean, englishAudio: Boolean): PoolEpisode? { val id = item.optString("Id") val season = item.optInt("ParentIndexNumber", -1) val number = item.optInt("IndexNumber", -1) diff --git a/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt b/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt index c3cc9830..9454f719 100644 --- a/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt +++ b/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt @@ -297,7 +297,8 @@ internal fun GuideGrid(channels: List, selectedNumber: Int, modif } } Row(Modifier.fillMaxWidth()) { - Text("▲▼ Channel ◄► Time (◄ back two days for Catch Up) Hold ◄► Day OK Watch", Modifier.weight(1f), color = Muted, fontSize = 11.sp) + // What Back does here, always in words (1.0 RC1): back to now first, then out of the guide. + Text("▲▼ Channel ◄► Time (◄ back two days for Catch Up) Hold ◄► Day OK Watch Back " + if (awayFromNow) "To now" else "Main menu", Modifier.weight(1f), color = Muted, fontSize = 11.sp) if (rowsShown < channels.size) Text("Channels ${firstRow + 1} to ${firstRow + rowsShown} of ${channels.size}", color = Muted, fontSize = 11.sp) } } diff --git a/android/app/src/main/java/tv/orbit/classic/Onboarding.kt b/android/app/src/main/java/tv/orbit/classic/Onboarding.kt index dc1ae9c4..f6e4cb95 100644 --- a/android/app/src/main/java/tv/orbit/classic/Onboarding.kt +++ b/android/app/src/main/java/tv/orbit/classic/Onboarding.kt @@ -282,6 +282,8 @@ private fun ChannelsStep(onNext: () -> Unit) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(16.dp)) { OrbitButton("Set up ${ticked.size} channels", enabled = ticked.isNotEmpty(), onClick = { ChannelSetup.begin(SmartChannels.map { it.number }.filter { it in ticked }) }) if (maker != null) OrbitButton("Create your own", onClick = { made = null; creating = true }) + // A channel of your own is enough to go on with (1.0 RC1): first run never needs a ready-made one to match. + if (made != null) OrbitButton("Next", onClick = onNext) Text("Change them any time in Settings › Channels.", color = Muted, fontSize = 13.sp) } } @@ -303,11 +305,18 @@ private fun ChannelsStep(onNext: () -> Unit) { drawLine(Color(0xFF14213D), eye - Offset(r * .2f, 0f), eye + Offset(r * .2f, 0f), r * .07f) } } - Text(if (ChannelSetup.finished) "All matched" else "Drift's matching your library", color = Ink, fontSize = 20.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center) + // None of them matched (1.0 RC1: a library unlike the ones Orbit's channels were made for). First run must still + // end on a programme, so instead of carrying on to an empty TV, it offers a channel made from what the library has. + val noneMatched = ChannelSetup.finished && ChannelSetup.found.values.none { it > 0 } + Text(if (noneMatched) "Nothing matched yet" else if (ChannelSetup.finished) "All matched" else "Drift's matching your library", color = Ink, fontSize = 20.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center) val now = System.currentTimeMillis() - Text(if (ChannelSetup.finished) "${ChannelSetup.found.values.filter { it > 0 }.sum()} titles across ${ChannelSetup.found.count { it.value > 0 }} channels" + Text(if (noneMatched) "None of these found their shows in your library. Make a channel from what you have, or try others." + else if (ChannelSetup.finished) "${ChannelSetup.found.values.filter { it > 0 }.sum()} titles across ${ChannelSetup.found.count { it.value > 0 }} channels" else "${ChannelSetup.found.size} of ${ChannelSetup.wanted.size} channels · about ${ChannelSetup.minutesLeft(now + t * 0)} min left", color = Yellow, fontSize = 14.sp, textAlign = TextAlign.Center) - if (ChannelSetup.finished) OrbitButton("Next", Modifier.padding(top = 16.dp).width(180.dp).focusRequester(go), centred = true, onClick = onNext) + if (noneMatched) { + if (maker != null) OrbitButton("Create your own", Modifier.padding(top = 16.dp).width(220.dp).focusRequester(go), centred = true, onClick = { made = null; ChannelSetup.begin(emptyList()); creating = true }) + OrbitButton("Try other channels", Modifier.padding(top = 8.dp).width(220.dp).then(if (maker == null) Modifier.focusRequester(go) else Modifier), centred = true, onClick = { ChannelSetup.begin(emptyList()) }) + } else if (ChannelSetup.finished) OrbitButton("Next", Modifier.padding(top = 16.dp).width(180.dp).focusRequester(go), centred = true, onClick = onNext) } Column(Modifier.weight(1f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(5.dp)) { Text("Here's where everything goes", color = Ink, fontFamily = Anton, fontSize = 26.sp) diff --git a/android/app/src/main/java/tv/orbit/classic/ProgrammeLengths.kt b/android/app/src/main/java/tv/orbit/classic/ProgrammeLengths.kt index d1cff6e1..e3dd5a43 100644 --- a/android/app/src/main/java/tv/orbit/classic/ProgrammeLengths.kt +++ b/android/app/src/main/java/tv/orbit/classic/ProgrammeLengths.kt @@ -97,15 +97,15 @@ internal fun retimedPlan(plan: ChannelPlan, startMs: Long, actualMs: Long): Chan } /** - * Opens a booked programme. A film the server answers for with an error because its number has gone (404, or Emby's 500 - * for an item it no longer has) is looked for once by title; the copy found plays in the same slot, and on a live channel + * Opens a booked programme. A film or episode the server answers for with an error because its number has gone (404, or + * Emby's 500 for an item it no longer has) is looked for once by title (an episode by its series and number); the copy found plays in the same slot, and on a live channel * the schedule is updated to it, so the guide and every screen agree. Returns the plan and the programme as now booked. */ internal fun openBooked(session: EmbySampleSession, channel: SampleChannel, store: ScheduleStore, show: SampleBroadcast, live: Boolean, ahead: Boolean = false): Pair { try { return session.prepareForTuning(show.media.item, show.media.sourceId, ahead) { Thread.sleep(2_000) } to show } catch (failure: EmbyCheckException) { if (failure.httpStatus != 404 && failure.httpStatus != 500) throw failure - val found = session.refiledFilm(show.media.item) ?: throw failure + val found = session.refiledFilm(show.media.item) ?: session.refiledEpisode(show.media.item) ?: throw failure android.util.Log.i("OrbitSchedule", "channel=${channel.number} refiled old=${show.media.item.id} new=${found.item.id}") if (live) PlanEdits.replace(channel, store, session.accountId, show.startMs, show.media.item.id, found) // Booked in the old slot; the length check that follows then re-times it for the copy's own length. diff --git a/android/app/src/test/java/tv/orbit/classic/RefiledTest.kt b/android/app/src/test/java/tv/orbit/classic/RefiledTest.kt new file mode 100644 index 00000000..d870b5ee --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/RefiledTest.kt @@ -0,0 +1,51 @@ +package tv.orbit.classic + +import org.json.JSONArray +import org.json.JSONObject +import org.junit.Assert.* +import org.junit.Test + +/** 12 to 13 November 2026: the first scan re-files titles under new numbers; Orbit finds a booked one again, once. */ +class RefiledTest { + @org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" } + @org.junit.After fun noServer() { EmbyServer.origin = "" } + private val gone = SampleItem("Fixture Show / S2 E3 / The Third", "Episode", 22, "", "oldep1", 22 * 60_000L) + private fun source(id: String) = JSONArray().put(JSONObject().put("Id", id).put("Container", "mkv").put("RunTimeTicks", 22 * 60_000L * 10_000)) + private fun episode(id: String, s: Int, e: Int) = JSONObject().put("Id", id).put("Type", "Episode").put("Name", "Episode $e") + .put("ParentIndexNumber", s).put("IndexNumber", e).put("MediaSources", source("src$id")) + + @Test fun anEpisodeIsFoundAgainBySeriesAndNumber() { + val asked = mutableListOf() + val transport = EmbyTransport { r -> + asked += r.path + when { + "IncludeItemTypes=Series" in r.path -> EmbyReply(200, JSONObject().put("Items", JSONArray() + .put(JSONObject().put("Id", "other1").put("Name", "Fixture Show Revisited")) + .put(JSONObject().put("Id", "show2").put("Name", "Fixture Show"))).toString()) + r.path.startsWith("/Shows/show2/Episodes") -> EmbyReply(200, JSONObject().put("Items", JSONArray() + .put(episode("newep2", 2, 2)).put(episode("newep3", 2, 3))).toString()) + else -> EmbyReply(404, "") + } + } + val session = EmbySampleSession(transport, "fixture-token-private", "fixture-user", EmbySample(listOf(gone), 1)) + val found = session.refiledEpisode(gone)!! + assertEquals("newep3", found.item.id) + assertEquals("srcnewep3", found.sourceId) + assertTrue(found.item.title.startsWith("Fixture Show / S2 E3 / ")) + // Two small requests, and only the exactly named series was opened. + assertEquals(2, asked.size) + assertTrue(asked.none { it.startsWith("/Shows/other1") }) + } + + @Test fun nothingWhenTheEpisodeIsntThere() { + val transport = EmbyTransport { r -> + when { + "IncludeItemTypes=Series" in r.path -> EmbyReply(200, JSONObject().put("Items", JSONArray().put(JSONObject().put("Id", "show2").put("Name", "Fixture Show"))).toString()) + else -> EmbyReply(200, JSONObject().put("Items", JSONArray().put(episode("newep2", 2, 2))).toString()) + } + } + val session = EmbySampleSession(transport, "fixture-token-private", "fixture-user", EmbySample(listOf(gone), 1)) + assertNull(session.refiledEpisode(gone)) + assertNull(session.refiledEpisode(gone.copy(type = "Movie"))) + } +} diff --git a/tools/make-build-folder.sh b/tools/make-build-folder.sh new file mode 100755 index 00000000..3c5b2821 --- /dev/null +++ b/tools/make-build-folder.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# After tools/verify.sh passes: puts the household build in ~/Documents/OrbitTV/outputs// with a BUILD.txt that the +# signing script (tools/sign-household.sh, copied to outputs/sign.sh) reads. Nothing is signed or installed here. +# +# bash tools/make-build-folder.sh 1.0-rc1 "What changed, in one line" +set -euo pipefail +NAME=${1:?a build name, such as 1.0-rc1} +CHANGES=${2:?one line on what changed} +ROOT=$(cd "$(dirname "$0")/.." && pwd) +OUTPUTS=${ORBIT_OUTPUTS:-$HOME/Documents/OrbitTV/outputs} +APK=$ROOT/android/app/build/outputs/apk/household/release/app-household-release-unsigned.apk +[ -f "$APK" ] || { echo "No household release build: run tools/verify.sh first."; exit 1; } +[ -z "$(git -C "$ROOT" status --porcelain -- android)" ] || { echo "android/ has uncommitted changes: commit first, so the build matches a commit."; exit 1; } +BT=$(ls -d /opt/android-sdk/build-tools/* | sort -V | tail -1) +DIR=$OUTPUTS/$NAME +[ ! -e "$DIR" ] || { echo "$DIR already exists."; exit 1; } +mkdir -p "$DIR" +UNSIGNED=orbit-$NAME-aligned-unsigned.apk +"$BT/zipalign" -f -p 4 "$APK" "$DIR/$UNSIGNED" +BADGING=$("$BT/aapt2" dump badging "$DIR/$UNSIGNED" | head -1) +VERSION=$(sed -E "s/.*versionName='([^']*)'.*/\1/" <<<"$BADGING"); CODE=$(sed -E "s/.*versionCode='([^']*)'.*/\1/" <<<"$BADGING") +cat > "$DIR/BUILD.txt" </dev/null || rm -f "$KEY"' EXIT +gpg --quiet --decrypt "$SOURCE" > "$KEY" +"$BT/apksigner" sign --ks "$KEY" --out "$OUT" "$IN" +GOT=$("$BT/apksigner" verify --print-certs "$OUT" | grep -m1 'SHA-256 digest' | awk '{print $NF}') +if [ "$GOT" = "$WANT" ]; then echo "Signed $(field name) with the household key: $OUT" +else echo "Certificate doesn't match the TVs' ($GOT); not using it."; rm -f "$OUT"; exit 1; fi