Create: the Director takes the lead, plus Off, Undo and new arrivals
A big collection comes back in the Director's order, so the 200 a channel carries are its picks: the series with the most to watch and films from right across it. Picking a collection goes straight to the Director's plan, with every title by part of the day, to star, move or take off. Your channels get an Off switch and an Undo after removing; titles new to a channel's collection are offered in the Director's Chair. The tabs and action bar step aside while typing, so they no longer sit over the search. 0.108.90. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,7 +60,13 @@ internal class ChannelMaker(
|
||||
/** Networks and studios by name, with their title counts. */
|
||||
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." })
|
||||
val remove: suspend (Int) -> String = { "That channel can't be removed here." },
|
||||
/** Turns a channel of your own off (kept, with its place) or on again. */
|
||||
val power: suspend (Int, Boolean) -> String = { _, _ -> "That channel can't be changed here." },
|
||||
/** Brings back the channel removed a moment ago, as it was. */
|
||||
val restore: suspend (Int) -> String = { "That channel can't be brought back." },
|
||||
/** New titles from a channel's collection: added to it, or set aside as seen. */
|
||||
val arrivals: suspend (Int, List<String>, Boolean) -> String = { _, _, _ -> "That can't be done 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)
|
||||
@@ -179,7 +185,8 @@ internal fun CreateChannelFlow(maker: ChannelMaker, editing: CustomChannel?, onD
|
||||
// Editing on the TV keeps what the phone set: the season, and a shaped layout while the shows and style stay.
|
||||
val kept = editing?.takeIf { it.style == style && it.shows.toSet() == chosen.map { c -> c.title }.toSet() }
|
||||
val channel = CustomChannel(number, name.trim(), style, hours, description.trim(), chosen.map { it.title },
|
||||
slots = kept?.slots.orEmpty(), core = kept?.core.orEmpty(), season = editing?.season, brand = editing?.brand ?: brandPackFor(name))
|
||||
slots = kept?.slots.orEmpty(), core = kept?.core.orEmpty(), season = editing?.season, brand = editing?.brand ?: brandPackFor(name),
|
||||
collection = editing?.collection, seen = editing?.seen.orEmpty())
|
||||
onDone(runCatching { maker.create(channel, chosen) }.getOrElse { "That channel couldn't be made. Try again." })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,17 @@ internal data class CustomChannel(val number: Int, val name: String, val style:
|
||||
/** On air only through this part of the year, if you chose one (Paul, 7 November 2026: an optional choice, with dates). */
|
||||
val season: SeasonWindow? = null,
|
||||
/** An Orbit brand pack it wears ([BrandPacks]), or null for the plain Yours look. */
|
||||
val brand: String? = null) {
|
||||
val brand: String? = null,
|
||||
/**
|
||||
* The library collection it was made from, and that collection's titles as they were when you last looked, so the
|
||||
* Director's Chair can offer what has arrived since (Paul, 7 November 2026).
|
||||
*/
|
||||
val collection: String? = null, val seen: Set<String> = emptySet()) {
|
||||
init { require(number in YOURS_FIRST..YOURS_LAST && name.isNotBlank() && name.length <= 40) }
|
||||
fun toJson(): JSONObject = JSONObject().put("number", number).put("name", name).put("style", style.name).put("description", description)
|
||||
.put("hours", hours?.let { JSONObject().put("from", it.fromHour).put("to", it.toHour) } ?: JSONObject.NULL).put("shows", JSONArray(shows))
|
||||
.put("slots", JSONObject(slots.mapValues { it.value.name })).put("core", JSONArray(core.toList())).put("season", season?.toJson() ?: JSONObject.NULL).put("brand", brand ?: JSONObject.NULL)
|
||||
.put("collection", collection ?: JSONObject.NULL).put("seen", JSONArray(seen.toList()))
|
||||
companion object {
|
||||
fun fromJson(o: JSONObject) = CustomChannel(o.getInt("number"), o.getString("name").take(40),
|
||||
runCatching { PlayStyle.valueOf(o.optString("style")) }.getOrDefault(PlayStyle.Standard),
|
||||
@@ -56,7 +62,9 @@ internal data class CustomChannel(val number: Int, val name: String, val style:
|
||||
o.optJSONArray("shows")?.let { a -> (0 until minOf(a.length(), 200)).map { a.getString(it).take(160) } }.orEmpty(),
|
||||
o.optJSONObject("slots")?.let { m -> m.keys().asSequence().take(200).mapNotNull { k -> runCatching { k.take(160) to Slot.valueOf(m.getString(k)) }.getOrNull() }.toMap() }.orEmpty(),
|
||||
o.optJSONArray("core")?.let { a -> (0 until minOf(a.length(), 20)).map { a.getString(it).take(160) }.toSet() }.orEmpty(),
|
||||
SeasonWindow.of(o.optJSONObject("season")), o.optString("brand").takeIf { it in BrandPacks })
|
||||
SeasonWindow.of(o.optJSONObject("season")), o.optString("brand").takeIf { it in BrandPacks },
|
||||
o.optString("collection").takeIf { !o.isNull("collection") && it.isNotBlank() }?.take(120),
|
||||
o.optJSONArray("seen")?.let { a -> (0 until minOf(a.length(), COLLECTION_MAX)).map { a.getString(it) }.filter(EmbyClient::validId).toSet() }.orEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.89\"") +
|
||||
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.90\"") +
|
||||
(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.89\"" +
|
||||
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.90\"" +
|
||||
(token?.let { ", Token=\"$it\"" } ?: ""))
|
||||
}
|
||||
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
|
||||
|
||||
@@ -534,6 +534,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
}
|
||||
// Create your own from a phone and the Companion: kept here, before any screen returns early, so the phone can make
|
||||
// and edit channels from every section, not only while Settings is open (Paul, 7 November 2026).
|
||||
var lastRemoved by remember { mutableStateOf<Pair<CustomChannel, Long>?>(null) }
|
||||
val channelMaker = remember(session, workspace) { session?.let { active -> ChannelMaker(
|
||||
suggest = { description, chosen, skipped -> withContext(Dispatchers.IO) {
|
||||
val wish = wishOf(description)
|
||||
@@ -573,6 +574,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
},
|
||||
remove = { number ->
|
||||
val gone = CustomChannels.of(number) ?: return@ChannelMaker "That channel has already gone."
|
||||
lastRemoved = gone to System.currentTimeMillis()
|
||||
withContext(Dispatchers.IO) {
|
||||
scheduler.setEnabled(active.accountId, number, false)
|
||||
CustomChannels.remove(workspace.scheduleDir, number)
|
||||
@@ -583,6 +585,46 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
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."
|
||||
},
|
||||
power = { number, on ->
|
||||
val programming = SmartChannels.firstOrNull { it.number == number }
|
||||
when {
|
||||
programming == null -> "That channel has gone."
|
||||
busy -> "The TV is still planning another channel. Try again in a minute."
|
||||
on == scheduledChannels.containsKey(number) -> "${programming.name} is already ${if (on) "on" else "off"}."
|
||||
else -> { setSmartSchedule(programming, on); if (on) "${programming.name} is coming back on. Its programmes are being planned now." else "${programming.name} is off. Its place and shows are kept." }
|
||||
}
|
||||
},
|
||||
restore = { number ->
|
||||
val (gone, at) = lastRemoved ?: return@ChannelMaker "There's nothing to bring back."
|
||||
if (gone.number != number || System.currentTimeMillis() - at > 60_000L || CustomChannels.of(number) != null) return@ChannelMaker "That can't be brought back now."
|
||||
withContext(Dispatchers.IO) { scheduleStore.bringBack(number); CustomChannels.upsert(workspace.scheduleDir, gone) }
|
||||
lastRemoved = null
|
||||
android.util.Log.i("OrbitSchedule", "yours restored channel=$number")
|
||||
SmartChannels.firstOrNull { it.number == number }?.let { setSmartSchedule(it, true) }
|
||||
"${gone.name} is back on $number."
|
||||
},
|
||||
arrivals = { number, ids, add ->
|
||||
val ch = CustomChannels.of(number) ?: return@ChannelMaker "That channel has gone."
|
||||
val seen = ch.seen + ids
|
||||
if (!add) { withContext(Dispatchers.IO) { CustomChannels.upsert(workspace.scheduleDir, ch.copy(seen = seen)) }; return@ChannelMaker "Set aside. The Director won't offer those again." }
|
||||
val (have, rows) = withContext(Dispatchers.IO) { scheduleStore.loadChoices(active.accountId, number).accepted to catalogue.shapeRows(ids) }
|
||||
val fresh = rows.filter { r -> have.none { it.id == r.id } }.take((200 - have.size).coerceAtLeast(0))
|
||||
if (fresh.isEmpty()) { withContext(Dispatchers.IO) { CustomChannels.upsert(workspace.scheduleDir, ch.copy(seen = seen)) }
|
||||
return@ChannelMaker if (have.size >= 200) "${ch.name} already carries 200 titles. Remove some to make room." else "Those are already on ${ch.name}." }
|
||||
val shows = have + fresh.map { Suggestion(it.id, it.title, it.year, it.type, "", "New in ${ch.collection}") }
|
||||
// New titles take the slot the Director would give them; everything already laid out stays where it is.
|
||||
val slots = if (ch.style != PlayStyle.Shaped || ch.slots.isEmpty()) ch.slots else withContext(Dispatchers.IO) {
|
||||
val all = catalogue.shapeRows(shows.map { it.id }); val shape = shapeChannel(all); val titleOf = all.associate { it.id to it.title }
|
||||
ch.slots + fresh.mapNotNull { r -> shape.slots[r.id]?.let { r.title to it } ?: (titleOf[r.id]?.let { it to Slot.Evening }) }.toMap()
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
CustomChannels.upsert(workspace.scheduleDir, ch.copy(shows = shows.map { it.title }, slots = slots, seen = seen))
|
||||
scheduleStore.saveChoices(active.accountId, number, ChannelChoices(shows, scheduleStore.loadChoices(active.accountId, number).rejected))
|
||||
}
|
||||
android.util.Log.i("OrbitSchedule", "yours arrivals channel=$number added=${fresh.size}")
|
||||
SmartChannels.firstOrNull { it.number == number }?.takeIf { scheduledChannels.containsKey(number) }?.let { setSmartSchedule(it, true) }
|
||||
"${fresh.size} added to ${ch.name}. They join as it plans ahead; nothing already booked changes."
|
||||
}) } }
|
||||
// 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) {
|
||||
|
||||
@@ -332,7 +332,8 @@ internal object PhoneLink {
|
||||
"GET /api/browse" -> if (r.query["collection"] != null) {
|
||||
// From a collection: its actual members, as the library lists them, not a guess from its name.
|
||||
val c = runBlocking { h.maker.collections() }.firstOrNull { it.name == r.query["collection"] } ?: return json(out, 404, JSONObject().put("error", "That collection isn't in the library copy yet."))
|
||||
val rows = runBlocking { h.maker.rowsOf(c.members.take(1000)) }
|
||||
// In the Director's order: its picks first, so a channel's 200 are the best of the whole collection.
|
||||
val rows = directorOrder(runBlocking { h.maker.rowsOf(c.members.take(2000)) }, c.name.hashCode())
|
||||
json(out, 200, JSONObject().put("complete", c.complete).put("total", c.total).put("found", rows.size).put("items", JSONArray(rows.map { row -> suggestionJson(Suggestion(row.id, row.title, row.year, row.type, "",
|
||||
listOfNotNull(row.genres.take(2).joinToString(", ").ifEmpty { null }, row.rating.ifEmpty { null }).joinToString(" · ").ifEmpty { "In ${c.name}" })).put("band", ratingBand(row.rating).name) })))
|
||||
} else {
|
||||
@@ -379,13 +380,52 @@ internal object PhoneLink {
|
||||
val titleOf = shows.associate { it.id to it.title }
|
||||
// An Orbit brand pack: the one chosen, else the one the name matches ("Sakura" wears Orbit Sakura).
|
||||
val chosenBrand = if (o.has("brand")) o.optString("brand").takeIf { it in BrandPacks } else brandPackFor(channel.name)
|
||||
val seasoned = channel.copy(season = SeasonWindow.of(o.optJSONObject("season")), brand = chosenBrand)
|
||||
// Made from a collection: remember it and what it held, so its new arrivals can be offered later. An edit keeps them.
|
||||
val before = CustomChannels.of(number)
|
||||
val fromCollection = o.optString("collection").takeIf { it.isNotBlank() }?.let { name -> runBlocking { h.maker.collections() }.firstOrNull { it.name == name } }
|
||||
val seasoned = channel.copy(season = SeasonWindow.of(o.optJSONObject("season")), brand = chosenBrand,
|
||||
collection = fromCollection?.name ?: before?.collection, seen = fromCollection?.members?.toSet() ?: before?.seen.orEmpty())
|
||||
val laidOut = if (seasoned.style != PlayStyle.Shaped) seasoned else seasoned.copy(
|
||||
slots = o.optJSONObject("slots")?.let { m -> m.keys().asSequence().mapNotNull { id -> titleOf[id]?.let { t -> runCatching { t to Slot.valueOf(m.getString(id)) }.getOrNull() } }.toMap() }.orEmpty(),
|
||||
core = o.optJSONArray("core")?.let { a -> (0 until minOf(a.length(), 20)).mapNotNull { titleOf[a.getString(it)] }.toSet() }.orEmpty())
|
||||
val said = runBlocking { withContext(mainDispatcher) { h.maker.create(laidOut, shows) } }
|
||||
json(out, 200, JSONObject().put("message", said).put("number", number))
|
||||
}
|
||||
// Off keeps a channel and its place; on plans it again (Paul, 7 November 2026: an Off switch beside Remove).
|
||||
"POST /api/channels/power" -> {
|
||||
if (!OrbitCompanion.grownUp) return json(out, 403, JSONObject().put("error", "Kids is watching. Switch to Adult to change channels."))
|
||||
val o = runCatching { JSONObject(r.body) }.getOrNull() ?: return json(out, 400, JSONObject())
|
||||
val number = o.optInt("number").takeIf { n -> CustomChannels.list.any { it.number == n } } ?: return json(out, 404, JSONObject().put("error", "That channel has gone."))
|
||||
val said = runBlocking { withContext(mainDispatcher) { h.maker.power(number, o.optBoolean("on")) } }
|
||||
json(out, 200, JSONObject().put("message", said))
|
||||
}
|
||||
// Undo, for a few seconds after a removal: the channel and everything it had planned come back as they were.
|
||||
"POST /api/channels/restore" -> {
|
||||
if (!OrbitCompanion.grownUp) return json(out, 403, JSONObject().put("error", "Kids is watching. Switch to Adult to change channels."))
|
||||
val number = runCatching { JSONObject(r.body).getInt("number") }.getOrNull() ?: return json(out, 400, JSONObject())
|
||||
val said = runBlocking { withContext(mainDispatcher) { h.maker.restore(number) } }
|
||||
json(out, 200, JSONObject().put("message", said))
|
||||
}
|
||||
// New in a channel's collection since you last looked, for the Director's Chair on the phone.
|
||||
"GET /api/arrivals" -> {
|
||||
val cols = runBlocking { h.maker.collections() }.associateBy { it.name }
|
||||
val found = CustomChannels.list.mapNotNull { ch ->
|
||||
val col = ch.collection?.let { cols[it] } ?: return@mapNotNull null
|
||||
val fresh = col.members.filter { it !in ch.seen }.take(40)
|
||||
if (fresh.isEmpty()) null else Triple(ch, col, runBlocking { h.maker.rowsOf(fresh) }.take(12))
|
||||
}.filter { it.third.isNotEmpty() }
|
||||
json(out, 200, JSONObject().put("arrivals", JSONArray(found.map { (ch, col, rows) -> JSONObject().put("number", ch.number).put("channel", ch.name)
|
||||
.put("collection", col.name).put("room", (200 - ch.shows.size).coerceAtLeast(0))
|
||||
.put("titles", JSONArray(rows.map { row -> suggestionJson(Suggestion(row.id, row.title, row.year, row.type, "", "New in ${col.name}")) })) })))
|
||||
}
|
||||
"POST /api/arrivals" -> {
|
||||
if (!OrbitCompanion.grownUp) return json(out, 403, JSONObject().put("error", "Kids is watching. Switch to Adult for the Director."))
|
||||
val o = runCatching { JSONObject(r.body) }.getOrNull() ?: return json(out, 400, JSONObject())
|
||||
val number = o.optInt("number").takeIf { n -> CustomChannels.list.any { it.number == n } } ?: return json(out, 404, JSONObject().put("error", "That channel has gone."))
|
||||
val ids = runCatching { o.getJSONArray("ids").let { a -> (0 until minOf(a.length(), 40)).map { a.getString(it) }.filter(EmbyClient::validId) } }.getOrDefault(emptyList())
|
||||
val said = runBlocking { withContext(mainDispatcher) { h.maker.arrivals(number, ids, o.optBoolean("add")) } }
|
||||
json(out, 200, JSONObject().put("message", said))
|
||||
}
|
||||
"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 } }
|
||||
|
||||
@@ -244,6 +244,12 @@ internal class ScheduleStore(private val directory: File) {
|
||||
.map { File(directory, it) }.filter { it.exists() }.forEach { it.renameTo(File(directory, it.name + ".removed")) }
|
||||
}
|
||||
|
||||
/** Undo of [setAside], straight after: the channel's files come back as they were. */
|
||||
fun bringBack(number: Int) {
|
||||
directory.listFiles()?.filter { f -> listOf("episodes", "schedule", "progress", "choices").any { f.name.startsWith("$it-$number.json") } && f.name.endsWith(".removed") }
|
||||
?.forEach { it.renameTo(File(directory, it.name.removeSuffix(".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.89")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.108.90")
|
||||
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()) {
|
||||
|
||||
@@ -157,6 +157,25 @@ internal fun shapeChannel(rows: List<ShapeRow>): Shape {
|
||||
}
|
||||
|
||||
/** A Christmas channel's season, offered by the Director when most of the picks are Christmas titles; the choice is yours. */
|
||||
/**
|
||||
* A big collection in the order the Director would take it (Paul, 7 November 2026: "the Director needs to take control"),
|
||||
* so the first 200 are its picks rather than the first 200 by name. Series with the most to watch come first, as they carry
|
||||
* a channel; films are drawn in a mixed order so a run of films isn't A to J; the two are woven together in the
|
||||
* collection's own proportions. The same collection always comes out in the same order.
|
||||
*/
|
||||
internal fun directorOrder(rows: List<ShapeRow>, seed: Int): List<ShapeRow> {
|
||||
val series = rows.filter { it.type == "Series" }.sortedWith(compareByDescending<ShapeRow> { it.runMs ?: 0L }.thenBy { it.title })
|
||||
val films = rows.filter { it.type != "Series" }.sortedBy { it.id }.shuffled(java.util.Random(seed.toLong()))
|
||||
val out = ArrayList<ShapeRow>(rows.size)
|
||||
var s = 0; var f = 0
|
||||
while (s < series.size || f < films.size) {
|
||||
// Whichever kind is furthest behind its share goes next.
|
||||
val takeSeries = f >= films.size || (s < series.size && s.toDouble() / series.size <= f.toDouble() / films.size)
|
||||
out += if (takeSeries) series[s++] else films[f++]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
internal fun suggestSeason(rows: List<ShapeRow>): SeasonWindow? {
|
||||
val festive = rows.count { r -> Regex("(?i)christmas|xmas|holiday|noel|santa|mistletoe|snow").containsMatchIn(r.title) || "Christmas" in r.genres }
|
||||
return if (rows.size >= 3 && festive >= rows.size * .5) SeasonWindow(11, 1, 12, 31) else null
|
||||
|
||||
Reference in New Issue
Block a user