Evenings rotate twelve shows a week; files marked unplayable get one fresh try
A shaped channel's evening carries at most twelve shows a week, a different set each Monday until all have had theirs (Sakura's evening had 85, each on once). The unplayable list is set aside once now the player reads zlib subtitles (The Twilight Zone S1 E3); any still failing go back on it. 0.108.96. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -105,11 +105,13 @@ internal object CustomChannels {
|
||||
/** Roughly how long a first plan takes, from what it has to read: each series' episodes, a quick look for each film. */
|
||||
fun planMinutes(series: Int, films: Int) = ((series * 9 + films) / 60.0).let { kotlin.math.ceil(it).toInt() }.coerceAtLeast(1)
|
||||
|
||||
@Volatile private var cachedWeek = -1L
|
||||
@Volatile private var cached: Pair<List<CustomChannel>, List<ChannelProgramming>> = emptyList<CustomChannel>() to emptyList()
|
||||
/** Every channel of your own as the planner sees it. */
|
||||
val programmings: List<ChannelProgramming> get() {
|
||||
val now = list
|
||||
if (cached.first !== now) cached = now to now.map(::programmingOf)
|
||||
val now = list; val week = rotationWeek()
|
||||
// Remade when the list changes, and each week for the evening's rotation.
|
||||
if (cached.first !== now || cachedWeek != week) { cached = now to now.map(::programmingOf); cachedWeek = week }
|
||||
return cached.second
|
||||
}
|
||||
}
|
||||
@@ -125,7 +127,7 @@ internal fun programmingOf(channel: CustomChannel): ChannelProgramming = Channel
|
||||
// You chose these titles yourself, so they play in the sound they have: Sakura's anime is mostly Japanese with subtitles,
|
||||
// and asking for English sound left nearly all of it out (7 November 2026).
|
||||
englishAudio = false,
|
||||
dayParts = when (channel.style) { PlayStyle.Blocks -> timetableParts(channel.shows); PlayStyle.Shaped -> shapedParts(channel.slots); else -> emptyList() },
|
||||
dayParts = when (channel.style) { PlayStyle.Blocks -> timetableParts(channel.shows); PlayStyle.Shaped -> shapedParts(channel.slots, eveningPage = rotationWeek()); else -> emptyList() },
|
||||
storyGrouping = channel.style == PlayStyle.Standard || channel.style == PlayStyle.Shaped,
|
||||
shorts = if (channel.style == PlayStyle.Standard || channel.style == PlayStyle.Shaped) YoursShorts else null,
|
||||
tierWeights = if (channel.style == PlayStyle.Shaped && channel.core.isNotEmpty()) shapedWeights(channel.core) 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.95\"") +
|
||||
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.96\"") +
|
||||
(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.95\"" +
|
||||
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.96\"" +
|
||||
(token?.let { ", Token=\"$it\"" } ?: ""))
|
||||
}
|
||||
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
|
||||
|
||||
@@ -160,6 +160,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
var guideCategory by ui::guideCategory
|
||||
val liveHandoff = remember { LiveHandoff() }
|
||||
val scheduleStore = remember(workspace) { workspace.schedules }
|
||||
remember(scheduleStore) { runCatching { scheduleStore.retryFailedOnce() }; true }
|
||||
// Your own channels (Create your own) are this server's, read before anything plans or restores.
|
||||
remember(workspace) { CustomChannels.load(workspace.scheduleDir); true }
|
||||
val scheduler = remember(workspace) { ChannelScheduler(scheduleStore, copies = { if (catalogue.complete()) catalogue.idsByImdb(it) else null }, original = workspace.original) }
|
||||
|
||||
@@ -168,6 +168,14 @@ internal class ScheduleStore(private val directory: File) {
|
||||
/** Files that wouldn't play on this box, across every channel. Never planned again. */
|
||||
fun saveFailed(userId: String, ids: Set<String>) =
|
||||
write(file("failed", 0), root(userId, 0).put("items", JSONArray(ids.toList())))
|
||||
/**
|
||||
* Once, after the player learnt zlib subtitles (0.108.96, Paul, 7 November 2026: The Twilight Zone S1 E3), the files marked
|
||||
* unplayable get one fresh try: the list is set aside, and any that still fail go straight back on it.
|
||||
*/
|
||||
fun retryFailedOnce() {
|
||||
val list = file("failed", 0); val aside = File(directory, "failed-0.json.before-zlib")
|
||||
if (!aside.exists()) { if (list.exists()) list.renameTo(aside) else aside.writeText("") }
|
||||
}
|
||||
fun loadFailed(userId: String): Set<String> = read(file("failed", 0), userId, 0) { root ->
|
||||
val items = root.getJSONArray("items")
|
||||
(0 until items.length()).map { validId(items.getString(it)) }.toSet()
|
||||
|
||||
@@ -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.95")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.108.96")
|
||||
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()) {
|
||||
|
||||
@@ -230,9 +230,12 @@ internal fun weekCheck(series: Int, films: Int): String? = when {
|
||||
* never the late ones, so a late title stays late (Paul, 7 November 2026: the creator's choices and the profile's rules win).
|
||||
* With nothing laid out, everything plays all day.
|
||||
*/
|
||||
internal fun shapedParts(slots: Map<String, Slot>): List<DayPart> {
|
||||
internal fun shapedParts(slots: Map<String, Slot>, eveningPage: Long = 0): List<DayPart> {
|
||||
if (slots.isEmpty()) return emptyList()
|
||||
val bySlot = Slot.entries.associateWith { s -> slots.filterValues { it == s }.keys.toList() }
|
||||
val bySlot = Slot.entries.associateWith { s -> slots.filterValues { it == s }.keys.toList() }.toMutableMap()
|
||||
// Evenings are appointments (Paul, 7 November 2026: Sakura's evening had 85 shows, each on once a week): at most
|
||||
// EVENING_ROTATION shows a week, so each comes back most nights, and a different set the next week until all have had theirs.
|
||||
bySlot[Slot.Evening] = eveningRotation(bySlot.getValue(Slot.Evening), eveningPage)
|
||||
val gentle = bySlot.getValue(Slot.Daytime) + bySlot.getValue(Slot.Evening)
|
||||
return Slot.entries.mapNotNull { s ->
|
||||
val titles = bySlot.getValue(s).ifEmpty { if (s == Slot.Late) gentle + bySlot.getValue(Slot.Late) else gentle }
|
||||
@@ -240,6 +243,24 @@ internal fun shapedParts(slots: Map<String, Slot>): List<DayPart> {
|
||||
}
|
||||
}
|
||||
|
||||
/** How many shows a shaped channel's evening carries in a week. */
|
||||
internal const val EVENING_ROTATION = 12
|
||||
|
||||
/** This week's evening shows from [titles]: all of them when there are few, else the week's turn of [EVENING_ROTATION]. */
|
||||
internal fun eveningRotation(titles: List<String>, page: Long): List<String> {
|
||||
if (titles.size <= EVENING_ROTATION) return titles
|
||||
val sorted = titles.sortedBy { seriesKey(it) }
|
||||
val pages = (sorted.size + EVENING_ROTATION - 1) / EVENING_ROTATION
|
||||
// Spread evenly, so the last week isn't a handful of leftovers.
|
||||
val per = (sorted.size + pages - 1) / pages
|
||||
val k = Math.floorMod(page, pages.toLong()).toInt()
|
||||
return sorted.drop(k * per).take(per)
|
||||
}
|
||||
|
||||
/** Which week it is for the evening's rotation: Mondays turn it over. */
|
||||
internal fun rotationWeek(nowMs: Long = System.currentTimeMillis(), zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): Long =
|
||||
java.time.Instant.ofEpochMilli(nowMs).atZone(zone).toLocalDate().with(java.time.DayOfWeek.MONDAY).toEpochDay() / 7
|
||||
|
||||
/** "About 42 hours", for the week check: how long the picks run before anything repeats. */
|
||||
internal fun hoursLine(totalMs: Long): String = (totalMs / 3_600_000.0).let { h ->
|
||||
when { h < 1 -> "under an hour"; h < 10 -> "about %.0f hours".format(h).replace("about 1 hours", "about an hour"); else -> "about ${(h / 5).toInt() * 5} hours" }
|
||||
|
||||
Reference in New Issue
Block a user