0.81.0: Orbit Tots, with shuffled episodes, day-part idents and Wind Down Now
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId = "tv.orbit.classic"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 90
|
||||
versionName = "0.80.0-blender-idents"
|
||||
versionCode = 91
|
||||
versionName = "0.81.0-orbit-tots"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
|
||||
|
||||
@@ -14,6 +14,7 @@ internal object ChannelBrands {
|
||||
308 to ChannelBranding("orbit-detour", "Orbit Detour", R.drawable.orbit_detour_epg, R.drawable.orbit_one_background, R.drawable.orbit_detour_bug, ChannelCategory.Movies),
|
||||
309 to ChannelBranding("orbit-britx", "Orbit BritX", R.drawable.orbit_britx_epg, R.drawable.orbit_one_background, R.drawable.orbit_britx_bug, ChannelCategory.Movies),
|
||||
611 to ChannelBranding("orbit-junior", "Orbit Junior", R.drawable.orbit_junior_epg, R.drawable.orbit_one_background, R.drawable.orbit_junior_bug, ChannelCategory.Kids),
|
||||
TOTS_NUMBER to ChannelBranding("orbit-tots", "Orbit Tots", R.drawable.orbit_tots_epg, R.drawable.orbit_one_background, R.drawable.orbit_tots_bug, ChannelCategory.Kids),
|
||||
203 to ChannelBranding("orbit-wild", "Orbit Wild", R.drawable.orbit_wild_epg, R.drawable.orbit_one_background, R.drawable.orbit_wild_bug, ChannelCategory.Documentaries),
|
||||
102 to ChannelBranding("orbit-2", "Orbit 2", R.drawable.orbit_2_epg, R.drawable.orbit_one_background, R.drawable.orbit_2_bug, ChannelCategory.Entertainment),
|
||||
612 to ChannelBranding("wonder", "Orbit Wonder", R.drawable.wonder_epg, R.drawable.orbit_one_background, R.drawable.wonder_bug, ChannelCategory.Kids),
|
||||
|
||||
@@ -19,7 +19,9 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
||||
val dayParts: List<DayPart> = emptyList(),
|
||||
val suggestionRules: List<SuggestionRule> = emptyList(),
|
||||
/** Leave out episodes with no English sound. Off where subtitled shows belong, like Vortex's anime. */
|
||||
val englishAudio: Boolean = true) {
|
||||
val englishAudio: Boolean = true,
|
||||
/** Each show's episodes in a mixed order, all of them before any repeats. Everything else runs in season order. */
|
||||
val shuffleEpisodes: Boolean = false) {
|
||||
/** Changes when the list does, so the episode cache is read again. What's already committed stays. */
|
||||
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount"
|
||||
}
|
||||
@@ -58,6 +60,7 @@ internal val SmartChannels = listOf(
|
||||
"Life on Earth", "The Living Planet", "The Trials of Life", "Our Planet", "Our Planet II", "Dynasties", "Dynasties II", "Seven Worlds, One Planet", "A Perfect Planet",
|
||||
"Hostile Planet", "Africa", "Wild China", "South Pacific", "Great Barrier Reef", "The Hunt", "The Life of Mammals", "The Life of Birds", "Nature's Great Events", "Green Planet", "Prehistoric Planet"),
|
||||
seriesCount = 20, finishTogether = true, exactTitles = true),
|
||||
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = TotsDayParts, shuffleEpisodes = true),
|
||||
ChannelProgramming(106, "Paradox", ChannelPresets.first { it.number == 106 }.searches)) +
|
||||
ChannelPresets.filter { it.smartOnly }.map { ChannelProgramming(it.number, it.name, it.searches, seriesCount = if (it.films) it.searches.size else 60, finishTogether = !it.films, exactTitles = true,
|
||||
filmRestMs = if (it.films) 7 * 24 * 60 * 60_000L else null,
|
||||
@@ -123,6 +126,9 @@ internal const val SCHEDULE_KEEP_PAST_MS = 24 * 60 * 60_000L
|
||||
internal fun nextEpisode(series: PoolSeries, last: EpisodeMark?): PoolEpisode =
|
||||
last?.let { mark -> series.episodes.firstOrNull { it.mark > mark } } ?: series.episodes.first()
|
||||
|
||||
/** The same mix every time, so a place in it can be saved as an episode. */
|
||||
internal fun shuffledEpisodes(series: PoolSeries): List<PoolEpisode> = series.episodes.shuffled(java.util.Random(series.id.hashCode().toLong()))
|
||||
|
||||
/**
|
||||
* What a programme starting at [startMs] may use, by the local hour then, so the clocks changing moves blocks with the wall clock.
|
||||
* A block with nothing in the pool leaves the whole pool, so a channel never goes off air for lack of a title.
|
||||
@@ -195,21 +201,28 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
|
||||
|
||||
/** Shows take turns, one episode each, back to back from [fromMs] until [untilMs] is covered. */
|
||||
internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, fromMs: Long, untilMs: Long, filmRestMs: Long? = null, finishTogether: Boolean = false,
|
||||
dayParts: List<DayPart> = emptyList(), zone: java.time.ZoneId = java.time.ZoneId.systemDefault(), avoid: ProgrammeClash = { _, _, _ -> false }): ChannelPlan {
|
||||
dayParts: List<DayPart> = emptyList(), zone: java.time.ZoneId = java.time.ZoneId.systemDefault(), avoid: ProgrammeClash = { _, _, _ -> false }, shuffle: Boolean = false): ChannelPlan {
|
||||
require(pool.isNotEmpty() && pool.all { it.episodes.isNotEmpty() })
|
||||
if (filmRestMs != null) return extendFilmSchedule(pool, cursor, fromMs, untilMs, filmRestMs, dayParts, zone, avoid)
|
||||
val marks = cursor.marks.toMutableMap()
|
||||
val entries = mutableListOf<ScheduleEntry>()
|
||||
var last = cursor.lastSeriesId
|
||||
var start = fromMs
|
||||
val mixes = HashMap<String, List<PoolEpisode>>()
|
||||
fun running(show: PoolSeries) = if (shuffle) mixes.getOrPut(show.id) { shuffledEpisodes(show) } else show.episodes
|
||||
fun following(show: PoolSeries): PoolEpisode {
|
||||
if (!shuffle) return nextEpisode(show, marks[show.id])
|
||||
val mix = running(show)
|
||||
return mix[(mix.indexOfFirst { it.mark == marks[show.id] } + 1) % mix.size]
|
||||
}
|
||||
while (start < untilMs) {
|
||||
val available = dayPartPool(pool, dayParts, start, zone)
|
||||
// Shows only wait for others in the same block, or a daytime show could stand idle for an evening one.
|
||||
if (finishTogether && available.all { marks[it.id] == it.episodes.last().mark }) available.forEach { marks.remove(it.id) }
|
||||
val allowed = { show: PoolSeries -> show in available && (!finishTogether || marks[show.id] != show.episodes.last().mark) }
|
||||
if (finishTogether && available.all { marks[it.id] == running(it).last().mark }) available.forEach { marks.remove(it.id) }
|
||||
val allowed = { show: PoolSeries -> show in available && (!finishTogether || marks[show.id] != running(show).last().mark) }
|
||||
// Skips a show already on elsewhere, unless that would leave nothing to show.
|
||||
val series = turnOrder(pool, last).firstOrNull { allowed(it) && !avoid(it, start, start + nextEpisode(it, marks[it.id]).durationMs) } ?: nextInTurn(pool, last, allowed)
|
||||
val episode = nextEpisode(series, marks[series.id])
|
||||
val series = turnOrder(pool, last).firstOrNull { allowed(it) && !avoid(it, start, start + following(it).durationMs) } ?: nextInTurn(pool, last, allowed)
|
||||
val episode = following(series)
|
||||
val item = if (series.isFilm) SampleItem(series.title, "Movie", episode.durationMs / 60_000, "", episode.id, episode.durationMs) else scheduledItem(series.title, episode)
|
||||
val media = ScheduledMedia(item, episode.sourceId, episode.durationMs)
|
||||
entries += ScheduleEntry(series.id, episode.mark, media, start)
|
||||
@@ -241,12 +254,12 @@ internal fun airedCursor(base: ScheduleCursor, entries: List<ScheduleEntry>, now
|
||||
* With no usable plan it starts from now at the aired position.
|
||||
*/
|
||||
internal fun topUpPlan(existing: ChannelPlan?, aired: ScheduleCursor, pool: List<PoolSeries>?, nowMs: Long, filmRestMs: Long? = null, finishTogether: Boolean = false,
|
||||
dayParts: List<DayPart> = emptyList(), zone: java.time.ZoneId = java.time.ZoneId.systemDefault(), avoid: ProgrammeClash = { _, _, _ -> false }): ChannelPlan? {
|
||||
dayParts: List<DayPart> = emptyList(), zone: java.time.ZoneId = java.time.ZoneId.systemDefault(), avoid: ProgrammeClash = { _, _, _ -> false }, shuffle: Boolean = false): ChannelPlan? {
|
||||
val kept = existing?.let { plan -> plan.copy(entries = plan.entries.dropWhile { it.endMs < nowMs - SCHEDULE_KEEP_PAST_MS }) }
|
||||
if (kept != null && kept.endMs >= nowMs + SCHEDULE_TOP_UP_MS) return kept
|
||||
if (pool.isNullOrEmpty()) return kept
|
||||
val from = if (kept != null && kept.endMs > nowMs) kept.endMs else nowMs
|
||||
val added = extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid)
|
||||
val added = extendSchedule(pool, existing?.tail ?: aired, from, nowMs + SCHEDULE_AHEAD_MS, filmRestMs, finishTogether, dayParts, zone, avoid, shuffle)
|
||||
return ChannelPlan(kept?.entries.orEmpty() + added.entries, added.tail)
|
||||
}
|
||||
|
||||
@@ -256,8 +269,11 @@ internal fun topUpPlan(existing: ChannelPlan?, aired: ScheduleCursor, pool: List
|
||||
*/
|
||||
internal class ScheduledChannel(val loop: SampleChannel, plan: ChannelPlan) : SampleChannel(loop.lineup, loop.name, loop.number) {
|
||||
@Volatile var plan: ChannelPlan = plan
|
||||
fun seriesIdAt(startMs: Long) = plan.entries.firstOrNull { it.startMs == startMs }?.seriesId
|
||||
/** Runs over the plan for a while, as Wind Down Now does, leaving the plan itself as it was. */
|
||||
@Volatile var stepIn: ChannelPlan? = null
|
||||
fun seriesIdAt(startMs: Long) = (stepIn?.entries.orEmpty() + plan.entries).firstOrNull { it.startMs == startMs }?.seriesId
|
||||
override fun at(timeMs: Long): SampleBroadcast {
|
||||
stepIn?.entries?.firstOrNull { timeMs >= it.startMs && timeMs < it.endMs }?.let { return SampleBroadcast(it.media, it.startMs) }
|
||||
val entries = plan.entries
|
||||
var low = 0
|
||||
var high = entries.lastIndex
|
||||
|
||||
@@ -15,9 +15,25 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
|
||||
fun load(userId: String, loop: SampleChannel): ScheduledChannel? {
|
||||
if (store.loadProgress(userId, loop.number)?.enabled != true) return null
|
||||
val plan = store.loadPlan(userId, loop.number)?.takeIf { it.entries.isNotEmpty() } ?: return null
|
||||
return ScheduledChannel(loop, plan)
|
||||
return ScheduledChannel(loop, plan).also { if (it.number == TOTS_NUMBER) it.stepIn = windDownPlan(userId) }
|
||||
}
|
||||
|
||||
/** Wind Down Now's plan, if one is still running. */
|
||||
fun windDownPlan(userId: String): ChannelPlan? = store.loadPlan(userId, TOTS_WIND_DOWN_FILE)?.takeIf { it.entries.isNotEmpty() && it.endMs > clock() }
|
||||
|
||||
/** Calm shows from [fromMs], the end of what's on now, until morning. Tots' own plan isn't touched, so stopping just removes this. */
|
||||
fun startWindDown(userId: String, fromMs: Long): ChannelPlan? {
|
||||
val calm = TotsWindDown.map(::seriesKey).toSet()
|
||||
val pool = withoutFailed(store.loadPool(userId, TOTS_NUMBER)?.series.orEmpty().filter { seriesKey(it.title) in calm }, store.loadFailed(userId))
|
||||
if (pool.isEmpty()) return null
|
||||
val others = clashesWith((SmartChannels.map { it.number }.filter { it != TOTS_NUMBER } + DRIVE_IN_NUMBER).mapNotNull { store.loadPlan(userId, it) })
|
||||
val plan = extendSchedule(pool, store.loadProgress(userId, TOTS_NUMBER)?.aired ?: ScheduleCursor(), fromMs, totsWindDownEnd(fromMs), finishTogether = true, avoid = others, shuffle = true)
|
||||
store.savePlan(userId, TOTS_WIND_DOWN_FILE, plan)
|
||||
return plan
|
||||
}
|
||||
|
||||
fun stopWindDown(userId: String) = store.savePlan(userId, TOTS_WIND_DOWN_FILE, ChannelPlan(emptyList(), ScheduleCursor()))
|
||||
|
||||
fun enabled(userId: String, number: Int) = store.loadProgress(userId, number)?.enabled == true
|
||||
|
||||
/** Going back to the loop keeps the schedule and the place, so turning it on again carries on. */
|
||||
@@ -89,7 +105,7 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
|
||||
// Other channels' plans are only read if this one is actually about to grow.
|
||||
val others by lazy { clashesWith((SmartChannels.map { it.number }.filter { it != number } + DRIVE_IN_NUMBER).mapNotNull { store.loadPlan(userId, it) }) }
|
||||
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) }) ?: throw EmbyCheckException("${programming.name} has no episodes to schedule.")
|
||||
avoid = { show, startMs, endMs -> others(show, startMs, endMs) }, shuffle = programming.shuffleEpisodes) ?: throw EmbyCheckException("${programming.name} has no episodes to schedule.")
|
||||
if (plan !== existing) store.savePlan(userId, number, plan)
|
||||
store.saveProgress(userId, number, ScheduleStore.SavedProgress(progress?.enabled ?: true, airedCursor(base, plan.entries, now)))
|
||||
session.rememberScheduledItems(plan.entries.map { it.media.item })
|
||||
|
||||
@@ -21,6 +21,8 @@ internal fun ChannelTuningBackdrop(number: Int, modifier: Modifier = Modifier, a
|
||||
Image(painterResource(branding.logo), null,
|
||||
Modifier.align(Alignment.TopStart).padding(start = 40.dp, top = 32.dp).width(200.dp).height(62.dp))
|
||||
}
|
||||
if (number == TOTS_NUMBER && totsMood(System.currentTimeMillis()).evening)
|
||||
Image(painterResource(R.drawable.orbit_tots_sleepy), null, Modifier.align(Alignment.Center).size(180.dp))
|
||||
ClassicTuningNumber(number, Modifier.align(Alignment.TopEnd).padding(top = 32.dp, end = 44.dp))
|
||||
Column(Modifier.align(Alignment.BottomStart).padding(start = 40.dp, bottom = 36.dp).background(Navy.copy(alpha = .78f)).padding(horizontal = 12.dp, vertical = 6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("Tuning…", color = Muted, fontSize = 17.sp)
|
||||
|
||||
@@ -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.80.0\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.81.0\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -88,6 +88,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
var tickets by remember { mutableStateOf<Map<Long, Int>>(emptyMap()) }
|
||||
var pendingDriveInWatch by remember { mutableStateOf(false) }
|
||||
var reminder by remember { mutableStateOf<DriveInReminder?>(null) }
|
||||
var windingDown by remember { mutableStateOf(false) }
|
||||
// Each visit opens on the next of the three scenes.
|
||||
var driveInVisits by remember { mutableIntStateOf((System.currentTimeMillis() / 60_000 % DRIVE_IN_SCENES).toInt()) }
|
||||
var guideCategory by remember { mutableStateOf(ChannelCategory.All) }
|
||||
@@ -236,6 +237,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
}
|
||||
}
|
||||
LaunchedEffect(Unit) { while (true) { now = System.currentTimeMillis(); delay(1000) } }
|
||||
LaunchedEffect(scheduledChannels) { windingDown = scheduledChannels[TOTS_NUMBER]?.stepIn?.let { it.endMs > System.currentTimeMillis() } == true }
|
||||
fun smartLoop(programming: ChannelProgramming) = (extraChannels + listOfNotNull(channel, afterDarkChannel, toonamiChannel)).firstOrNull { it.number == programming.number }
|
||||
// Keeps smart channels topped up in the background. A failure changes nothing on air.
|
||||
LaunchedEffect(session, extraChannels, channel, afterDarkChannel, toonamiChannel) {
|
||||
@@ -292,7 +294,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
val booked = driveInPlan
|
||||
while (booked != null) {
|
||||
val time = System.currentTimeMillis()
|
||||
val due = driveInReminderDue(driveInBills(booked), tickets, time)
|
||||
// Nothing pops up over Tots once it's winding down for the night.
|
||||
val due = driveInReminderDue(driveInBills(booked), tickets, time).takeUnless { watchingChannel && selectedNumber == TOTS_NUMBER && totsMood(time).evening }
|
||||
// Already watching it, so there's nothing to remind about.
|
||||
if (due != null && due.stage == 2 && watchingDriveIn) saveTickets(tickets + (due.bill.startMs to 2)) else if (due?.stage != reminder?.stage || due?.bill?.startMs != reminder?.bill?.startMs) reminder = due
|
||||
delay(5_000)
|
||||
@@ -451,7 +454,16 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
if (session != null) {
|
||||
SettingsScreen(settingsSection, { settingsSection = it }, modifier, busy, message, HttpsEmbyTransport.SERVER, sample?.total,
|
||||
isOn = { scheduledChannels.containsKey(it) }, onSwitch = { programming, on -> setSmartSchedule(programming, on) }, onSuggestions = { openSuggestions(it) },
|
||||
onSignOut = { job?.cancel(); closeSession(forget = true) })
|
||||
onSignOut = { job?.cancel(); closeSession(forget = true) }, windingDown = windingDown, onWindDown = { on ->
|
||||
val tots = scheduledChannels[TOTS_NUMBER]
|
||||
val active = session
|
||||
if (tots != null && active != null) scope.launch(Dispatchers.IO) {
|
||||
runCatching {
|
||||
tots.stepIn = if (on) scheduler.startWindDown(active.accountId, tots.at(System.currentTimeMillis()).endMs) else { scheduler.stopWindDown(active.accountId); null }
|
||||
windingDown = tots.stepIn != null
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
Box(modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
|
||||
@@ -45,6 +45,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
|
||||
/** Set while an ident covers the end of the show: drawn over everything, with the show itself quietened underneath. */
|
||||
ident: (@Composable () -> Unit)? = null) {
|
||||
val context = LocalContext.current
|
||||
val logoSetting = remember { OrbitSettings(context).channelLogo }
|
||||
var failure by remember { mutableStateOf<String?>(null) }
|
||||
var tuningNumberVisible by remember { mutableStateOf(announce) }
|
||||
var ready by remember { mutableStateOf(false) }
|
||||
@@ -316,7 +317,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
|
||||
ClassicTuningNumber(scheduled.channel.number,
|
||||
Modifier.align(Alignment.TopEnd).padding(top = 32.dp, end = 44.dp))
|
||||
// The channel's mark, off while the programme bar is up. It's drawn over the picture, never into it.
|
||||
val bug = scheduled?.let { ChannelBrands.forNumber(it.channel.number)?.bug }
|
||||
val bug = scheduled?.let { ChannelBrands.forNumber(it.channel.number)?.bug }?.takeIf { logoSetting }
|
||||
if (bug != null && ready && !infoVisible && failure == null)
|
||||
Image(painterResource(bug), null, Modifier.align(Alignment.BottomStart).padding(start = 40.dp, bottom = 28.dp).width(108.dp).height(36.dp), alpha = .8f)
|
||||
if (infoVisible && failure == null && ready) ClassicProgrammeStrip(plan.item, playing,
|
||||
|
||||
@@ -37,8 +37,13 @@ private val IdentVideos = mapOf(101 to R.raw.ident_101, 102 to R.raw.ident_102,
|
||||
306 to R.raw.ident_306, 307 to R.raw.ident_307, 308 to R.raw.ident_308, 309 to R.raw.ident_309, 401 to R.raw.ident_401, 601 to R.raw.ident_601, 602 to R.raw.ident_602, 603 to R.raw.ident_603, 604 to R.raw.ident_604, 605 to R.raw.ident_605,
|
||||
611 to R.raw.ident_611, 612 to R.raw.ident_612, 613 to R.raw.ident_613)
|
||||
|
||||
internal fun identVideo(number: Int) = IdentVideos[number]
|
||||
internal fun identLength(number: Int) = if (number in IdentVideos) IDENT_VIDEO_MS else IDENT_STING_MS
|
||||
/** [atMs] is when the next programme starts, for a channel whose ident follows the time of day. */
|
||||
internal fun identVideo(number: Int, atMs: Long = 0) = if (number == TOTS_NUMBER) totsMood(atMs).video else IdentVideos[number]
|
||||
internal fun identLength(number: Int, atMs: Long = 0) = when (number) {
|
||||
TOTS_NUMBER -> totsMood(atMs).lengthMs
|
||||
in IdentVideos -> IDENT_VIDEO_MS
|
||||
else -> IDENT_STING_MS
|
||||
}
|
||||
|
||||
internal enum class IdentPhase { None, LoadNext, Showing }
|
||||
|
||||
@@ -78,16 +83,21 @@ internal fun loadNextPlayer(context: Context, session: EmbySampleSession, plan:
|
||||
@Composable
|
||||
internal fun IdentOverlay(session: EmbySampleSession, channel: SampleChannel, next: SampleBroadcast, identMs: Long, startedLateMs: Long) {
|
||||
val context = LocalContext.current
|
||||
val mood = if (channel.number == TOTS_NUMBER) totsMood(next.startMs) else null
|
||||
val settings = remember { OrbitSettings(context) }
|
||||
val fade = remember { Animatable(0f) }
|
||||
LaunchedEffect(Unit) { fade.animateTo(1f, tween(400)) }
|
||||
LaunchedEffect(Unit) { fade.animateTo(1f, tween(mood?.fadeMs ?: 400)) }
|
||||
Box(Modifier.fillMaxSize().graphicsLayer { alpha = fade.value }.background(Navy)) {
|
||||
val video = identVideo(channel.number)
|
||||
if (video != null) {
|
||||
val video = identVideo(channel.number, next.startMs)
|
||||
// With idents off, Tots still says goodbye with a picture that doesn't move.
|
||||
if (mood != null && !settings.idents) Image(painterResource(mood.still), null, Modifier.fillMaxSize())
|
||||
else if (video != null) {
|
||||
val player = remember(video) {
|
||||
ExoPlayer.Builder(context).build().apply {
|
||||
setMediaItem(MediaItem.fromUri(RawResourceDataSource.buildRawResourceUri(video)))
|
||||
seekTo(startedLateMs.coerceIn(0, identMs))
|
||||
volume = 0f; prepare(); playWhenReady = true
|
||||
volume = if (mood != null && settings.identSound && TotsJingle.take(mood, System.currentTimeMillis())) 1f else 0f
|
||||
prepare(); playWhenReady = true
|
||||
}
|
||||
}
|
||||
DisposableEffect(player) { onDispose { player.release() } }
|
||||
|
||||
@@ -53,8 +53,9 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
|
||||
else { stream?.discard(session); null }
|
||||
}
|
||||
val next = shows[1]
|
||||
val identMs = identLength(channel.number)
|
||||
val identsHere = channel is ScheduledChannel && clockOffsetMs == 0L && channel.number != DRIVE_IN_NUMBER && next.startMs == current.endMs
|
||||
val identMs = identLength(channel.number, next.startMs)
|
||||
val identsOn = remember { OrbitSettings(settingsContext).idents }
|
||||
val identsHere = channel is ScheduledChannel && clockOffsetMs == 0L && channel.number != DRIVE_IN_NUMBER && next.startMs == current.endMs && (identsOn || channel.number == TOTS_NUMBER)
|
||||
val phase = if (identsHere) identPhase(current.startMs, current.endMs, now, identMs) else IdentPhase.None
|
||||
val playerContext = androidx.compose.ui.platform.LocalContext.current
|
||||
var loaded by remember(channel) { mutableStateOf<LoadedNext?>(null) }
|
||||
|
||||
@@ -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.80.0")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.81.0")
|
||||
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()) {
|
||||
|
||||
@@ -37,6 +37,15 @@ internal class OrbitSettings(context: Context) {
|
||||
var subtitlesOn: Boolean
|
||||
get() = saved.getBoolean("subtitles_on", false)
|
||||
set(value) { saved.edit().putBoolean("subtitles_on", value).apply() }
|
||||
var channelLogo: Boolean
|
||||
get() = saved.getBoolean("channel_logo", true)
|
||||
set(value) { saved.edit().putBoolean("channel_logo", value).apply() }
|
||||
var idents: Boolean
|
||||
get() = saved.getBoolean("idents", true)
|
||||
set(value) { saved.edit().putBoolean("idents", value).apply() }
|
||||
var identSound: Boolean
|
||||
get() = saved.getBoolean("ident_sound", true)
|
||||
set(value) { saved.edit().putBoolean("ident_sound", value).apply() }
|
||||
}
|
||||
|
||||
internal enum class SettingsSection(val label: String, val icon: Int) {
|
||||
@@ -110,14 +119,39 @@ private fun ChannelsDetail(busy: Boolean, message: String?, isOn: (Int) -> Boole
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ViewingDetail(modifier: Modifier) {
|
||||
private fun ViewingDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Boolean) -> Unit, modifier: Modifier) {
|
||||
val context = LocalContext.current
|
||||
val settings = remember { OrbitSettings(context) }
|
||||
var subtitlesOn by remember { mutableStateOf(settings.subtitlesOn) }
|
||||
var channelLogo by remember { mutableStateOf(settings.channelLogo) }
|
||||
var idents by remember { mutableStateOf(settings.idents) }
|
||||
var identSound by remember { mutableStateOf(settings.identSound) }
|
||||
var confirming by remember { mutableStateOf(false) }
|
||||
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SettingLine("Subtitles", "Turn on English subtitles whenever you tune in, if the programme has them. You can still change them while watching, by pressing right.") {
|
||||
OrbitButton(if (subtitlesOn) "On" else "Off", Modifier.width(64.dp), selected = subtitlesOn, onClick = { subtitlesOn = !subtitlesOn; settings.subtitlesOn = subtitlesOn })
|
||||
}
|
||||
SettingLine("Channel logo", "Show the channel's small logo in the corner during programmes.") {
|
||||
OrbitButton(if (channelLogo) "On" else "Off", Modifier.width(64.dp), selected = channelLogo, onClick = { channelLogo = !channelLogo; settings.channelLogo = channelLogo })
|
||||
}
|
||||
SettingLine("Idents", "Play each channel's ident between programmes. When off, Tots shows a still picture instead.") {
|
||||
OrbitButton(if (idents) "On" else "Off", Modifier.width(64.dp), selected = idents, onClick = { idents = !idents; settings.idents = idents })
|
||||
}
|
||||
SettingLine("Ident sound", "Let Tots play its jingle, at most once every 30 minutes.") {
|
||||
OrbitButton(if (identSound) "On" else "Off", Modifier.width(64.dp), selected = identSound, onClick = { identSound = !identSound; settings.identSound = identSound })
|
||||
}
|
||||
if (totsOn) {
|
||||
if (confirming) SettingLine(if (windingDown) "Go back to Tots' usual schedule now?" else "Start Wind Down on Tots?", if (windingDown) "The programme on Tots changes straight away." else "Calm shows begin when the current programme ends, and run until morning unless you stop them.") {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
val keep = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { keep.requestFocus() }
|
||||
OrbitButton("Not now", Modifier.focusRequester(keep), onClick = { confirming = false })
|
||||
OrbitButton("Yes", onClick = { confirming = false; onWindDown(!windingDown) })
|
||||
}
|
||||
} else SettingLine("Wind Down Now", "Calm shows on Tots at any time of day. Tots' usual schedule stays saved.") {
|
||||
OrbitButton(if (windingDown) "On" else "Off", Modifier.width(64.dp), selected = windingDown, onClick = { confirming = true })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +181,8 @@ private fun AccountDetail(server: String, titles: Long?, onSignOut: () -> Unit,
|
||||
/** Everything behind the gear: a rail of sections on the left, and the chosen one beside it. */
|
||||
@Composable
|
||||
internal fun SettingsScreen(section: SettingsSection, onSection: (SettingsSection) -> Unit, modifier: Modifier, busy: Boolean, message: String?, server: String, titles: Long?,
|
||||
isOn: (Int) -> Boolean, onSwitch: (ChannelProgramming, Boolean) -> Unit, onSuggestions: (ChannelProgramming) -> Unit, onSignOut: () -> Unit) {
|
||||
isOn: (Int) -> Boolean, onSwitch: (ChannelProgramming, Boolean) -> Unit, onSuggestions: (ChannelProgramming) -> Unit, onSignOut: () -> Unit,
|
||||
windingDown: Boolean, onWindDown: (Boolean) -> Unit) {
|
||||
val firstFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { firstFocus.requestFocus() }
|
||||
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
@@ -161,7 +196,7 @@ internal fun SettingsScreen(section: SettingsSection, onSection: (SettingsSectio
|
||||
val detail = Modifier.weight(1f).fillMaxHeight()
|
||||
when (section) {
|
||||
SettingsSection.Channels -> ChannelsDetail(busy, message, isOn, onSwitch, onSuggestions, detail)
|
||||
SettingsSection.Viewing -> ViewingDetail(detail)
|
||||
SettingsSection.Viewing -> ViewingDetail(isOn(TOTS_NUMBER), windingDown, onWindDown, detail)
|
||||
SettingsSection.Account -> AccountDetail(server, titles, onSignOut, detail)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
internal const val TOTS_NUMBER = 614
|
||||
/** Where Wind Down Now keeps its plan. Never a channel of its own, so the guide and settings don't see it. */
|
||||
internal const val TOTS_WIND_DOWN_FILE = 6140
|
||||
private const val TOTS_JINGLE_GAP_MS = 30 * 60_000L
|
||||
private const val TOTS_DAY_STARTS = 6
|
||||
|
||||
/** Every title here is hand-approved, and spelled as the library spells it. */
|
||||
private val TotsMorning = listOf("Teletubbies", "Clifford the Big Red Dog", "Balamory (2026)", "Bluey (2018)", "Numberblocks", "Andy's Wild Adventures", "Andy's Dinosaur Adventures", "Andy's Baby Animals", "Something Special")
|
||||
private val TotsPlaytime = listOf("Peppa Pig", "Ben and Holly's Little Kingdom", "Paw Patrol", "Fireman Sam", "Digby Dragon", "Floogals", "Bob the Builder", "Peter Rabbit (2013)", "Shimmer and Shine",
|
||||
"Blaze and the Monster Machines", "Nella the Princess Knight", "Roary the Racing Car", "The Adventures of Paddington", "Rusty Rivets", "Noddy's Toyland Adventures", "Thomas & Friends: All Engines Go!",
|
||||
"Bananas In Pyjamas", "Angelina Ballerina", "Olivia", "Mr Men", "Hey Duggee", "Octonauts", "Go Jetters")
|
||||
internal val TotsWindDown = listOf("CBeebies Bedtime Stories", "In The Night Garden", "Clangers", "BeddyByes")
|
||||
|
||||
internal val TotsShows get() = TotsMorning + TotsPlaytime + TotsWindDown
|
||||
internal val TotsDayParts get() = listOf(DayPart(6, 9, TotsMorning), DayPart(9, 17, TotsMorning + TotsPlaytime), DayPart(17, 21, TotsWindDown), DayPart(21, 6, TotsWindDown))
|
||||
|
||||
internal enum class TotsMood(val video: Int, val still: Int, val lengthMs: Long, val fadeMs: Int, val sings: Boolean) {
|
||||
Morning(R.raw.ident_614_morning, R.drawable.orbit_tots_still_morning, 5_000, 400, true),
|
||||
Playtime(R.raw.ident_614_morning, R.drawable.orbit_tots_still_morning, 5_000, 400, false),
|
||||
WindDown(R.raw.ident_614_evening, R.drawable.orbit_tots_still_evening, 6_000, 800, true),
|
||||
Night(R.raw.ident_614_evening, R.drawable.orbit_tots_still_evening, 6_000, 800, false);
|
||||
val evening get() = this == WindDown || this == Night
|
||||
}
|
||||
|
||||
internal fun totsMood(atMs: Long, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()) = when (java.time.Instant.ofEpochMilli(atMs).atZone(zone).hour) {
|
||||
in 6 until 9 -> TotsMood.Morning
|
||||
in 9 until 17 -> TotsMood.Playtime
|
||||
in 17 until 21 -> TotsMood.WindDown
|
||||
else -> TotsMood.Night
|
||||
}
|
||||
|
||||
/** Wind Down Now always hands back by the start of the next morning. */
|
||||
internal fun totsWindDownEnd(fromMs: Long, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): Long {
|
||||
val from = java.time.Instant.ofEpochMilli(fromMs).atZone(zone)
|
||||
val today = from.toLocalDate().atTime(TOTS_DAY_STARTS, 0).atZone(zone)
|
||||
return (if (from.isBefore(today)) today else today.plusDays(1)).toInstant().toEpochMilli()
|
||||
}
|
||||
|
||||
/** A short episode can mean an ident every few minutes, so most stay silent. */
|
||||
internal object TotsJingle {
|
||||
@Volatile private var lastMs = Long.MIN_VALUE / 2
|
||||
fun take(mood: TotsMood, nowMs: Long): Boolean {
|
||||
if (!mood.sings || nowMs - lastMs < TOTS_JINGLE_GAP_MS) return false
|
||||
lastMs = nowMs
|
||||
return true
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
Binary file not shown.
@@ -163,7 +163,7 @@ class ChannelPresetsTest {
|
||||
}
|
||||
listOf(612, 613, 306, 303, 304, 302, 307, 301).forEach { assertNotNull(SmartChannels.first { channel -> channel.number == it }.filmRestMs) }
|
||||
assertEquals(ChannelCategory.Sport, ChannelBrands.forNumber(401)!!.category)
|
||||
assertEquals(29, SmartChannels.size)
|
||||
assertEquals(30, SmartChannels.size)
|
||||
}
|
||||
|
||||
@Test fun ringXKeepsItsWeeknightsAndFallsBackToTheVault() {
|
||||
@@ -194,7 +194,7 @@ class ChannelPresetsTest {
|
||||
|
||||
@Test fun everySmartChannelIsBrandedAndNumberedAfterTheMove() {
|
||||
SmartChannels.forEach { assertNotNull("${it.name} has no brand at ${it.number}", ChannelBrands.forNumber(it.number)) }
|
||||
assertEquals(OldChannelNumbers.values.toSet() - DRIVE_IN_NUMBER + 101, SmartChannels.map { it.number }.toSet())
|
||||
assertEquals(OldChannelNumbers.values.toSet() - DRIVE_IN_NUMBER + 101 + TOTS_NUMBER, SmartChannels.map { it.number }.toSet())
|
||||
}
|
||||
|
||||
@Test fun channelsSitInTheirBlocks() {
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
class TotsTest {
|
||||
private val zone = ZoneId.of("Europe/London")
|
||||
private fun at(hour: Int, day: Int = 3) = ZonedDateTime.of(2026, 11, day, hour, 0, 0, 0, zone).toInstant().toEpochMilli()
|
||||
private fun show(title: String, count: Int) = PoolSeries(title, title, (1..count).map { PoolEpisode("$title$it", "s", EpisodeMark(1, it), "E$it", 10 * 60_000L) })
|
||||
|
||||
@Test fun moodFollowsLocalHours() {
|
||||
assertEquals(TotsMood.Night, totsMood(at(5), zone))
|
||||
assertEquals(TotsMood.Morning, totsMood(at(6), zone))
|
||||
assertEquals(TotsMood.Playtime, totsMood(at(9), zone))
|
||||
assertEquals(TotsMood.WindDown, totsMood(at(17), zone))
|
||||
assertEquals(TotsMood.Night, totsMood(at(21), zone))
|
||||
}
|
||||
|
||||
@Test fun moodMovesWithTheClocks() {
|
||||
// 06:00 British Summer Time on the last Saturday of October, an hour earlier by the universal clock than in winter.
|
||||
val summer = ZonedDateTime.of(2026, 10, 24, 6, 0, 0, 0, zone).toInstant().toEpochMilli()
|
||||
assertEquals(TotsMood.Morning, totsMood(summer, zone))
|
||||
}
|
||||
|
||||
@Test fun onlyTheTwoMoodsSing() {
|
||||
assertFalse(TotsJingle.take(TotsMood.Playtime, 1_000_000_000L))
|
||||
assertFalse(TotsJingle.take(TotsMood.Night, 1_000_000_000L))
|
||||
}
|
||||
|
||||
@Test fun jingleWaitsThirtyMinutes() {
|
||||
val start = 2_000_000_000_000L
|
||||
assertTrue(TotsJingle.take(TotsMood.Morning, start))
|
||||
assertFalse(TotsJingle.take(TotsMood.Morning, start + 29 * 60_000L))
|
||||
assertTrue(TotsJingle.take(TotsMood.WindDown, start + 30 * 60_000L))
|
||||
}
|
||||
|
||||
@Test fun identFollowsTheNextProgramme() {
|
||||
assertEquals(TotsMood.Morning.video, identVideo(TOTS_NUMBER, at(7)))
|
||||
assertEquals(5_000L, identLength(TOTS_NUMBER, at(7)))
|
||||
assertEquals(6_000L, identLength(TOTS_NUMBER, at(18)))
|
||||
}
|
||||
|
||||
@Test fun everyEpisodePlaysOnceBeforeAnyRepeat() {
|
||||
val pool = listOf(show("a", 12), show("b", 12))
|
||||
val plan = extendSchedule(pool, ScheduleCursor(), at(10), at(10) + 24 * 10 * 60_000L, finishTogether = true, zone = zone, shuffle = true)
|
||||
assertEquals(24, plan.entries.size)
|
||||
assertEquals(24, plan.entries.map { it.media.item.id }.distinct().size)
|
||||
}
|
||||
|
||||
@Test fun shuffleIsMixedAndRepeatable() {
|
||||
val series = show("a", 40)
|
||||
assertEquals(shuffledEpisodes(series), shuffledEpisodes(series))
|
||||
assertNotEquals(series.episodes, shuffledEpisodes(series))
|
||||
}
|
||||
|
||||
@Test fun shuffleCarriesOnFromItsPlace() {
|
||||
val pool = listOf(show("a", 6))
|
||||
val first = extendSchedule(pool, ScheduleCursor(), at(10), at(10) + 30 * 60_000L, zone = zone, shuffle = true)
|
||||
val rest = extendSchedule(pool, first.tail, first.endMs, first.endMs + 30 * 60_000L, zone = zone, shuffle = true)
|
||||
assertEquals(6, (first.entries + rest.entries).map { it.media.item.id }.distinct().size)
|
||||
}
|
||||
|
||||
@Test fun otherChannelsStayInSeasonOrder() {
|
||||
val plan = extendSchedule(listOf(show("a", 5)), ScheduleCursor(), at(10), at(10) + 50 * 60_000L, zone = zone)
|
||||
assertEquals((1..5).toList(), plan.entries.map { it.mark.episode })
|
||||
}
|
||||
|
||||
@Test fun windDownEndsAtTheNextMorning() {
|
||||
assertEquals(at(6, 4), totsWindDownEnd(at(10), zone))
|
||||
assertEquals(at(6, 4), totsWindDownEnd(at(20), zone))
|
||||
assertEquals(at(6), totsWindDownEnd(at(2), zone))
|
||||
}
|
||||
|
||||
@Test fun eveningOnlyOffersCalmShows() {
|
||||
val calm = TotsWindDown.map(::seriesKey).toSet()
|
||||
TotsDayParts.filter { it.covers(18) || it.covers(23) }.forEach { part -> assertEquals(calm, part.titles.map(::seriesKey).toSet()) }
|
||||
}
|
||||
|
||||
@Test fun stepInCoversThePlanThenHandsBack() {
|
||||
val pool = listOf(show("a", 50))
|
||||
val main = extendSchedule(pool, ScheduleCursor(), at(10), at(14), zone = zone)
|
||||
val channel = ScheduledChannel(SampleChannel(main.entries.take(2).map { it.media }, "t", TOTS_NUMBER), main)
|
||||
val calm = listOf(show("calm", 5))
|
||||
channel.stepIn = extendSchedule(calm, ScheduleCursor(), at(11), at(11) + 50 * 60_000L, zone = zone)
|
||||
assertEquals("calm1", channel.at(at(11) + 1).media.item.id)
|
||||
assertTrue(channel.at(at(13)).media.item.id.startsWith("a"))
|
||||
assertEquals(main.entries.size, channel.plan.entries.size)
|
||||
channel.stepIn = null
|
||||
assertTrue(channel.at(at(11) + 1).media.item.id.startsWith("a"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user