0.99.16: automatic English subtitles for programmes with no English sound (Stage D2)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m0s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m48s

Manual choices win, manual Off is kept distinct from the untouched default, nothing is saved and the setting is
untouched. Booking fingerprints identical to 0.99.15.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 15:34:31 +00:00
co-authored by Claude Opus 5.5
parent 0e16a0effe
commit 0d2ea65934
9 changed files with 221 additions and 11 deletions
@@ -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.15\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.16\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -111,6 +111,8 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
}
LaunchedEffect(player) { onPlayer?.invoke(player) }
fun textTracks() = player.currentTracks.groups.filter { it.type == C.TRACK_TYPE_TEXT && it.isSupported }
/** The languages of the programme's sound tracks, for [subtitleChoice]. */
fun audioLanguages() = player.currentTracks.groups.filter { it.type == C.TRACK_TYPE_AUDIO }.map { it.getTrackFormat(0).language.orEmpty() }
fun chooseSubtitle(index: Int?, tracks: List<Tracks.Group>) {
subtitleIndex = index
val builder = player.trackSelectionParameters.buildUpon().clearOverridesOfType(C.TRACK_TYPE_TEXT).setTrackTypeDisabled(C.TRACK_TYPE_TEXT, index == null)
@@ -126,7 +128,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
fun trackRows(): List<TrackRow> {
val subtitles = textTracks()
val audio = player.currentTracks.groups.filter { it.type == C.TRACK_TYPE_AUDIO && it.isSupported }
val subtitleRows = listOf(TrackRow("Subtitles", "Off", subtitles.none { it.isSelected }) { chooseSubtitle(null, subtitles); subtitlePreference?.value = null }) +
val subtitleRows = listOf(TrackRow("Subtitles", "Off", subtitles.none { it.isSelected }) { chooseSubtitle(null, subtitles); subtitlePreference?.value = SUBTITLES_OFF }) +
// Capped so the panel always fits the screen, even on a file with dozens of subtitles.
subtitles.take(8).mapIndexed { index, group ->
val format = group.getTrackFormat(0)
@@ -174,7 +176,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
// Its tracks were found before this listener arrived, so the subtitle choice is made here.
if (runningPlayer != null && subtitleIndex == null) {
val available = textTracks()
subtitleFor(subtitlePreference?.value, available.map { it.getTrackFormat(0).language.orEmpty() })?.let { chooseSubtitle(it, available) }
subtitleChoice(subtitlePreference?.value, audioLanguages(), available.map { it.getTrackFormat(0).language.orEmpty() })?.let { chooseSubtitle(it, available) }
}
playing = player.isPlaying
val listener = object : Player.Listener {
@@ -235,7 +237,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
}
if (subtitleIndex == null) {
val available = textTracks()
subtitleFor(subtitlePreference?.value, available.map { it.getTrackFormat(0).language.orEmpty() })?.let { chooseSubtitle(it, available) }
subtitleChoice(subtitlePreference?.value, audioLanguages(), available.map { it.getTrackFormat(0).language.orEmpty() })?.let { chooseSubtitle(it, available) }
}
}
override fun onPlaybackStateChanged(state: Int) {
@@ -27,8 +27,8 @@ import kotlinx.coroutines.withContext
/**
* The hand-run playback test (approved by Paul on 4 November 2026 for Dragon Ball Super: Beerus): one episode, by its
* Emby id, in Orbit's own player, opened with `--es orbit_play_test <id>` on MainActivity. English subtitles are chosen the
* way Orbit chooses them with its subtitles setting on. It books nothing and never touches the scheduler, plans, cursors or
* Emby id, in Orbit's own player, opened with `--es orbit_play_test <id>` on MainActivity. Subtitles are chosen exactly as on
* a channel, from the subtitles setting and [subtitleChoice]. It books nothing and never touches the scheduler, plans, cursors or
* pools, reports nothing to Emby (so no progress or resume point is recorded there), and ends by itself after
* [TEST_MS], or on Back, returning to Orbit as it was. It logs formats, languages and counts only (tag OrbitPlayTest),
* never a title, path or address.
@@ -74,7 +74,8 @@ private fun PlaybackTest(itemId: String, done: () -> Unit) {
var plan by remember { mutableStateOf<EmbyPlaybackPlan?>(null) }
var problem by remember { mutableStateOf<String?>(null) }
val record = remember { PlaybackTestRecord() }
val subtitles = remember { mutableStateOf<String?>(SUBTITLES_BY_DEFAULT) }
// Starts from the subtitles setting exactly as a channel visit does, so the test shows what a viewer would get.
val subtitles = remember { mutableStateOf(if (OrbitSettings(context).subtitlesOn) SUBTITLES_BY_DEFAULT else null) }
val startedAt = remember { android.os.SystemClock.elapsedRealtime() }
var ended by remember { mutableStateOf(false) }
fun finish(reason: String) {
@@ -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.15")
next.setRequestProperty("User-Agent", "OrbitTV/0.99.16")
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()) {
@@ -30,13 +30,32 @@ internal data class ChannelEntry(val digits: List<Int>, val slot: Int = 0) {
/** The setting's choice: English where a programme has it, and otherwise none, so a foreign track never appears unasked. */
internal const val SUBTITLES_BY_DEFAULT = "default-english"
/** The viewer turned subtitles off by hand: unlike no choice at all (null), it stops [subtitleChoice] turning them on by itself. */
internal const val SUBTITLES_OFF = "off"
/** Subtitles stay on across programmes: the same language if it's there, otherwise the first track. */
internal fun subtitleFor(wanted: String?, languages: List<String>): Int? {
if (wanted == null || languages.isEmpty()) return null
if (wanted == null || wanted == SUBTITLES_OFF || languages.isEmpty()) return null
if (wanted == SUBTITLES_BY_DEFAULT) return languages.indexOfFirst { it.lowercase(java.util.Locale.ROOT).startsWith("en") }.takeIf { it >= 0 }
return languages.indexOf(wanted).takeIf { it >= 0 } ?: 0
}
private fun isEnglish(language: String) = language.trim().lowercase(java.util.Locale.ROOT).let { it == "en" || it == "eng" || it == "english" || it.startsWith("en-") }
/**
* Which subtitle track a programme opens with (approved by Paul on 4 November 2026, Stage D2). A choice the viewer has made
* wins: a language, or [SUBTITLES_OFF]. With none, the subtitles setting's choice applies ([SUBTITLES_BY_DEFAULT] when on).
* With the setting off and no choice made, a programme whose sound is all tagged as other languages, such as Japanese-only
* anime, opens with English subtitles if it has them. Untagged sound gets the benefit of the doubt and stays as before. This
* picks a track for this programme only: nothing is saved, so the next programme decides afresh.
*/
internal fun subtitleChoice(preference: String?, audioLanguages: List<String>, subtitleLanguages: List<String>): Int? = when {
preference != null -> subtitleFor(preference, subtitleLanguages)
audioLanguages.isNotEmpty() && audioLanguages.all { it.isNotBlank() && it.lowercase(java.util.Locale.ROOT) != "und" } && audioLanguages.none(::isEnglish) ->
subtitleFor(SUBTITLES_BY_DEFAULT, subtitleLanguages)
else -> null
}
@Composable
internal fun ChannelNumberBox(entry: ChannelEntry, problem: String?, modifier: Modifier = Modifier) {
val corner = RoundedCornerShape(6.dp)