Kids profiles: one fail-closed policy, enforced at the playback request

Paul, 30 November 2026: unrated films and series blocked unless explicitly approved;
episodes never less restricted than their series; UK U/PG/12/12A/15/18 alongside US film
and TV ratings, anything unrecognised fails closed; the check sits where every stream is
asked for, so resume, autoplay, channel changes and deep links can't get past it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 18:59:36 +00:00
co-authored by Claude Opus 5.5
parent 3cdae246cf
commit 5bebac1299
9 changed files with 199 additions and 75 deletions
@@ -227,10 +227,10 @@ internal class CatalogueStore(context: Context, private val file: File) : Catalo
buildList { while (c.moveToNext()) add(c.getString(0) to c.getLong(1)) }
}
}.toMap()
/** Ratings of these items, where the catalogue has one ([KidsRatings]). Read only. */
@Synchronized fun ratingsOf(ids: Collection<String>): Map<String, String> = ids.distinct().chunked(400).flatMap { chunk ->
readableDatabase.rawQuery("SELECT id, rating FROM items WHERE rating <> '' AND id IN (${chunk.joinToString(",") { "?" }})", chunk.toTypedArray()).use { c ->
buildList { while (c.moveToNext()) add(c.getString(0) to c.getString(1)) }
/** Kind, title, year and rating of these items, for Kids profiles ([KidsRatings]). Read only. */
@Synchronized fun kidsRows(ids: Collection<String>): Map<String, KidsRatings.Row> = ids.distinct().chunked(400).flatMap { chunk ->
readableDatabase.rawQuery("SELECT id, type, title, year, rating FROM items WHERE id IN (${chunk.joinToString(",") { "?" }})", chunk.toTypedArray()).use { c ->
buildList { while (c.moveToNext()) add(c.getString(0) to KidsRatings.Row(c.getString(1), c.getString(2), if (c.isNull(3)) null else c.getInt(3), c.getString(4))) }
}
}.toMap()
/** Films' ratings by lower-case title and year, for films re-filed under a new number ([KidsRatings]). Read only. */
@@ -421,7 +421,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
// rating is read, Kids isn't shown it off the kids' own channels ([KidsRatings]).
LaunchedEffect(scheduledChannels, driveInPlan) {
val entries = scheduledChannels.values.flatMap { it.plan.entries } + driveInPlan?.entries.orEmpty()
withContext(Dispatchers.IO) { runCatching { KidsRatings.refresh(entries, { catalogue.ratingsOf(it) }, { catalogue.filmRatingsByTitle(it) }) } }
withContext(Dispatchers.IO) { runCatching { KidsRatings.refresh(entries, { catalogue.kidsRows(it) }, { catalogue.filmRatingsByTitle(it) }) } }
}
// Keeps smart channels topped up in the background. A failure changes nothing on air.
LaunchedEffect(session, extraChannels, channel, afterDarkChannel, toonamiChannel) {
@@ -473,7 +473,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
catch (_: Exception) { /* Tried again next hour. */ }
}
// The round's new bookings, rated for Kids before they come round.
withContext(Dispatchers.IO) { runCatching { KidsRatings.refresh(scheduledChannels.values.flatMap { it.plan.entries }, { catalogue.ratingsOf(it) }, { catalogue.filmRatingsByTitle(it) }) } }
withContext(Dispatchers.IO) { runCatching { KidsRatings.refresh(scheduledChannels.values.flatMap { it.plan.entries }, { catalogue.kidsRows(it) }, { catalogue.filmRatingsByTitle(it) }) } }
try { driveInPlan = withContext(Dispatchers.IO) { BackgroundPacing.run { scheduler.topUpDriveIn(active.accountId, active, refile = false) } } }
catch (cancelled: CancellationException) { throw cancelled }
catch (_: Exception) { /* Tried again next hour. */ }
@@ -126,6 +126,8 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
prepare(item, isPlayback = !ahead, preferredSourceId = sourceId)
}
fun prepare(item: SampleItem, isPlayback: Boolean = true, preferredSourceId: String? = null): EmbyPlaybackPlan {
// Kids profiles (30 November 2026): the one place every stream is asked for, so nothing Kids may not watch is ever opened.
KidsAccess.require(item)
if (preferredSourceId != null && !EmbyClient.validId(preferredSourceId)) throw EmbyCheckException("The channel source is no longer usable.")
if (item.id.isBlank() || sample.items.none { it.id == item.id } && candidateEpisodes[item.id] != item && channelEpisodes[item.id] != item && darkCandidates.none { it.item == item } && darkLineup[item.id] != item) throw EmbyCheckException("Choose a title from the current sample.")
// A show allowed AVI on its own (AviShows) plays its AVI copy even with the AVI switch off.
@@ -84,7 +84,7 @@ private fun closeLiveStream(session: EmbySampleSession, plan: EmbyPlaybackPlan,
}
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
internal fun channelMediaItem(plan: EmbyPlaybackPlan): MediaItem = MediaItem.Builder().setUri(plan.url).setSubtitleConfigurations(plan.subtitles.map { subtitle ->
internal fun channelMediaItem(plan: EmbyPlaybackPlan): MediaItem = if (!KidsAccess.allows(plan.item)) MediaItem.EMPTY else MediaItem.Builder().setUri(plan.url).setSubtitleConfigurations(plan.subtitles.map { subtitle ->
MediaItem.SubtitleConfiguration.Builder(android.net.Uri.parse(subtitle.url)).setMimeType(subtitle.mime)
.setLanguage(subtitle.language).setLabel(subtitle.label).build()
}).build()
@@ -0,0 +1,8 @@
package tv.orbit.classic
/**
* Programmes with no trustworthy rating that Paul has explicitly approved for Kids profiles ([kidsMay]): a series by
* [kidsSeriesKey], a film by [kidsFilmKey]. An approval only ever lets an unrated programme through; a restricted rating is
* never overridden. Empty until Paul approves titles (30 November 2026).
*/
internal val KidsApproved: Set<String> = emptySet()
@@ -1,64 +1,107 @@
package tv.orbit.classic
/**
* Kids profiles and adult-rated programmes (Paul, 30 November 2026: a release blocker. Kids was protected by channel only,
* and a Kids profile with Premiere ticked could watch Joker at 06:43). Whatever channels a Kids profile has, a programme
* rated for adults never plays for it: live, Catch Up, What's On, the guide and the companion all treat it as not for Kids.
* Grown-up profiles are unchanged and no schedule moves.
* Kids profiles and what they may watch (Paul, 30 November 2026: a release blocker. Kids was protected by channel only, and a
* Kids profile with Premiere ticked could watch Joker at 06:43).
*
* Ratings come from the box's own catalogue (no server reads): an episode takes its series' rating. A film with no rating at
* all is kept from Kids off the kids' own channels, where most unrated films are grown-up; an unrated episode plays, since
* so much television carries no rating. Until the ratings have been read, nothing off the kids' channels plays for Kids.
* One policy, applied where every stream is opened ([KidsAccess.require], in the playback request itself) as well as on every
* screen that lists or previews programmes ([kidsHidden]). For Kids, a programme plays only when its rating is recognised and
* suitable, or when it has no trustworthy rating and has been explicitly approved for Kids ([KidsApproved]):
* - A film goes by its own rating. An episode goes by its series' rating; an episode can never be less restricted than its
* series, and any rating it carries of its own only ever adds restriction.
* - US film and TV ratings and UK classifications are recognised. Anything else (no rating, "Not Rated", another country's
* board, an unknown value) is untrustworthy and fails closed.
* - Ratings come from the box's own catalogue (no server reads). Until a programme's rating has been read it doesn't play for
* Kids. Grown-up profiles are untouched.
*/
internal val AdultRatings = setOf("R", "NC-17", "NC17", "X", "XXX", "AO", "TV-MA", "18", "R18", "R-18", "GB-18", "18+", "UK-18", "DE-18", "FSK-18", "MA15+", "R18+")
internal enum class KidsVerdict { Suitable, Restricted, Unrated }
/** A rating that is for adults only, whatever board gave it. */
internal fun adultRating(rating: String?): Boolean = rating?.trim()?.uppercase()?.let { it in AdultRatings } == true
/** Recognised ratings a Kids profile may watch: US G to PG-13, US TV-Y to TV-14, UK U to 12A. */
internal val KidsSuitableRatings = setOf("G", "PG", "PG-13", "TV-Y", "TV-Y7", "TV-Y7-FV", "TV-G", "TV-PG", "TV-14", "U", "12", "12A")
/** Recognised ratings that are never for Kids: UK 15 and 18 (and R18), US R, NC-17 and TV-MA. */
internal val KidsRestrictedRatings = setOf("15", "18", "R18", "R", "NC-17", "TV-MA", "X")
/** The kids' own channels (as a Kids profile starts with), where an unrated film is taken to be a family one. */
internal val KidsOwnChannels get() = KidsStartChannels + WONDER_TV_NUMBER
/** One rating as given, judged: UK ratings may carry a GB- or UK- prefix, US ones a US- prefix. Anything else is unrated. */
internal fun kidsVerdict(rating: String?): KidsVerdict {
val r = rating?.trim()?.uppercase()?.removePrefix("GB-")?.removePrefix("UK-")?.removePrefix("US-")?.takeIf { it.isNotEmpty() } ?: return KidsVerdict.Unrated
return when (r) { in KidsSuitableRatings -> KidsVerdict.Suitable; in KidsRestrictedRatings -> KidsVerdict.Restricted; else -> KidsVerdict.Unrated }
}
/** A programme kept from Kids: [rating] is the one found for it (null when none), [isFilm] whether it's a film. */
internal fun kidsRatedOut(channel: Int, rating: String?, isFilm: Boolean, known: Boolean): Boolean = when {
rating != null -> adultRating(rating)
!known -> channel !in KidsOwnChannels
else -> isFilm && channel !in KidsOwnChannels
/** All of a programme's ratings together (its own, and its series'): the most restrictive wins, and an untrustworthy one is never suitable. */
internal fun kidsVerdict(vararg ratings: String?): KidsVerdict {
val given = ratings.filter { !it.isNullOrBlank() }.map(::kidsVerdict)
return when {
KidsVerdict.Restricted in given -> KidsVerdict.Restricted
given.isEmpty() || KidsVerdict.Unrated in given -> KidsVerdict.Unrated
else -> KidsVerdict.Suitable
}
}
/** What's known of one booked item: its own rating (a film's), its series' rating (an episode's), and its key for [KidsApproved]. */
internal data class KidsItem(val rating: String?, val seriesRating: String?, val approvalKey: String)
/** The key a title is approved under: a series by its name, a film by its name and year. */
internal fun kidsSeriesKey(title: String) = "series:${seriesKey(title)}"
internal fun kidsFilmKey(title: String, year: Int?) = "film:${seriesKey(title)}|${year ?: ""}"
/** May Kids watch it: suitable, or unrated and explicitly approved. Restricted is never overridden. */
internal fun kidsMay(item: KidsItem?, approved: Set<String> = KidsApproved): Boolean = when (item?.let { kidsVerdict(it.rating, it.seriesRating) }) {
KidsVerdict.Suitable -> true
KidsVerdict.Unrated -> item.approvalKey in approved
else -> false
}
internal object KidsRatings {
/** Each booked item's rating ("" when the catalogue has none), by the item's id. */
@Volatile private var byItem: Map<String, String> = emptyMap()
/** True once a first read has finished. */
@Volatile private var byItem: Map<String, KidsItem> = emptyMap()
@Volatile var loaded = false
private set
fun ratingOf(itemId: String): String? = byItem[itemId]?.ifEmpty { null }
fun known(itemId: String) = itemId in byItem
fun of(itemId: String): KidsItem? = byItem[itemId]
/** Not for Kids: the profile watching is Kids and [item] is rated for adults (or can't be shown to be suitable). */
fun hidden(channel: Int, item: SampleItem): Boolean = Profiles.kids && kidsRatedOut(channel, ratingOf(item.id), item.type == "Movie", known(item.id))
/** Not for Kids: the profile watching is Kids and [item] isn't known to be suitable or approved. */
fun hidden(@Suppress("UNUSED_PARAMETER") channel: Int, item: SampleItem): Boolean = Profiles.kids && !kidsMay(byItem[item.id])
/** A catalogue row: kind, title, year and rating. */
data class Row(val type: String, val title: String, val year: Int?, val rating: String)
/**
* Reads the ratings of booked programmes not already known, from the catalogue: by the item's own id, then its series' id,
* then (for a film the server has re-filed under a new number) by its title and year. Read only.
* Reads what's needed for booked programmes not already known, from the catalogue: a film by its own id (or, re-filed under
* a new number, by its title and year), an episode by its series. Read only.
*/
fun refresh(entries: List<ScheduleEntry>, lookup: (ids: Collection<String>) -> Map<String, String>, films: (titles: Collection<String>) -> Map<Pair<String, Int?>, String>) {
val missing = entries.filter { it.media.item.id !in byItem }
fun refresh(entries: List<ScheduleEntry>, rows: (ids: Collection<String>) -> Map<String, Row>, films: (titles: Collection<String>) -> Map<Pair<String, Int?>, String>) {
val missing = entries.filter { it.media.item.id !in byItem }.distinctBy { it.media.item.id }
if (missing.isEmpty()) { loaded = true; return }
val ids = lookup(missing.flatMap { listOf(it.media.item.id, it.seriesId) })
val unrated = missing.filter { ids[it.media.item.id] == null && ids[it.seriesId] == null && it.media.item.type == "Movie" }
val byTitle = if (unrated.isEmpty()) emptyMap() else films(unrated.map { it.media.item.title })
val found = missing.associate { e ->
e.media.item.id to (ids[e.media.item.id] ?: ids[e.seriesId] ?: byTitle[e.media.item.title.trim().lowercase() to e.media.item.year] ?: "")
val found = rows(missing.flatMap { listOf(it.media.item.id, it.seriesId) })
val filmsWithout = missing.filter { it.media.item.type == "Movie" && found[it.media.item.id]?.rating.isNullOrBlank() }
val byTitle = if (filmsWithout.isEmpty()) emptyMap() else films(filmsWithout.map { it.media.item.title })
byItem = byItem + missing.associate { e ->
val item = e.media.item
e.media.item.id to if (item.type == "Movie") {
val own = found[item.id]?.rating?.ifBlank { null } ?: byTitle[item.title.trim().lowercase() to item.year]
KidsItem(own, null, kidsFilmKey(item.title, item.year))
} else {
val series = found[e.seriesId]
KidsItem(found[item.id]?.rating?.ifBlank { null }, series?.rating?.ifBlank { null }, kidsSeriesKey(series?.title ?: item.title.substringBefore(" / ")))
}
}
byItem = byItem + found
loaded = true
// Counts only (no titles): how much of what's booked a Kids profile may watch, so a check after installing can see it.
val verdicts = byItem.values.groupingBy { if (kidsMay(it)) "allowed" else kidsVerdict(it.rating, it.seriesRating).name.lowercase() }.eachCount()
runCatching { android.util.Log.i("OrbitSchedule", "kidsRatings items=${byItem.size} ${verdicts.entries.joinToString(" ") { "${it.key}=${it.value}" }}") }
}
internal fun resetForTest() { byItem = emptyMap(); loaded = false }
}
/** Kept from the profile watching: a grown-up takeover, or a programme rated for adults (Kids only). */
/** Kept from Kids where the stream is opened: whatever screen asked, a programme Kids may not watch is never requested. */
internal class NotForKids : EmbyCheckException("This one's for grown-ups.")
internal object KidsAccess {
fun allows(item: SampleItem): Boolean = !KidsRatings.hidden(0, item)
fun require(item: SampleItem) { if (!allows(item)) throw NotForKids() }
}
/** Kept from the profile watching: a grown-up takeover, or a programme Kids may not watch (Kids only). */
internal fun kidsHidden(channel: Int, show: SampleBroadcast, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()) =
kidsAsleep(takeoverOf(channel, show, zone)) || KidsRatings.hidden(channel, show.media.item)
internal fun kidsHidden(channel: Int, entry: ScheduleEntry, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()) =
@@ -139,7 +139,9 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
// A channel of your own outside its hours is off air, and nothing of it is opened either.
val offAir = offAirUntil(channel.number, current.startMs)
// Kids and a programme rated for adults (30 November 2026): nothing of it is opened, whatever channels Kids has.
val notForKids = !kidsAsleep(takeoverOf(channel.number, current)) && KidsRatings.hidden(channel.number, current.media.item)
// Also when the playback request itself refuses it ([KidsAccess]), say if the profile changed as it was being asked for.
var refusedForKids by remember(channel, current.startMs) { mutableStateOf(false) }
val notForKids = !kidsAsleep(takeoverOf(channel.number, current)) && (refusedForKids || KidsRatings.hidden(channel.number, current.media.item))
val asleep = kidsAsleep(takeoverOf(channel.number, current)) || notForKids || offAir != null
// A new wall-clock slot disposes the old player before opening its successor.
LaunchedEffect(channel, current.startMs, retryAttempt, asleep) {
@@ -171,6 +173,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
// The server not answering at all (13 November 2026: Emby froze for six minutes during its scan) isn't this programme's
// fault: say so plainly, and try again by itself every 30 seconds rather than give the slot up.
catch (failure: ServerNotAnswering) { problem = if (tvOnline(tuneContext)) SERVER_NOT_ANSWERING else TV_OFFLINE; serverRetry++ }
catch (failure: NotForKids) { refusedForKids = true }
catch (failure: EmbyCheckException) { problem = if (channel is ScheduledChannel) "This programme isn't available right now. Orbit moves on at ${clock(current.endMs)}." else failure.message }
catch (_: Exception) { problem = if (channel is ScheduledChannel) "This programme isn't available right now. Orbit moves on at ${clock(current.endMs)}." else "This scheduled programme could not be opened. Return to the guide and try again." }
}
@@ -1,60 +1,119 @@
package tv.orbit.classic
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
/** Kids profiles never see adult-rated programmes, whatever channels they have (Paul, 30 November 2026: Joker at 06:43 on Premiere). */
/**
* Kids profiles (Paul, 30 November 2026, a release blocker: Joker at 06:43 on Premiere for a Kids profile with Premiere ticked).
* The policy, and that it holds where every stream is asked for, so direct playback, resume, channel changes, autoplay and
* deep links (all of which come through the same playback request) can't get past it.
*/
class KidsRatingsTest {
private val kids = Profile("kids", "Amelia", "ollie", ProfileKind.Kids, setOf(301, 304, 611))
private val grown = Profile("grown", "Paul", "sil-blue", ProfileKind.Grown)
private fun film(id: String, title: String, year: Int) = SampleItem(title, "Movie", 120, "", id, year = year)
private fun episode(id: String) = SampleItem("Episode", "Episode", 22, "", id)
private fun episode(id: String, title: String = "Episode") = SampleItem(title, "Episode", 22, "", id)
private fun entry(seriesId: String, item: SampleItem) = ScheduleEntry(seriesId, EpisodeMark(1, 1), ScheduledMedia(item, "mediasource_${item.id}", 60_000L), 0L)
private val rows = mapOf(
"joker" to KidsRatings.Row("Movie", "Joker", 2019, "R"), "hook" to KidsRatings.Row("Movie", "Hook", 1991, "PG"),
"paddington" to KidsRatings.Row("Movie", "Paddington", 2014, "GB-PG"), "fifteen" to KidsRatings.Row("Movie", "Kes", 1969, "15"),
"nr" to KidsRatings.Row("Movie", "Holiday Inn", 1942, "NR"), "foreign" to KidsRatings.Row("Movie", "Elsewhere", 2001, "AU-G"),
"sopranos" to KidsRatings.Row("Series", "The Sopranos", 1999, "TV-MA"), "bluey" to KidsRatings.Row("Series", "Bluey", 2018, "TV-Y"),
"clangers" to KidsRatings.Row("Series", "Clangers", 1969, "NR"), "byker" to KidsRatings.Row("Series", "Byker Grove", 1989, ""),
// An episode rated more leniently than its series never gets through.
"mild-episode" to KidsRatings.Row("Episode", "Pilot", 1999, "TV-PG"))
@Before fun ratings() {
KidsRatings.resetForTest()
val catalogue = mapOf("joker" to "R", "braveheart" to "R", "hook" to "PG", "sopranos" to "TV-MA", "bluey" to "TV-Y")
KidsRatings.refresh(listOf(entry("joker", film("joker", "Joker", 2019)), entry("hook", film("hook", "Hook", 1991)),
entry("sopranos", episode("s1e1")), entry("bluey", episode("b1e1")), entry("old", film("refiled", "Braveheart", 1995)),
entry("x", film("unrated", "Something", 2001)), entry("y", episode("unrated-episode"))),
lookup = { ids -> ids.mapNotNull { id -> catalogue[id]?.let { id to it } }.toMap() },
entry("paddington", film("paddington", "Paddington", 2014)), entry("fifteen", film("fifteen", "Kes", 1969)),
entry("nr", film("nr", "Holiday Inn", 1942)), entry("foreign", film("foreign", "Elsewhere", 2001)),
entry("old", film("refiled", "Braveheart", 1995)), entry("gone", film("unrated", "Something", 2001)),
entry("sopranos", episode("mild-episode")), entry("sopranos", episode("s1e2")), entry("bluey", episode("b1e1")),
entry("clangers", episode("c1e1")), entry("byker", episode("bg1e1"))),
rows = { ids -> ids.mapNotNull { id -> rows[id]?.let { id to it } }.toMap() },
films = { titles -> if ("Braveheart" in titles) mapOf(("braveheart" to 1995) to "R") else emptyMap() })
}
@After fun nobody() { Profiles.current = null; KidsRatings.resetForTest() }
@Test fun kidsNeverSeeAdultRatedProgrammes() {
@Test fun recognisedSuitableRatingsPlayAndRestrictedNeverDo() {
Profiles.current = kids
assertFalse(KidsRatings.hidden(301, film("hook", "Hook", 1991)))
assertFalse(KidsRatings.hidden(301, film("paddington", "Paddington", 2014)))
assertFalse(KidsRatings.hidden(611, episode("b1e1")))
assertTrue(KidsRatings.hidden(301, film("joker", "Joker", 2019)))
// An episode takes its series' rating.
assertTrue(KidsRatings.hidden(109, episode("s1e1")))
assertTrue(KidsRatings.hidden(301, film("fifteen", "Kes", 1969)))
// A film the server re-filed under a new number is found by its title and year.
assertTrue(KidsRatings.hidden(301, film("refiled", "Braveheart", 1995)))
assertFalse(KidsRatings.hidden(301, film("hook", "Hook", 1991)))
assertFalse(KidsRatings.hidden(611, episode("b1e1")))
}
@Test fun unratedFilmsAreKeptFromKidsOffTheKidsChannels() {
@Test fun episodesGoByTheirSeriesAndNeverLessRestricted() {
Profiles.current = kids
assertTrue(KidsRatings.hidden(301, film("unrated", "Something", 2001)))
assertFalse(KidsRatings.hidden(612, film("unrated", "Something", 2001)))
// Unrated television plays.
assertFalse(KidsRatings.hidden(102, episode("unrated-episode")))
// Anything not read yet waits off the kids' channels.
assertTrue(KidsRatings.hidden(301, film("new", "New", 2020)))
assertFalse(KidsRatings.hidden(611, episode("new-episode")))
assertTrue(KidsRatings.hidden(109, episode("s1e2")))
assertTrue(KidsRatings.hidden(109, episode("mild-episode")))
}
@Test fun grownUpsAreUnchanged() {
@Test fun anythingWithoutATrustworthyRatingFailsClosed() {
Profiles.current = kids
assertTrue(KidsRatings.hidden(612, film("unrated", "Something", 2001)))
assertTrue(KidsRatings.hidden(310, film("nr", "Holiday Inn", 1942)))
assertTrue(KidsRatings.hidden(201, film("foreign", "Elsewhere", 2001)))
assertTrue(KidsRatings.hidden(614, episode("c1e1")))
assertTrue(KidsRatings.hidden(611, episode("bg1e1")))
// Not read yet: it waits.
assertTrue(KidsRatings.hidden(611, episode("never-seen")))
KidsRatings.resetForTest()
assertTrue(KidsRatings.hidden(611, episode("b1e1")))
}
@Test fun approvalLetsUnratedThroughButNeverRestricted() {
val approved = setOf(kidsSeriesKey("Clangers"), kidsFilmKey("Holiday Inn", 1942), kidsFilmKey("Joker", 2019), kidsSeriesKey("The Sopranos"))
assertTrue(kidsMay(KidsRatings.of("c1e1"), approved))
assertTrue(kidsMay(KidsRatings.of("nr"), approved))
assertFalse(kidsMay(KidsRatings.of("joker"), approved))
assertFalse(kidsMay(KidsRatings.of("s1e2"), approved))
assertFalse(kidsMay(KidsRatings.of("bg1e1"), approved))
}
@Test fun ratingsFromBothBoards() {
listOf("G", "PG", "PG-13", "TV-Y", "TV-Y7", "TV-G", "TV-PG", "TV-14", "U", "12", "12A", "GB-12A", "uk-u", "US-PG").forEach { assertEquals(it, KidsVerdict.Suitable, kidsVerdict(it)) }
listOf("15", "18", "R18", "R", "NC-17", "TV-MA", "GB-15", "tv-ma").forEach { assertEquals(it, KidsVerdict.Restricted, kidsVerdict(it)) }
listOf("NR", "Not Rated", "Unrated", "AU-G", "RU-0+", "12+", "M", "", null).forEach { assertEquals("$it", KidsVerdict.Unrated, kidsVerdict(it)) }
assertEquals(KidsVerdict.Restricted, kidsVerdict("TV-PG", "TV-MA"))
assertEquals(KidsVerdict.Unrated, kidsVerdict("TV-PG", "NR"))
}
@Test fun grownUpsAreUnchangedAndSwitchingProfileTakesEffectAtOnce() {
Profiles.current = grown
assertFalse(KidsRatings.hidden(301, film("joker", "Joker", 2019)))
assertFalse(KidsRatings.hidden(301, film("never-seen", "New", 2020)))
Profiles.current = kids
assertTrue(KidsRatings.hidden(301, film("joker", "Joker", 2019)))
Profiles.current = grown
assertFalse(KidsRatings.hidden(301, film("joker", "Joker", 2019)))
assertFalse(KidsRatings.hidden(301, film("new", "New", 2020)))
}
@Test fun adultRatingsFromEveryBoard() {
listOf("R", "NC-17", "TV-MA", "18", "R18", "tv-ma").forEach { assertTrue(it, adultRating(it)) }
listOf("PG-13", "TV-14", "15", "12A", "PG", null).forEach { assertFalse("$it", adultRating(it)) }
/** The playback request itself: for Kids, a restricted or unknown programme is refused before anything reaches the server. */
@Test fun thePlaybackRequestRefusesForKidsAndNeverAsksTheServer() {
val joker = film("joker", "Joker", 2019); val hook = film("hook", "Hook", 1991)
val asked = mutableListOf<String>()
val transport = EmbyTransport { r -> asked += r.path; EmbyReply(500, "") }
val session = EmbySampleSession(transport, "fixture-token-private", "fixture-user", EmbySample(listOf(joker, hook), 2))
Profiles.current = kids
try { session.prepare(joker); fail("Kids opened Joker") } catch (_: NotForKids) {}
try { session.prepareForTuning(joker, "mediasource_joker") { }; fail("Kids tuned to Joker") } catch (_: NotForKids) {}
assertTrue(asked.toString(), asked.isEmpty())
// A suitable film goes on to ask the server, as before.
runCatching { session.prepare(hook) }.exceptionOrNull()?.let { assertFalse(it is NotForKids) }
assertEquals(1, asked.count { "/PlaybackInfo" in it })
// A grown-up's request for Joker goes ahead as before.
Profiles.current = grown
runCatching { session.prepare(joker) }.exceptionOrNull()?.let { assertFalse(it is NotForKids) }
assertEquals(2, asked.count { "/PlaybackInfo" in it })
}
}