Add weekday events and a Vortex Movie Night (0.48.0 in testing)
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 = 48
|
||||
versionName = "0.47.0-tighter-pools"
|
||||
versionCode = 49
|
||||
versionName = "0.48.0-movie-night"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
/** Local hours, wrapping past midnight, and the titles a channel may use then. No titles means everything in its pool. */
|
||||
internal data class DayPart(val fromHour: Int, val toHour: Int, val titles: List<String> = emptyList(), val group: String = "") {
|
||||
internal data class DayPart(val fromHour: Int, val toHour: Int, val titles: List<String> = emptyList(), val group: String = "",
|
||||
/** Set for an event: only these days, starting from its [fromHour] on each. List it before the everyday blocks. */
|
||||
val days: Set<java.time.DayOfWeek> = emptySet()) {
|
||||
fun covers(hour: Int) = if (fromHour <= toHour) hour in fromHour until toHour else hour >= fromHour || hour < toHour
|
||||
fun covers(hour: Int, day: java.time.DayOfWeek) = covers(hour) && (days.isEmpty() || day in days)
|
||||
}
|
||||
|
||||
/** What makes a channel itself. The engine below knows nothing about any particular channel. */
|
||||
@@ -42,8 +45,11 @@ internal val SmartChannels = listOf(
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Thriller", "Mystery"), 1975..2005, 6.5f, setOf("NC-17", "X"), 30, NotCultCinema + "Science Fiction", 70, 7.9f),
|
||||
SuggestionRule("late", "Late night", "Movie", listOf("Horror"), 1970..2010, 6f, emptySet(), 90, NotCultCinema, 70))),
|
||||
ChannelProgramming(103, "Vortex", VortexDaytime + VortexEvening, seriesCount = 40, finishTogether = true, exactTitles = true,
|
||||
dayParts = listOf(DayPart(6, 18, VortexDaytime, group = "day"), DayPart(18, 6, VortexEvening, group = "night")),
|
||||
dayParts = listOf(DayPart(20, 22, group = "movie", days = setOf(java.time.DayOfWeek.FRIDAY, java.time.DayOfWeek.SATURDAY)),
|
||||
DayPart(6, 18, VortexDaytime, group = "day"), DayPart(18, 6, VortexEvening, group = "night")),
|
||||
suggestionRules = listOf(
|
||||
SuggestionRule("movie", "Movie Night", "Movie", listOf("Animation"), 1985..2025, 5f, setOf("NC-17", "X"), 30, setOf("Documentary"), 30, titleContains = "Dragon Ball"),
|
||||
SuggestionRule("movie", "Movie Night", "Movie", listOf("Animation", "Action"), 1985..2015, 7f, setOf("NC-17", "X"), 30, setOf("Documentary", "Family"), 60),
|
||||
SuggestionRule("day", "Daytime", "Series", listOf("Animation", "Action"), 1985..2015, 7f, setOf("TV-MA"), 30),
|
||||
SuggestionRule("night", "Evening", "Series", listOf("Anime", "Action"), 1985..2020, 7f, setOf("TV-MA"), 30))),
|
||||
ChannelProgramming(140, "Terra", listOf("The Blue Planet", "Blue Planet II", "Planet Earth", "Planet Earth II", "Planet Earth III", "Frozen Planet", "Frozen Planet II",
|
||||
@@ -56,7 +62,10 @@ internal data class EpisodeMark(val season: Int, val episode: Int) : Comparable<
|
||||
override fun compareTo(other: EpisodeMark) = compareValuesBy(this, other, { it.season }, { it.episode })
|
||||
}
|
||||
internal data class PoolEpisode(val id: String, val sourceId: String, val mark: EpisodeMark, val title: String, val durationMs: Long)
|
||||
internal data class PoolSeries(val id: String, val title: String, val episodes: List<PoolEpisode>, val group: String = "")
|
||||
internal data class PoolSeries(val id: String, val title: String, val episodes: List<PoolEpisode>, val group: String = "") {
|
||||
/** A film is its own only episode. */
|
||||
val isFilm get() = episodes.size == 1 && episodes[0].id == id
|
||||
}
|
||||
|
||||
/** Where a channel has got to: the last episode of each show, and whose turn was last. */
|
||||
internal data class ScheduleCursor(val lastSeriesId: String? = null, val marks: Map<String, EpisodeMark> = emptyMap(),
|
||||
@@ -85,11 +94,16 @@ internal fun nextEpisode(series: PoolSeries, last: EpisodeMark?): PoolEpisode =
|
||||
* A block with nothing in the pool leaves the whole pool, so a channel never goes off air for lack of a title.
|
||||
*/
|
||||
internal fun dayPartPool(pool: List<PoolSeries>, parts: List<DayPart>, startMs: Long, zone: java.time.ZoneId): List<PoolSeries> {
|
||||
val hour = java.time.Instant.ofEpochMilli(startMs).atZone(zone).hour
|
||||
val part = parts.firstOrNull { it.covers(hour) } ?: return pool
|
||||
if (part.titles.isEmpty() && part.group.isEmpty()) return pool
|
||||
val titles = part.titles.map(::seriesKey).toSet()
|
||||
return pool.filter { seriesKey(it.title) in titles || (part.group.isNotEmpty() && it.group == part.group) }.ifEmpty { pool }
|
||||
val local = java.time.Instant.ofEpochMilli(startMs).atZone(zone)
|
||||
// An event with nothing to show gives way to the ordinary block for that time.
|
||||
for (part in parts.filter { it.covers(local.hour, local.dayOfWeek) }) {
|
||||
if (part.titles.isEmpty() && part.group.isEmpty()) return pool
|
||||
val titles = part.titles.map(::seriesKey).toSet()
|
||||
val allowed = pool.filter { seriesKey(it.title) in titles || (part.group.isNotEmpty() && it.group == part.group) }
|
||||
if (allowed.isNotEmpty()) return allowed
|
||||
}
|
||||
// A film saved for an event doesn't appear in everyday programming.
|
||||
return pool.filter { !it.isFilm || pool.all(PoolSeries::isFilm) }.ifEmpty { pool }
|
||||
}
|
||||
|
||||
/** The next show after [last] in the rota that [eligible] allows. */
|
||||
@@ -142,7 +156,8 @@ internal fun extendSchedule(pool: List<PoolSeries>, cursor: ScheduleCursor, from
|
||||
if (finishTogether && available.all { marks[it.id] == it.episodes.last().mark }) available.forEach { marks.remove(it.id) }
|
||||
val series = nextInTurn(pool, last) { it in available && (!finishTogether || marks[it.id] != it.episodes.last().mark) }
|
||||
val episode = nextEpisode(series, marks[series.id])
|
||||
val media = ScheduledMedia(scheduledItem(series.title, episode), episode.sourceId, episode.durationMs)
|
||||
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)
|
||||
marks[series.id] = episode.mark
|
||||
last = series.id
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.net.URLEncoder
|
||||
/** A plain rule for what suits a channel. Every suggestion it makes can be explained from these fields alone. */
|
||||
internal data class SuggestionRule(val group: String, val label: String, val type: String, val genres: List<String>,
|
||||
val years: IntRange, val minRating: Float, val excludeRatings: Set<String> = emptySet(), val limit: Int,
|
||||
val excludeGenres: Set<String> = emptySet(), val minMinutes: Int = 0, val maxRating: Float = 10f)
|
||||
val excludeGenres: Set<String> = emptySet(), val minMinutes: Int = 0, val maxRating: Float = 10f, val titleContains: String? = null)
|
||||
|
||||
internal data class Suggestion(val id: String, val title: String, val year: Int?, val type: String, val group: String, val reason: String,
|
||||
val sourceId: String? = null, val durationMs: Long? = null)
|
||||
@@ -56,7 +56,8 @@ internal fun findSuggestions(transport: EmbyTransport, userId: String, token: ()
|
||||
checkActive()
|
||||
requests++
|
||||
val genre = URLEncoder.encode(rule.genres.first(), "UTF-8")
|
||||
val reply = transport.execute(EmbyRequest("GET", "/Items?UserId=$userId&Recursive=true&IncludeItemTypes=${rule.type}&Genres=$genre&Years=${rule.years.joinToString(",")}" +
|
||||
val search = rule.titleContains?.let { "&SearchTerm=${URLEncoder.encode(it, "UTF-8")}" }.orEmpty()
|
||||
val reply = transport.execute(EmbyRequest("GET", "/Items?UserId=$userId&Recursive=true&IncludeItemTypes=${rule.type}&Genres=$genre$search&Years=${rule.years.joinToString(",")}" +
|
||||
"&MinCommunityRating=${rule.minRating}&SortBy=CommunityRating&SortOrder=Descending&StartIndex=${page * SUGGESTION_PAGE}&Limit=$SUGGESTION_PAGE" +
|
||||
"&Fields=Genres,MediaSources,ProductionYear,OfficialRating,CommunityRating&EnableImages=false&EnableUserData=false", token = token(), readTimeoutMs = WHOLE_SERIES_TIMEOUT_MS))
|
||||
EmbyClient.expectSuccess(reply.status, false)
|
||||
@@ -70,6 +71,7 @@ internal fun findSuggestions(transport: EmbyTransport, userId: String, token: ()
|
||||
if (!EmbyClient.validId(id) || title.isBlank() || row.optString("Type") != rule.type || id in alreadyInPool || id in rejected || id in found) continue
|
||||
val tags = row.optJSONArray("Genres")
|
||||
val genres = (0 until (tags?.length() ?: 0)).mapNotNull { tags?.optString(it) }.map { it.lowercase() }
|
||||
if (rule.titleContains != null && !title.contains(rule.titleContains, ignoreCase = true)) continue
|
||||
if (rule.genres.any { it.lowercase() !in genres } || rule.excludeGenres.any { it.lowercase() in genres }) continue
|
||||
val score = row.optDouble("CommunityRating", 0.0)
|
||||
if (score > rule.maxRating) continue
|
||||
|
||||
@@ -41,7 +41,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.47.0\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.48.0\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -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.47.0")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.48.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()) {
|
||||
|
||||
@@ -83,14 +83,14 @@ class ChannelSuggestionsTest {
|
||||
|
||||
@Test fun afterDarkAndVortexBlocksAcceptTheirGroups() {
|
||||
assertEquals("day", SmartChannels.first { it.number == 102 }.dayParts[1].group)
|
||||
assertEquals(listOf("day", "night"), SmartChannels.first { it.number == 103 }.dayParts.map { it.group })
|
||||
assertEquals(listOf("movie", "day", "night"), SmartChannels.first { it.number == 103 }.dayParts.map { it.group })
|
||||
}
|
||||
|
||||
@Test fun vortexKeepsPaulsToonamiPicksInTheRightBlocks() {
|
||||
val vortex = SmartChannels.first { it.number == 103 }
|
||||
val day = vortex.dayParts[0].titles.map(::seriesKey)
|
||||
val day = vortex.dayParts.first { it.group == "day" }.titles.map(::seriesKey)
|
||||
assertTrue(listOf("Batman Beyond", "Batman: The Animated Series", "ThunderCats", "The Powerpuff Girls", "Jonny Quest").all { seriesKey(it) in day })
|
||||
assertTrue(seriesKey("Dragon Ball Z") in vortex.dayParts[1].titles.map(::seriesKey))
|
||||
assertTrue(seriesKey("Dragon Ball Z") in vortex.dayParts.first { it.group == "night" }.titles.map(::seriesKey))
|
||||
assertEquals(vortex.searches.size, vortex.searches.distinct().size)
|
||||
assertTrue(vortex.seriesCount >= vortex.searches.size)
|
||||
}
|
||||
@@ -114,4 +114,58 @@ class ChannelSuggestionsTest {
|
||||
@Test fun vortexOnlyTakesExactTitles() {
|
||||
assertTrue(SmartChannels.first { it.number == 103 }.exactTitles)
|
||||
}
|
||||
|
||||
private val london = java.time.ZoneId.of("Europe/London")
|
||||
private fun at(d: Int, h: Int, m: Int = 0) = java.time.ZonedDateTime.of(2026, 11, d, h, m, 0, 0, london).toInstant().toEpochMilli()
|
||||
private fun show(id: String, group: String, n: Int = 200) = PoolSeries(id, id, (1..n).map { PoolEpisode("$id-$it", "s", EpisodeMark(1, it), "E$it", 24 * 60_000L) }, group)
|
||||
private fun film(id: String) = PoolSeries(id, id, listOf(PoolEpisode(id, "s$id", EpisodeMark(1, 1), id, 50 * 60_000L)), "movie")
|
||||
private val parts = listOf(DayPart(20, 22, group = "movie", days = setOf(java.time.DayOfWeek.FRIDAY)), DayPart(6, 18, group = "day"), DayPart(18, 6, group = "night"))
|
||||
private val vortexPool = listOf(show("c", "day"), show("a", "night"), film("m1"), film("m2"), film("m3"))
|
||||
private fun hour(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(london)
|
||||
|
||||
@Test fun moviesOnlyAirOnMovieNight() {
|
||||
val start = at(2, 7) // Monday
|
||||
val entries = extendSchedule(vortexPool, ScheduleCursor(), start, start + 7 * 24 * 3_600_000L, finishTogether = true, dayParts = parts, zone = london).entries
|
||||
val films = entries.filter { it.media.item.type == "Movie" }
|
||||
assertTrue(films.isNotEmpty())
|
||||
films.forEach { assertEquals(java.time.DayOfWeek.FRIDAY, hour(it.startMs).dayOfWeek); assertTrue(hour(it.startMs).hour in 20 until 22) }
|
||||
assertTrue(films.all { !it.media.item.title.contains(" / ") })
|
||||
}
|
||||
|
||||
@Test fun movieNightReplacesTheEveningBlockThenItComesBack() {
|
||||
val friday = at(6, 19)
|
||||
val entries = extendSchedule(vortexPool, ScheduleCursor(), friday, friday + 5 * 3_600_000L, finishTogether = true, dayParts = parts, zone = london).entries
|
||||
assertEquals("a", entries.first().seriesId)
|
||||
assertTrue(entries.any { it.media.item.type == "Movie" })
|
||||
assertEquals("a", entries.last().seriesId)
|
||||
}
|
||||
|
||||
@Test fun moviesTakeTurnsBeforeRepeating() {
|
||||
val start = at(2, 7)
|
||||
val films = extendSchedule(vortexPool, ScheduleCursor(), start, start + 21 * 24 * 3_600_000L, finishTogether = true, dayParts = parts, zone = london).entries.filter { it.media.item.type == "Movie" }.map { it.seriesId }
|
||||
assertEquals(films.take(3).toSet().size, 3)
|
||||
}
|
||||
|
||||
@Test fun withNoMoviesThatNightRunsAsUsual() {
|
||||
val pool = listOf(show("c", "day"), show("a", "night"))
|
||||
assertEquals(listOf("a"), dayPartPool(pool, parts, at(6, 20, 30), london).map { it.id })
|
||||
}
|
||||
|
||||
@Test fun moviesStayOutOfEverydayBlocksEvenWithNoBlockForThem() {
|
||||
assertEquals(listOf("c"), dayPartPool(listOf(show("c", "day"), film("m1")), listOf(DayPart(0, 1, group = "x")), at(2, 12), london).map { it.id })
|
||||
}
|
||||
|
||||
@Test fun aFilmChannelStillUsesItsFilmsOutsideItsBlocks() {
|
||||
val films = listOf(film("a"), film("b"))
|
||||
assertEquals(2, dayPartPool(films, listOf(DayPart(0, 1, group = "x")), at(2, 12), london).size)
|
||||
}
|
||||
|
||||
@Test fun aRuleCanRequireWordsInTheTitle() {
|
||||
val named = rule.copy(genres = listOf("Animation"), titleContains = "Dragon Ball", minMinutes = 30)
|
||||
val requests = mutableListOf<EmbyRequest>()
|
||||
val rows = JSONArray().put(row("db", "Dragon Ball Z: Bardock", listOf("Animation"))).put(row("x", "Other Film", listOf("Animation")))
|
||||
val read = findSuggestions(EmbyTransport { requests += it; EmbyReply(200, JSONObject().put("Items", rows).toString()) }, user, { "t" }, listOf(named), emptySet(), emptySet())
|
||||
assertEquals(listOf("db"), read.suggestions.map { it.id })
|
||||
assertTrue(requests.single().path.contains("SearchTerm=Dragon+Ball"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user