0.92.0: Joe Bob Saturdays (opt-in series on a film channel, After Dark only)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -286,4 +286,10 @@ internal val CultClassics = listOf("The Rocky Horror Picture Show", "Repo Man",
|
||||
* plays, as on any film channel; when none of its films are in the library at all, the channel's usual block carries on.
|
||||
*/
|
||||
internal val HorrorDayParts get() = listOf(DayPart(20, 2, SlasherSaturday, days = setOf(DayOfWeek.SATURDAY)))
|
||||
internal val AfterDarkEvents get() = listOf(DayPart(21, 1, BMovieThrowbacks, days = setOf(DayOfWeek.FRIDAY)), DayPart(21, 1, CultClassics, days = setOf(DayOfWeek.SUNDAY)))
|
||||
/**
|
||||
* After Dark's Saturday staple: one whole hosted episode, in order, running its full length however long. Its window opens at 20:00
|
||||
* because the film before it is usually still running: starting from the first slot after 20:00 lands it around 21:00.
|
||||
*/
|
||||
internal const val LAST_DRIVE_IN = "The Last Drive-in with Joe Bob Briggs"
|
||||
internal val AfterDarkEvents get() = listOf(DayPart(21, 1, BMovieThrowbacks, days = setOf(DayOfWeek.FRIDAY)), DayPart(20, 1, listOf(LAST_DRIVE_IN), days = setOf(DayOfWeek.SATURDAY)),
|
||||
DayPart(21, 1, CultClassics, days = setOf(DayOfWeek.SUNDAY)))
|
||||
|
||||
@@ -24,11 +24,13 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
||||
/** Each show's episodes in a mixed order, all of them before any repeats. Everything else runs in season order. */
|
||||
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()) {
|
||||
val shuffleTitles: Set<String> = emptySet(),
|
||||
/** 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. */
|
||||
val filmSeries: List<String> = emptyList()) {
|
||||
/** Whether a show plays its episodes in a mixed order here. */
|
||||
fun mixes(show: PoolSeries) = shuffleEpisodes || seriesKey(show.title) in shuffleTitles.mapTo(HashSet(), ::seriesKey)
|
||||
/** 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"
|
||||
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount" + if (filmSeries.isEmpty()) "" else "#series:${filmSeries.joinToString("|")}"
|
||||
}
|
||||
|
||||
/** Expect the unexpected: standalone adventures by day in a mixed order, cult drama in order in prime time, and the strange stuff late. */
|
||||
@@ -54,7 +56,7 @@ private val AfterDarkFilms = listOf("The Thing (1982)", "The Evil Dead (1983)",
|
||||
"Army of Darkness", "House (1977)", "The Holy Mountain", "Repo! The Genetic Opera")
|
||||
|
||||
internal val SmartChannels = listOf(
|
||||
ChannelProgramming(AFTER_DARK_NUMBER, "After Dark", AfterDarkFilms, seriesCount = AfterDarkFilms.size, filmRestMs = 7 * 24 * 60 * 60_000L,
|
||||
ChannelProgramming(AFTER_DARK_NUMBER, "After Dark", AfterDarkFilms, seriesCount = AfterDarkFilms.size, filmSeries = listOf(LAST_DRIVE_IN), filmRestMs = 7 * 24 * 60 * 60_000L,
|
||||
dayParts = AfterDarkEvents + listOf(DayPart(21, 5), DayPart(5, 21, listOf("The 'Burbs", "'Til Death Do Us Part (2017)", "Tremors (1990)", "The Lost Boys (1987)", "Fright Night (1985)", "Poltergeist (1982)", "Scream (1996)",
|
||||
"Escape from New York", "They Live", "Repo Man", "Donnie Darko", "From Dusk Till Dawn", "Creepshow", "Near Dark", "Halloween (1978)", "The Fog (1980)", "Blue Velvet",
|
||||
"The Wicker Man (1973)", "An American Werewolf in London", "Prince of Darkness"), group = "day")),
|
||||
@@ -235,9 +237,23 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
|
||||
val entries = mutableListOf<ScheduleEntry>()
|
||||
var last = cursor.lastSeriesId
|
||||
var start = fromMs
|
||||
val marks = cursor.marks.toMutableMap()
|
||||
while (start < untilMs) {
|
||||
val (available, block) = dayPartChoice(pool, dayParts, start, zone)
|
||||
val (film, why) = chooseFilm(available, shown, start, restMs, avoid)
|
||||
// An event naming only a series plays its next whole episode, once a night. Everywhere else is films only.
|
||||
val series = available.singleOrNull()?.takeIf { !it.isFilm && block.startsWith("event ") }
|
||||
if (series != null && shown[series.id]?.let { start - it < SERIES_NIGHT_MS } != true) {
|
||||
val episode = nextEpisode(series, marks[series.id])
|
||||
entries += ScheduleEntry(series.id, episode.mark, ScheduledMedia(scheduledItem(series.title, episode), episode.sourceId, episode.durationMs), start,
|
||||
"$block; next episode in order, played whole")
|
||||
marks[series.id] = episode.mark
|
||||
shown[series.id] = start
|
||||
last = series.id
|
||||
start += episode.durationMs
|
||||
continue
|
||||
}
|
||||
val films = available.filter { it.isFilm }.ifEmpty { pool.filter { it.isFilm } }.ifEmpty { available }
|
||||
val (film, why) = chooseFilm(films, shown, start, restMs, avoid)
|
||||
val copy = film.episodes.first()
|
||||
val item = SampleItem(film.title, "Movie", copy.durationMs / 60_000, "", copy.id, copy.durationMs)
|
||||
entries += ScheduleEntry(film.id, copy.mark, ScheduledMedia(item, copy.sourceId, copy.durationMs), start, "$block; $why")
|
||||
@@ -245,9 +261,12 @@ internal fun extendFilmSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor,
|
||||
last = film.id
|
||||
start += copy.durationMs
|
||||
}
|
||||
return ChannelPlan(entries, ScheduleCursor(last, cursor.marks, shown))
|
||||
return ChannelPlan(entries, ScheduleCursor(last, marks, shown))
|
||||
}
|
||||
|
||||
/** A series on a film channel airs at most once in this long, so a long event window still holds one episode. */
|
||||
private const val SERIES_NIGHT_MS = 12 * 60 * 60_000L
|
||||
|
||||
/** 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 }, shuffle: Boolean = false,
|
||||
|
||||
@@ -77,7 +77,7 @@ internal class ChannelScheduler(private val store: ScheduleStore, private val cl
|
||||
* A failed refresh keeps what's there, so a provider outage can't disturb what's committed.
|
||||
*/
|
||||
fun topUp(session: EmbySampleSession, userId: String, programming: ChannelProgramming, loop: SampleChannel, checkActive: () -> Unit = {}): SchedulerReport {
|
||||
SeriesInspection.take()?.let { title -> runCatching { session.inspectSeries(title) }.getOrElse { listOf("inspect failed: ${it.javaClass.simpleName}") }.forEach { Log.i("OrbitSchedule", it) } }
|
||||
SeriesInspection.take()?.let { title -> runCatching { session.inspectSeries(title) }.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()
|
||||
val cached = store.loadPool(userId, number)
|
||||
|
||||
@@ -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.91.1\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.92.0\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -195,7 +195,7 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
|
||||
val match = searchSeries(transport, userId, ::currentToken, title).candidates.filter { seriesKey(it.title) == seriesKey(title) }
|
||||
if (match.isEmpty()) return listOf("inspect \"$title\": no series of that name")
|
||||
return match.flatMap { series ->
|
||||
val reply = transport.execute(EmbyRequest("GET", "/Shows/${series.id}/Episodes?UserId=$userId&StartIndex=0&Limit=200&Fields=MediaSources,Chapters&EnableImages=false&EnableUserData=false",
|
||||
val reply = transport.execute(EmbyRequest("GET", "/Shows/${series.id}/Episodes?UserId=$userId&StartIndex=0&Limit=100&Fields=MediaSources,Chapters&EnableImages=false&EnableUserData=false",
|
||||
token = currentToken(), readTimeoutMs = WHOLE_SERIES_TIMEOUT_MS))
|
||||
EmbyClient.expectSuccess(reply.status, false)
|
||||
val body = EmbyClient.parse(reply.body)
|
||||
@@ -231,6 +231,16 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
|
||||
val film = lookup.film ?: continue
|
||||
if (pool.none { it.id == film.id }) { pool += film; found++ }
|
||||
}
|
||||
// A series this film channel carries in an event: read whole, like a series channel, kept as one series rather than as films.
|
||||
for (title in programming.filmSeries) {
|
||||
checkActive()
|
||||
requests++
|
||||
val match = searchSeries(transport, userId, ::currentToken, title).candidates.filter { seriesKey(it.title) == seriesKey(title) }.take(MAX_SERIES_COPIES)
|
||||
val read = match.map { copy -> readWholeSeries(transport, userId, ::currentToken, copy, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio) }
|
||||
val best = read.maxByOrNull { it.episodes.size }?.takeIf { it.episodes.isNotEmpty() }
|
||||
android.util.Log.i("OrbitSchedule", "channel=${programming.number} series=\"$title\" copies=${match.size} episodes=${best?.episodes?.size ?: 0}")
|
||||
if (best != null) pool += best
|
||||
}
|
||||
} else for (search in programming.searches) {
|
||||
if (pool.size == programming.seriesCount) break
|
||||
checkActive()
|
||||
|
||||
@@ -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.91.1")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.92.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()) {
|
||||
|
||||
Reference in New Issue
Block a user