0.99.11: seriesKey compiles its expressions once; pool-read failures logged by list position and kind. 0.99.10 installation record
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m6s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m26s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 12:32:36 +00:00
co-authored by Claude Opus 5.5
parent 0ebf45ef86
commit 3903d73304
7 changed files with 56 additions and 7 deletions
@@ -80,7 +80,10 @@ internal fun loopFromPool(pool: List<PoolSeries>, programming: ChannelProgrammin
/** What a build used, so the viewer can see what the library did and didn't have. */
internal class PresetBuild(val channel: SampleChannel, val shows: List<String>, val missing: List<String>)
internal fun seriesKey(title: String) = title.lowercase(java.util.Locale.ROOT).replace(Regex("[^a-z0-9 ]"), " ").trim().removePrefix("the ").replace(Regex(" +"), " ")
internal fun seriesKey(title: String) = title.lowercase(java.util.Locale.ROOT).replace(NotKeyCharacters, " ").trim().removePrefix("the ").replace(Spaces, " ")
// Compiled once: seriesKey runs for every show on every programme planned, and building these each time was most of a top-up's time on the box.
private val NotKeyCharacters = Regex("[^a-z0-9 ]")
private val Spaces = Regex(" +")
/** The same title, or else the title with something after it, such as Blue Planet II. Oldest first, so an original beats its revival. */
internal fun bestSeriesMatch(requested: String, candidates: List<SeriesCandidate>): SeriesCandidate? {
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
connection.connectTimeout = 10_000
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.10\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.11\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -245,7 +245,11 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
if (pool.size == programming.seriesCount) break
checkActive()
requests++
val candidates = searchSeries(transport, userId, ::currentToken, search).candidates
// Counts and the failure's kind only, never titles: which list entry a failed pool read stopped at.
fun <T> traced(step: String, block: () -> T): T = try { block() } catch (failure: Exception) {
android.util.Log.w("OrbitSchedule", "channel=${programming.number} listed=${index + 1} $step failed=${failure.javaClass.simpleName}"); throw failure
}
val candidates = traced("search") { searchSeries(transport, userId, ::currentToken, search).candidates }
val exact = candidates.count { seriesKey(it.title) == seriesKey(search) }
val match = bestSeriesMatch(search, if (programming.exactTitles) candidates.filter { seriesKey(it.title) == seriesKey(search) } else candidates)
// Counts only, never titles: which list entry found nothing, and at which step, so a missing show can be traced.
@@ -255,7 +259,7 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
// A library can hold several copies of one show, one with a single episode and another with the whole run.
// The copy with the most episodes this box can play is the one the channel uses.
val copies = (listOf(match) + candidates.filter { it.id != match.id && seriesKey(it.title) == seriesKey(match.title) }.sortedBy { it.year ?: Int.MAX_VALUE }).take(MAX_SERIES_COPIES)
val read = copies.map { copy -> readWholeSeries(transport, userId, ::currentToken, copy, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio) }
val read = traced("read") { copies.map { copy -> readWholeSeries(transport, userId, ::currentToken, copy, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio) } }
val best = read.maxByOrNull { it.episodes.size }?.takeIf { it.episodes.isNotEmpty() }
if (best == null) { android.util.Log.i("OrbitSchedule", "channel=${programming.number} listed=${index + 1} matched copies=${copies.size} playableEpisodes=0"); continue }
if (copies.size > 1) android.util.Log.i("OrbitSchedule", "channel=${programming.number} copies=${copies.size} usedCopy=${read.indexOf(best) + 1} episodes=${read.map { it.episodes.size }}")
@@ -33,7 +33,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.99.10")
next.setRequestProperty("User-Agent", "OrbitTV/0.99.11")
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()) {