Your channels: remove from the phone, and take turns in a mixed order

Each channel of your own gets an x on the phone's More page, asked first; the TV sets its files
aside so a new channel on that number starts clean. Shows and films on your own channels take
turns in a fixed mixed order rather than the order chosen (Mistletoe played its collection A to Z).
0.108.89.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-07 13:24:06 +00:00
co-authored by Claude Opus 5.5
parent 1bc38e7c86
commit 2ce22fe2e9
12 changed files with 71 additions and 10 deletions
@@ -51,6 +51,11 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
val shuffleEpisodes: Boolean = false,
/** Shows played in a mixed order on a channel that otherwise runs in season order, such as Paradox's standalone adventures. */
val shuffleTitles: Set<String> = emptySet(),
/**
* Shows and films take their turns in a fixed mixed order rather than the order they were chosen in. On for channels of
* your own (Paul, 7 November 2026: Mistletoe played the Hallmark Christmas collection A to Z).
*/
val mixedTurns: Boolean = false,
/** Films a series channel may carry, each only in an event that names it. Empty everywhere but Ring X. */
val channelFilms: List<String> = emptyList(),
/** Series a film channel may carry, each only in an event that names it, one whole episode a night in order. Empty everywhere but After Dark. */
@@ -379,6 +384,9 @@ internal fun dayPartFor(pool: List<PoolSeries>, parts: List<DayPart>, startMs: L
/** A few names and how many more, so a reason stays short. */
private fun someOf(names: List<String>) = names.take(3).joinToString(", ") + if (names.size > 3) " +${names.size - 3}" else ""
/** The pool in a mixed order that stays the same from one top-up to the next, so every title still gets its turn. */
internal fun mixedTurnOrder(pool: List<PoolSeries>, seed: Int): List<PoolSeries> = pool.sortedBy { it.id }.shuffled(java.util.Random(seed.toLong()))
internal fun turnOrder(pool: List<PoolSeries>, last: String?): List<PoolSeries> {
val after = pool.indexOfFirst { it.id == last } + 1
return (0 until pool.size).map { pool[(after + it) % pool.size] }
@@ -314,7 +314,7 @@ internal class ChannelScheduler(private val store: ScheduleStore,
clashesWithAirings((SmartChannels.map { it.number }.filter { it != number } + DRIVE_IN_NUMBER).flatMap { airingsOn(userId, it) })
.also { othersMs = android.os.SystemClock.elapsedRealtime() - began }
}
val plan = topUpPlan(existing, base, pool?.series?.let { withoutFailed(it, store.loadFailed(userId)) }, now, programming.filmRestMs, programming.finishTogether, programming.dayParts,
val plan = topUpPlan(existing, base, pool?.series?.let { withoutFailed(it, store.loadFailed(userId)) }?.let { if (programming.mixedTurns) mixedTurnOrder(it, number) else it }, now, programming.filmRestMs, programming.finishTogether, programming.dayParts,
avoid = { show, startMs, endMs -> others(show, startMs, endMs) }, shuffle = programming.shuffleEpisodes, mixed = programming::mixes,
weightOf = programming.tierWeights?.let { programming::weightOf }, adaptiveRest = programming.adaptiveFilmRest, fileRestMs = programming.fileRestMs, stories = programming.storyGrouping, shorts = programming.shorts, marathon = programming.marathon,
seasonEndMs = seasonEndMs(number, now)) ?: throw EmbyCheckException("${programming.name} has no episodes to schedule.")
@@ -58,7 +58,9 @@ internal class ChannelMaker(
/** Titles by item from the catalogue alone, quickly, for listing a collection. */
val rowsOf: suspend (List<String>) -> List<ShapeRow> = { emptyList() },
/** Networks and studios by name, with their title counts. */
val studios: suspend (String) -> List<Pair<String, Int>> = { emptyList() })
val studios: suspend (String) -> List<Pair<String, Int>> = { emptyList() },
/** Removes a channel of your own from every guide on this TV; what it says back. */
val remove: suspend (Int) -> String = { "That channel can't be removed here." })
/** One of the library's collections as Orbit read it. [complete] is false when it stopped short of [total]. */
internal class LibraryCollection(val name: String, val members: List<String>, val total: Int, val complete: Boolean)
@@ -108,7 +108,7 @@ internal object CustomChannels {
internal fun programmingOf(channel: CustomChannel): ChannelProgramming = ChannelProgramming(
channel.number, channel.name, emptyList(), seriesCount = 60,
finishTogether = channel.style == PlayStyle.Standard || channel.style == PlayStyle.Blocks || channel.style == PlayStyle.Shaped,
exactTitles = true, shuffleEpisodes = channel.style == PlayStyle.Shuffled,
exactTitles = true, shuffleEpisodes = channel.style == PlayStyle.Shuffled, mixedTurns = true,
dayParts = when (channel.style) { PlayStyle.Blocks -> timetableParts(channel.shows); PlayStyle.Shaped -> shapedParts(channel.slots); else -> emptyList() },
storyGrouping = channel.style == PlayStyle.Standard || channel.style == PlayStyle.Shaped,
shorts = if (channel.style == PlayStyle.Standard || channel.style == PlayStyle.Shaped) YoursShorts else null,
@@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
}
/** The sign-in headers for this kind of server. */
internal fun authHeaders(token: String?): Map<String, String> = when (kind) {
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.88\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.89\"") +
(token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap())
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.88\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.89\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -570,6 +570,19 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
android.util.Log.i("OrbitSchedule", "yours channel=${channel.number} style=${channel.style} titles=${shows.size}")
SmartChannels.firstOrNull { it.number == channel.number }?.let { setSmartSchedule(it, true) }
"${channel.name} is ready on ${channel.number}. Its first programmes are being planned now."
},
remove = { number ->
val gone = CustomChannels.of(number) ?: return@ChannelMaker "That channel has already gone."
withContext(Dispatchers.IO) {
scheduler.setEnabled(active.accountId, number, false)
CustomChannels.remove(workspace.scheduleDir, number)
scheduleStore.setAside(number)
}
scheduledChannels = scheduledChannels - number
extraChannels = extraChannels.filter { it.number != number }
if (selectedNumber == number) { selectedNumber = lastNumber.takeIf { it != number } ?: 101; channelClockOffset = 0 }
android.util.Log.i("OrbitSchedule", "yours removed channel=$number")
"${gone.name} has been removed from $number."
}) } }
// The phone page (Create your own from a phone) asks the same of this screen as Settings does, and can tune the TV.
DisposableEffect(channelMaker) {
@@ -386,6 +386,13 @@ internal object PhoneLink {
val said = runBlocking { withContext(mainDispatcher) { h.maker.create(laidOut, shows) } }
json(out, 200, JSONObject().put("message", said).put("number", number))
}
"POST /api/channels/remove" -> {
if (!OrbitCompanion.grownUp) return json(out, 403, JSONObject().put("error", "Kids is watching. Switch to Adult to remove channels."))
val number = runCatching { JSONObject(r.body).getInt("number") }.getOrNull()?.takeIf { n -> CustomChannels.list.any { it.number == n } }
?: return json(out, 404, JSONObject().put("error", "That channel has already gone."))
val said = runBlocking { withContext(mainDispatcher) { h.maker.remove(number) } }
json(out, 200, JSONObject().put("message", said))
}
"POST /api/watch" -> {
val number = runCatching { JSONObject(r.body).getInt("number") }.getOrNull() ?: return json(out, 400, JSONObject())
runBlocking { withContext(mainDispatcher) { h.watch(number) } }
@@ -235,6 +235,15 @@ internal class ScheduleStore(private val directory: File) {
/** Only when you ask for the guide to change now. The saved place and your choices stay. */
fun deletePlan(number: Int) { listOf("schedule-$number.json", "schedule-$number.json.prev").forEach { File(directory, it).delete() } }
/**
* A channel of your own removed (Paul, 7 November 2026): its files are set aside with ".removed", so a new channel given
* the same number starts clean and nothing of the old one comes back, while a removal by mistake can still be undone by hand.
*/
fun setAside(number: Int) {
listOf("episodes", "schedule", "progress", "choices").flatMap { listOf("$it-$number.json", "$it-$number.json.prev") }
.map { File(directory, it) }.filter { it.exists() }.forEach { it.renameTo(File(directory, it.name + ".removed")) }
}
/** Bytes held for a channel, for the measurements. */
fun sizes(number: Int) = listOf("episodes", "schedule", "progress", "choices").associateWith { file(it, number).length() }
@@ -39,7 +39,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.108.88")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.89")
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()) {