Give channel tuning more time and one retry (0.23.0)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m46s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m26s

Vortex failed to tune when the provider took over 15 seconds to answer.
Allows 45 seconds, retries once, and records the health check results.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-01 22:12:42 +00:00
co-authored by Claude Opus 5.5
parent 232ebfdc84
commit 80db5495e6
9 changed files with 61 additions and 7 deletions
@@ -41,7 +41,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.22.0\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.23.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -34,6 +34,8 @@ internal object PlaybackUrls {
}
}
internal const val PLAYBACK_INFO_TIMEOUT_MS = 45_000
/** A temporary session is owned by the sample screen, never by persistent storage. */
internal class EmbySampleSession(private val transport: EmbyTransport, private var token: String?,
private val userId: String, sample: EmbySample) {
@@ -71,6 +73,14 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
val auth = currentToken()
return if (PlaybackUrls.isProvider(URI(url))) mapOf("X-Emby-Token" to auth) else emptyMap()
}
/** Tuning shouldn't fail on one slow answer, so a timeout or dropped connection gets one more try. */
fun prepareForTuning(item: SampleItem, sourceId: String, pause: () -> Unit = {}): EmbyPlaybackPlan = try {
prepare(item, preferredSourceId = sourceId)
} catch (failure: EmbyCheckException) {
if (!failure.retryable) throw failure
pause()
prepare(item, preferredSourceId = sourceId)
}
fun prepare(item: SampleItem, isPlayback: Boolean = true, preferredSourceId: String? = null): EmbyPlaybackPlan {
if (preferredSourceId != null && !EmbyClient.validId(preferredSourceId)) throw EmbyCheckException("The channel source is no longer usable.")
if (item.id.isBlank() || sample.items.none { it.id == item.id } && candidateEpisodes[item.id] != item && channelEpisodes[item.id] != item && darkCandidates.none { it.item == item } && darkLineup[item.id] != item) throw EmbyCheckException("Choose a title from the current sample.")
@@ -83,7 +93,7 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
.put("SubtitleProfiles", JSONArray().put(JSONObject().put("Format", "srt").put("Method", "External"))
.put(JSONObject().put("Format", "vtt").put("Method", "External"))))
if (preferredSourceId != null) request.put("MediaSourceId", preferredSourceId)
val response = transport.execute(EmbyRequest("POST", "/Items/${item.id}/PlaybackInfo", request.toString(), currentToken()))
val response = transport.execute(EmbyRequest("POST", "/Items/${item.id}/PlaybackInfo", request.toString(), currentToken(), PLAYBACK_INFO_TIMEOUT_MS))
EmbyClient.expectSuccess(response.status, false)
val info = EmbyClient.parse(response.body)
if (!info.isNull("ErrorCode") && !info.optString("ErrorCode").let { it.isBlank() || it == "0" || it == "None" }) throw EmbyCheckException("The provider did not offer a playable source for this account.")
@@ -41,7 +41,7 @@ internal fun LibraryHealthScreen(health: CatalogueHealth?, busy: Boolean, messag
}
Column(Modifier.fillMaxWidth().background(Panel).padding(10.dp), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text("Full pass ${whole(h.scanMs)} ms • database ${whole(h.bytes / 1024)} KB", color = Color.White, fontSize = 15.sp)
h.timings.forEach { Text("${it.label}: ${whole(it.count)} found, ${whole(it.ms)} ms", color = Muted, fontSize = 14.sp) }
Text(h.timings.joinToString(" • ") { "${it.label}: ${whole(it.count)} in ${whole(it.ms)} ms" }, color = Muted, fontSize = 13.sp, maxLines = 3)
}
}
}
@@ -103,7 +103,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
try {
val plan = prepareMutex.withLock {
withContext(Dispatchers.IO) {
session.prepare(current.media.item, preferredSourceId = current.media.sourceId)
session.prepareForTuning(current.media.item, current.media.sourceId) { Thread.sleep(2_000) }
}
}
if (plan.durationMs == null || kotlin.math.abs(plan.durationMs - current.media.durationMs) > 2_000)
@@ -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.22.0")
next.setRequestProperty("User-Agent", "OrbitTV/0.23.0")
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()) {