diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 7f855e8a..7b2dd2a8 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 = 66 +val ORBIT_BUILD = 67 android { namespace = "tv.orbit.classic" compileSdk = 36 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 07c161be..cb9bc55b 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackProtocol.kt @@ -479,10 +479,11 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v if (found == null && accepted.ref.isNotEmpty()) { // A repair kept from before is tried first; a stale one is dropped and looked up afresh, once. for (attempt in 0..1) { - val id = IdRepairs.lookup("Movie", accepted.ref) { + // Paced out or not answering: tried again at the next read, with no cooldown. + val id = try { IdRepairs.lookup("Movie", accepted.ref) { requests++ - pickByProvider(runCatching { byProvider("Movie", accepted.ref, "&Fields=ProductionYear") }.getOrDefault(emptyList()), accepted.title, accepted.year)?.optString("Id") - } ?: break + pickByProvider(byProvider("Movie", accepted.ref, "&Fields=ProductionYear"), accepted.title, accepted.year)?.optString("Id") + } } catch (cancelled: kotlinx.coroutines.CancellationException) { throw cancelled } catch (_: Exception) { null } ?: break if (id == accepted.id) break requests++ found = playableFilm(id, programming.englishAudio, accepted.title, accepted.year) @@ -498,10 +499,10 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v // one request, only when reading it by its saved ID fails or finds nothing (18 November 2026). fun refind(): PoolSeries? { if (accepted.ref.isEmpty()) return null - val id = IdRepairs.lookup("Series", accepted.ref) { + val id = try { IdRepairs.lookup("Series", accepted.ref) { requests++ - pickByProvider(runCatching { byProvider("Series", accepted.ref, "&Fields=ProductionYear") }.getOrDefault(emptyList()), accepted.title, accepted.year)?.optString("Id") - }?.takeIf { it != accepted.id } ?: return null + pickByProvider(byProvider("Series", accepted.ref, "&Fields=ProductionYear"), accepted.title, accepted.year)?.optString("Id") + } } catch (cancelled: kotlinx.coroutines.CancellationException) { throw cancelled } catch (_: Exception) { null }?.takeIf { it != accepted.id } ?: return null return runCatching { read(id) }.getOrNull()?.takeIf { it.episodes.isNotEmpty() }?.also { refound[accepted.id] = id; accepted = accepted.copy(id = id) } ?: run { IdRepairs.forget("Series", accepted.ref); null } } diff --git a/android/app/src/main/java/tv/orbit/classic/IdRepairs.kt b/android/app/src/main/java/tv/orbit/classic/IdRepairs.kt index 18499aef..77c7803b 100644 --- a/android/app/src/main/java/tv/orbit/classic/IdRepairs.kt +++ b/android/app/src/main/java/tv/orbit/classic/IdRepairs.kt @@ -49,7 +49,7 @@ internal object IdRepairs { /** * The item for [ref]: the kept repair, or [fetch] (one lookup, never two at once for the same title, never during a - * cooldown). A fetch that finds nothing starts or lengthens the cooldown. + * cooldown). A fetch that finds nothing starts or lengthens the cooldown; one that throws records nothing and throws on. */ fun lookup(type: String, ref: String, nowMs: Long = System.currentTimeMillis(), fetch: () -> String?): String? { if (ref.isEmpty()) return null @@ -57,7 +57,9 @@ internal object IdRepairs { synchronized(locks.getOrPut(k) { Any() }) { known(type, ref)?.let { return it } if (coolingDown(type, ref, nowMs)) return null - val id = runCatching(fetch).getOrNull()?.takeIf { EmbyClient.validId(it) } + // A lookup that couldn't be made (paced out of the hour's budget, the server not answering) isn't a lookup that + // found nothing: it throws to the caller and starts no cooldown (18 November 2026, After Dark's first read). + val id = fetch()?.takeIf { EmbyClient.validId(it) } record(k, id, nowMs) return id } diff --git a/android/app/src/test/java/tv/orbit/classic/IdRepairsTest.kt b/android/app/src/test/java/tv/orbit/classic/IdRepairsTest.kt index c0a65a62..421b96dc 100644 --- a/android/app/src/test/java/tv/orbit/classic/IdRepairsTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/IdRepairsTest.kt @@ -99,3 +99,34 @@ class RemakeGuardTest { } finally { EmbyServer.origin = ""; IdRepairs.resetForTest() } } } + +/** 18 November 2026: After Dark's first read after the move ran out of the hour's budget mid-way. */ +class PacedLookupTest { + @org.junit.Before fun clean() { IdRepairs.resetForTest(); EmbyServer.origin = "https://emby.example.com" } + @org.junit.After fun after() { IdRepairs.resetForTest(); EmbyServer.origin = "" } + + @Test fun aLookupThatCouldntBeMadeStartsNoCooldown() { + assertThrows(PacedOut::class.java) { IdRepairs.lookup("Movie", "imdb.tt5", 0L) { throw PacedOut() } } + assertFalse(IdRepairs.coolingDown("Movie", "imdb.tt5", 1L)) + assertEquals("ok", IdRepairs.lookup("Movie", "imdb.tt5", 2L) { "ok" }) + } + + @Test fun anApprovalPacedOutIsTriedAgainAtTheNextRead() { + var paced = true + val transport = EmbyTransport { r -> + when { + paced && "AnyProviderIdEquals" in r.path -> throw PacedOut() + "AnyProviderIdEquals=imdb.tt0100814" in r.path -> EmbyReply(200, JSONObject().put("Items", org.json.JSONArray().put(JSONObject().put("Id", "new1").put("Name", "Tremors").put("Type", "Movie"))).toString()) + "Ids=new1" in r.path -> EmbyReply(200, JSONObject().put("Items", org.json.JSONArray().put(JSONObject().put("Id", "new1").put("Name", "Tremors").put("Type", "Movie") + .put("MediaSources", org.json.JSONArray().put(JSONObject().put("Id", "s1").put("Container", "mkv").put("RunTimeTicks", 90 * 60_000L * 10_000))))).toString()) + else -> EmbyReply(200, JSONObject().put("Items", org.json.JSONArray()).toString()) + } + } + val s = EmbySampleSession(transport, "fixture-token-private", "fixture-user", EmbySample(emptyList(), 0)) + val channel = ChannelProgramming(305, "After Dark", emptyList(), filmRestMs = 1L) + val choices = ChannelChoices(listOf(Suggestion("moved-1", "Tremors", 1990, "Movie", "", "", ref = "imdb.tt0100814"))) + assertTrue(s.readChannelPool(channel, null, choices).series.isEmpty()) + paced = false + assertEquals(listOf("new1"), s.readChannelPool(channel, null, choices).series.map { it.id }) + } +}