0.108.8: read-only Premiere evidence and proposals in the Chair; booking off (built, not installed)
Evidence reader covers the last 12 months' films. The Chair weighs Orbit Premiere candidates and shows at most three a week, view-only, apart from its picks. No debut slots, windows or list changes on this line. Scoring matches main (horror-comedy refinement included). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -177,8 +177,6 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
|
||||
SeriesInspection.take()?.let { title -> runCatching { session.inspectSeries(title, store.loadFailed(userId)) }.getOrElse { listOf("inspect failed: ${it.javaClass.simpleName} ${(it as? EmbyCheckException)?.httpStatus} ${it.message?.take(160)}") }.forEach { Log.i("OrbitSchedule", it) } }
|
||||
val number = programming.number
|
||||
val now = clock()
|
||||
// A film whose premiere window has ended moves from Premiere's list to its home's, before either reads its list.
|
||||
runCatching { graduatePremieres(store, userId, now) }.onSuccess { if (it.isNotEmpty()) Log.i("OrbitSchedule", "premiere graduated channels=${it.sorted()}") }
|
||||
val cached = store.loadPool(userId, number)
|
||||
val choices = store.loadChoices(userId, number)
|
||||
val signature = "${programming.signature}#${choices.tag}"
|
||||
@@ -219,11 +217,6 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
|
||||
clashesWithAirings((SmartChannels.map { it.number }.filter { it != number } + DRIVE_IN_NUMBER).flatMap { airingsOn(userId, it) })
|
||||
.also { othersMs = android.os.SystemClock.elapsedRealtime() - began }
|
||||
}
|
||||
// Advent on Orbit: this channel's doors as fixed slots, from films verified on the box; every film channel holds them back.
|
||||
val fixed = (if (programming.filmRestMs != null && (AdventDoors.any { it.channel == number } || number == AFTER_DARK_NUMBER))
|
||||
adventFilms(userId, session, now).associateBy { it.id }.let { films -> adventSlots(number, films) + naughtySlots(number, films) } else emptyList()) +
|
||||
// Premiere's debuts, placed from the Director's Chair: fixed first showings that only append.
|
||||
(if (number == PREMIERE_NUMBER) premiereSlots(loadPremiereRuns(store.premiereRunsFile()), pool?.series.orEmpty().associateBy { it.id }) else emptyList())
|
||||
val plan = topUpPlan(existing, base, pool?.series?.let { withoutFailed(it, store.loadFailed(userId)) }, 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, stories = programming.storyGrouping) ?: throw EmbyCheckException("${programming.name} has no episodes to schedule.")
|
||||
|
||||
@@ -419,7 +419,9 @@ private fun ChairPopup(choice: ChairChoice, onPlace: (DeskOption) -> Unit, onDro
|
||||
else Text("Premiere booking switches on once you approve it", color = ChairGold, fontSize = 10.sp)
|
||||
}
|
||||
// Asks show both channels from the start; a pick shows its suggestion, and the other fits on Change channel.
|
||||
val shown = when { choice.ask || others -> choice.options; else -> choice.options.take(1) }
|
||||
// A Premiere proposal is view-only while booking is off: no placing, no dropping, nothing written.
|
||||
val viewOnly = choice.firstRun != null && !PREMIERE_BOOKING_ACTIVE
|
||||
val shown = when { viewOnly -> emptyList(); choice.ask || others -> choice.options; else -> choice.options.take(1) }
|
||||
shown.forEachIndexed { i, option ->
|
||||
Row(Modifier.fillMaxWidth().background(ChairPanel, RoundedCornerShape(6.dp)).padding(10.dp), verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
@@ -431,9 +433,9 @@ private fun ChairPopup(choice: ChairChoice, onPlace: (DeskOption) -> Unit, onDro
|
||||
}
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
if (!choice.ask && !others && choice.options.size > 1) OrbitButton("Change channel", onClick = { others = true })
|
||||
OrbitButton("Drop", if (choice.options.isEmpty()) Modifier.focusRequester(firstButton) else Modifier, onClick = onDrop)
|
||||
OrbitButton("Not now", onClick = onClose)
|
||||
if (!viewOnly && !choice.ask && !others && choice.options.size > 1) OrbitButton("Change channel", onClick = { others = true })
|
||||
if (!viewOnly) OrbitButton("Drop", if (choice.options.isEmpty()) Modifier.focusRequester(firstButton) else Modifier, onClick = onDrop)
|
||||
OrbitButton(if (viewOnly) "Close" else "Not now", if (viewOnly) Modifier.focusRequester(firstButton) else Modifier, onClick = onClose)
|
||||
}
|
||||
Text("Placing adds it to that channel's own list; it joins at the next top-up and nothing already booked changes. Drop keeps it off the Chair.",
|
||||
color = Muted, fontSize = 10.sp)
|
||||
|
||||
@@ -1,106 +1,13 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.time.DayOfWeek
|
||||
import java.time.Instant
|
||||
import java.time.LocalTime
|
||||
import java.time.ZoneId
|
||||
|
||||
/**
|
||||
* Premiere as a broadcast stage (Paul's policy, 5 November 2026): a new film placed from the Director's Chair can make its debut
|
||||
* on Orbit Premiere and then move to its genre home. Premiere is never a film's home. Its first showing is a fixed slot, branded
|
||||
* as a first airing on Orbit; for [PREMIERE_WINDOW_MS] after it, Premiere's own rotation may repeat it under its usual film rest;
|
||||
* then the film leaves Premiere's list and joins its home channel's, for that channel's future, uncommitted schedule. Nothing
|
||||
* already booked ever changes. Only a film never booked on Orbit can have a premiere.
|
||||
* Orbit Premiere on the 0.108 line: the constants the Director's Chair shows. Premiere booking (debut slots, windows, moving a
|
||||
* film to its home) needs the fixed-slot scheduler that arrives with the Advent release, and stays off until Paul approves it.
|
||||
*/
|
||||
internal const val PREMIERE_NUMBER = 301
|
||||
/** Premiere booking from the Chair: off until Paul approves the final candidate selection and window behaviour (5 November 2026). */
|
||||
internal const val PREMIERE_BOOKING_ACTIVE = false
|
||||
/** The default premiere window; a run can carry its own. */
|
||||
/** The default premiere window (proposed, configurable). */
|
||||
internal const val PREMIERE_WINDOW_MS = 28 * 24 * 60 * 60_000L
|
||||
/** A theatrical premiere's debut: its own label in What's On, apart from a series' FIRST ON ORBIT, so no film carries both. */
|
||||
/** A theatrical premiere's debut: its own label in What's On, apart from a series' FIRST ON ORBIT. */
|
||||
internal const val PREMIERE_WHY = "orbit premiere: debut"
|
||||
/** Debuts are on Friday and Saturday evenings at this time. */
|
||||
private val PREMIERE_DEBUT_AT: LocalTime = LocalTime.of(20, 0)
|
||||
/** A debut is kept this far from any other fixed slot on Premiere (an Advent door, another debut). */
|
||||
private const val DEBUT_GAP_MS = 4 * 60 * 60_000L
|
||||
|
||||
/** One film's premiere run: its debut, when its window ends, the home it moves to, and whether it has moved. */
|
||||
internal class PremiereRun(val id: String, val title: String, val home: Int, val debutMs: Long, val untilMs: Long, val graduated: Boolean = false) {
|
||||
fun toJson(): JSONObject = JSONObject().put("i", id).put("t", title).put("h", home).put("d", debutMs).put("u", untilMs).put("g", graduated)
|
||||
companion object { fun of(o: JSONObject) = PremiereRun(o.getString("i"), o.optString("t"), o.getInt("h"), o.getLong("d"), o.getLong("u"), o.optBoolean("g")) }
|
||||
}
|
||||
|
||||
internal fun loadPremiereRuns(file: File): List<PremiereRun> =
|
||||
runCatching { JSONArray(file.readText()).let { a -> (0 until a.length()).map { PremiereRun.of(a.getJSONObject(it)) } } }.getOrDefault(emptyList())
|
||||
|
||||
private val PremiereLock = Any()
|
||||
private fun savePremiereRuns(file: File, runs: List<PremiereRun>) {
|
||||
val temp = File(file.parentFile, file.name + ".tmp")
|
||||
temp.writeText(JSONArray(runs.map { it.toJson() }).toString()); if (!temp.renameTo(file)) { file.writeText(temp.readText()); temp.delete() }
|
||||
}
|
||||
|
||||
/**
|
||||
* The first Friday or Saturday at 20:00 after Premiere's committed plan ([planEndMs]), so the debut only ever appends; kept clear
|
||||
* of [otherSlots] (Advent doors, other debuts). Null if none within three weeks.
|
||||
*/
|
||||
internal fun debutSlot(planEndMs: Long, nowMs: Long, otherSlots: List<Long>, zone: ZoneId = ZoneId.systemDefault()): Long? {
|
||||
var day = Instant.ofEpochMilli(maxOf(planEndMs, nowMs)).atZone(zone).toLocalDate()
|
||||
repeat(21) {
|
||||
if (day.dayOfWeek == DayOfWeek.FRIDAY || day.dayOfWeek == DayOfWeek.SATURDAY) {
|
||||
val at = day.atTime(PREMIERE_DEBUT_AT).atZone(zone).toInstant().toEpochMilli()
|
||||
if (at > planEndMs && at > nowMs && otherSlots.none { kotlin.math.abs(it - at) < DEBUT_GAP_MS }) return at
|
||||
}
|
||||
day = day.plusDays(1)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Places a film on Premiere for its first run, moving to [home] after its window: Premiere's list takes it now (as an accepted
|
||||
* choice) and its debut is set as a fixed slot after Premiere's committed plan. Returns the debut, or null if no slot was free
|
||||
* (then nothing is changed).
|
||||
*/
|
||||
internal fun placePremiereFromChair(store: ScheduleStore, userId: String, id: String, title: String, year: Int?, home: Int, nowMs: Long = System.currentTimeMillis(),
|
||||
zone: ZoneId = ZoneId.systemDefault(), windowMs: Long = PREMIERE_WINDOW_MS): Long? = synchronized(PremiereLock) {
|
||||
require(EmbyClient.validId(id) && home != PREMIERE_NUMBER)
|
||||
val runs = loadPremiereRuns(store.premiereRunsFile())
|
||||
runs.firstOrNull { it.id == id }?.let { return@synchronized it.debutMs }
|
||||
// Booked on Orbit already (now or since the report was worked out): its first airing has been, so it has no premiere.
|
||||
if (id in store.loadBooked(userId)) return@synchronized null
|
||||
val doors = AdventDoors.filter { it.channel == PREMIERE_NUMBER }.map { it.at.atZone(zone).toInstant().toEpochMilli() }
|
||||
val debut = debutSlot(store.loadPlan(userId, PREMIERE_NUMBER)?.endMs ?: nowMs, nowMs, doors + runs.map { it.debutMs }, zone) ?: return@synchronized null
|
||||
val choices = store.loadChoices(userId, PREMIERE_NUMBER)
|
||||
if (choices.accepted.none { it.id == id })
|
||||
store.saveChoices(userId, PREMIERE_NUMBER, ChannelChoices(choices.accepted + Suggestion(id, title.take(160), year, "Movie", "", "Premiere run, placed by you from the Director's Chair"), choices.rejected - id))
|
||||
savePremiereRuns(store.premiereRunsFile(), runs + PremiereRun(id, title.take(160), home, debut, debut + windowMs))
|
||||
saveDecision(store.decisionsFile(), ChairDecision(id, title.take(160), "Movie", true, home, null, nowMs, premiere = true))
|
||||
debut
|
||||
}
|
||||
|
||||
/** Premiere's debuts still to come, as fixed slots, for films its pool has read (a film with no playable copy has none). */
|
||||
internal fun premiereSlots(runs: List<PremiereRun>, films: Map<String, PoolSeries>): List<FixedSlot> =
|
||||
runs.filter { !it.graduated }.mapNotNull { run -> films[run.id]?.let { FixedSlot(run.debutMs, it, "$PREMIERE_WHY; approved on the Director's Chair", "") } }
|
||||
|
||||
/**
|
||||
* Moves every film whose premiere window has ended to its home channel's list, and off Premiere's. Their bookings on Premiere,
|
||||
* committed already, stay as they are. Returns the channels whose lists changed.
|
||||
*/
|
||||
internal fun graduatePremieres(store: ScheduleStore, userId: String, nowMs: Long = System.currentTimeMillis()): Set<Int> = synchronized(PremiereLock) {
|
||||
val runs = loadPremiereRuns(store.premiereRunsFile())
|
||||
val due = runs.filter { !it.graduated && it.untilMs <= nowMs }
|
||||
if (due.isEmpty()) return@synchronized emptySet()
|
||||
val premiere = store.loadChoices(userId, PREMIERE_NUMBER)
|
||||
val leaving = premiere.accepted.filter { a -> due.any { it.id == a.id } }
|
||||
store.saveChoices(userId, PREMIERE_NUMBER, ChannelChoices(premiere.accepted - leaving.toSet(), premiere.rejected))
|
||||
due.forEach { run ->
|
||||
val film = leaving.firstOrNull { it.id == run.id } ?: return@forEach
|
||||
val home = store.loadChoices(userId, run.home)
|
||||
if (home.accepted.none { it.id == run.id })
|
||||
store.saveChoices(userId, run.home, ChannelChoices(home.accepted + film.copy(reason = "After its premiere run, placed by you from the Director's Chair"), home.rejected - run.id))
|
||||
}
|
||||
savePremiereRuns(store.premiereRunsFile(), runs.map { r -> if (due.any { it.id == r.id }) PremiereRun(r.id, r.title, r.home, r.debutMs, r.untilMs, true) else r })
|
||||
setOf(PREMIERE_NUMBER) + due.map { it.home }
|
||||
}
|
||||
|
||||
@@ -89,6 +89,8 @@ private val Uk = Regex("United Kingdom|England|Scotland|Wales|\\bUK\\b")
|
||||
private val UkStudio = Regex("\\bBBC\\b|\\bITV\\b|Channel 4|Film4|Sky\\b|Working Title|Ealing|Hammer|Aardman", RegexOption.IGNORE_CASE)
|
||||
private val EnglishCountries = Regex("United States|United Kingdom|Canada|Australia|Ireland|New Zealand|England|Scotland|Wales")
|
||||
private val ForeignBoard = Regex("^(SG|BR|PL|KR|JP|DE|FR|IT|ES|NL|TR|IN|MX|CN|HK|TW|TH|PH|MY|ID|RU|SE|NO|DK|FI|AR|CL|CO|PT|CZ|HU|RO|GR|IL|EG|SA|AE|VN)-", RegexOption.IGNORE_CASE)
|
||||
/** Mainstream audience ratings: a horror-comedy rated these (or for children) keeps its usual channels. */
|
||||
private val MainstreamRatings = setOf("PG-13", "12", "12A", "TV-14", "GB-12", "GB-12A", "GB-15", "15")
|
||||
private val HorrorComedy = Regex("\\b(body horror|body-horror|gross-out|splatter|horror-comedy|horror comedy)", RegexOption.IGNORE_CASE)
|
||||
private val LiveSpecial = Regex("\\b(stand-up|standup|comedian|comedy special|unruly set|in this set|live from|in concert|tour film|takes aim at)\\b", RegexOption.IGNORE_CASE)
|
||||
private val EventFilmWords = Regex("superhero|epic|franchise|saga|blockbuster", RegexOption.IGNORE_CASE)
|
||||
@@ -204,7 +206,9 @@ internal fun channelScore(e: TitleEvidence, b: Brief, text: ChannelText, links:
|
||||
} else { s += .15; ev += "no description (not held against it)" }
|
||||
// Paul, 5 November 2026: context over category. Horror played for laughs (a horror-comedy, body horror, gross-out) is After
|
||||
// Dark's cult territory, whatever its year, rather than mainstream Horror or Sci-Fi.
|
||||
val horrorComedy = "Horror" in g && ("Comedy" in g || HorrorComedy.containsMatchIn(all))
|
||||
// Paul, the same day: not every horror-comedy. A family-friendly or mainstream-rated one (PG-13, 12A and under) keeps its usual
|
||||
// channels; tone and audience still count. An unknown rating isn't held against it.
|
||||
val horrorComedy = "Horror" in g && ("Comedy" in g || HorrorComedy.containsMatchIn(all)) && "Family" !in g && rating !in KidsOk && rating !in MainstreamRatings
|
||||
if (!(horrorComedy && ch == 305)) e.year?.let { year ->
|
||||
val (lo, hi) = b.era
|
||||
if (year < lo - 3 || year > hi + 3) { if (!b.current) { s *= .3; ev += "$year outside its era $lo-$hi" } }
|
||||
|
||||
@@ -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.108.7\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.8\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -516,14 +516,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
}.onFailure { android.util.Log.w("OrbitSchedule", "director placeFailed=${it.javaClass.simpleName}") } } } },
|
||||
drop = { choice -> scope.launch(Dispatchers.IO) { runCatching { dropFromChair(scheduleStore, choice.id, choice.title, choice.type, choice.options.firstOrNull()?.number, premiere = choice.firstRun != null) }
|
||||
.onFailure { android.util.Log.w("OrbitSchedule", "director dropFailed=${it.javaClass.simpleName}") }; android.util.Log.i("OrbitSchedule", "director dropped") } },
|
||||
premiere = { choice, home -> val active = session
|
||||
if (active == null) "Not connected, so nothing was placed." else withContext(Dispatchers.IO) { runCatching {
|
||||
placePremiereFromChair(scheduleStore, active.accountId, choice.id, choice.title, choice.year, home.number)
|
||||
}.getOrNull() }.let { debut ->
|
||||
android.util.Log.i("OrbitSchedule", "director premiere home=${home.number} debut=${debut != null}")
|
||||
if (debut == null) "${choice.title} wasn't placed: it has been booked on Orbit already, or there was no free Friday or Saturday night in the next three weeks."
|
||||
else "${choice.title} premieres on Orbit Premiere ${java.time.Instant.ofEpochMilli(debut).atZone(java.time.ZoneId.systemDefault()).let { "%s %d %s at %02d:%02d".format(it.dayOfWeek.getDisplayName(java.time.format.TextStyle.FULL, java.util.Locale.UK), it.dayOfMonth, it.month.getDisplayName(java.time.format.TextStyle.FULL, java.util.Locale.UK), it.hour, it.minute) }}, then joins ${home.name}."
|
||||
} }) }, isOn = { scheduledChannels.containsKey(it) }, onSwitch = { programming, on -> setSmartSchedule(programming, on) }, onSuggestions = { openSuggestions(it) },
|
||||
premiere = { _, _ -> "Premiere booking is off until you approve it." }) }, isOn = { scheduledChannels.containsKey(it) }, onSwitch = { programming, on -> setSmartSchedule(programming, on) }, onSuggestions = { openSuggestions(it) },
|
||||
onSignOut = { job?.cancel(); closeSession(forget = true) }, windingDown = windingDown, onWindDown = { on ->
|
||||
val tots = scheduledChannels[TOTS_NUMBER]
|
||||
val active = session
|
||||
|
||||
@@ -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.108.7")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.108.8")
|
||||
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()) {
|
||||
|
||||
Reference in New Issue
Block a user