From ecf8eac2adaf71b08c953ca09954600a2829ccc4 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Mon, 30 Nov 2026 19:06:01 +0000 Subject: [PATCH] Kids profiles: reviewed allowlist, other boards' ratings, films by IMDb ID Paul, 30 November 2026: known children's programmes mustn't disappear because their metadata is unrated or foreign. Series approved by name cover their episodes; films by IMDb ID; restricted ratings always win. AU, RU, BR, DE, CA, ES and IE ratings are mapped where reliable (with their board's prefix only). A re-filed film is found by IMDb ID, then title and year, then title alone only when every copy agrees. Co-Authored-By: Claude Opus 5.5 --- .../java/tv/orbit/classic/CatalogueStore.kt | 3 ++ .../tv/orbit/classic/EmbyConnectionScreen.kt | 4 +- .../java/tv/orbit/classic/KidsApproved.kt | 31 +++++++++-- .../main/java/tv/orbit/classic/KidsRatings.kt | 54 ++++++++++++++----- .../java/tv/orbit/classic/KidsRatingsTest.kt | 40 ++++++++++---- 5 files changed, 104 insertions(+), 28 deletions(-) diff --git a/android/app/src/main/java/tv/orbit/classic/CatalogueStore.kt b/android/app/src/main/java/tv/orbit/classic/CatalogueStore.kt index 72113a76..cf771b5e 100644 --- a/android/app/src/main/java/tv/orbit/classic/CatalogueStore.kt +++ b/android/app/src/main/java/tv/orbit/classic/CatalogueStore.kt @@ -233,6 +233,9 @@ internal class CatalogueStore(context: Context, private val file: File) : Catalo 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 IMDb ID (the copy with a rating), for films re-filed under a new number ([KidsRatings]). Read only. */ + @Synchronized fun filmRatingsByImdb(imdbs: Collection): Map = idsByImdb(imdbs).mapNotNull { (imdb, ids) -> + kidsRows(ids).values.map { it.rating }.firstOrNull { it.isNotBlank() }?.let { imdb to it } }.toMap() /** Films' ratings by lower-case title and year, for films re-filed under a new number ([KidsRatings]). Read only. */ @Synchronized fun filmRatingsByTitle(titles: Collection): Map, String> = titles.map { it.trim() }.distinct().chunked(400).flatMap { chunk -> readableDatabase.rawQuery("SELECT title, year, rating FROM items WHERE type = 'Movie' AND rating <> '' AND TRIM(title) IN (${chunk.joinToString(",") { "?" }})", chunk.toTypedArray()).use { c -> diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index 6943d695..e2624ba9 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -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.kidsRows(it) }, { catalogue.filmRatingsByTitle(it) }) } } + withContext(Dispatchers.IO) { runCatching { KidsRatings.refresh(entries, { catalogue.kidsRows(it) }, { catalogue.filmRatingsByTitle(it) }, { catalogue.filmRatingsByImdb(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.kidsRows(it) }, { catalogue.filmRatingsByTitle(it) }) } } + withContext(Dispatchers.IO) { runCatching { KidsRatings.refresh(scheduledChannels.values.flatMap { it.plan.entries }, { catalogue.kidsRows(it) }, { catalogue.filmRatingsByTitle(it) }, { catalogue.filmRatingsByImdb(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. */ } diff --git a/android/app/src/main/java/tv/orbit/classic/KidsApproved.kt b/android/app/src/main/java/tv/orbit/classic/KidsApproved.kt index eff50f42..0cdd2846 100644 --- a/android/app/src/main/java/tv/orbit/classic/KidsApproved.kt +++ b/android/app/src/main/java/tv/orbit/classic/KidsApproved.kt @@ -1,8 +1,31 @@ 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). + * Children's and family programmes with no trustworthy rating, reviewed and approved for Kids profiles ([kidsMay]). A series + * is approved by name ([kidsSeriesKey]) and that covers its episodes; a film by its IMDb ID ([kidsFilmKey]). An approval only + * ever lets an unrated programme through: a restricted rating, the series' or the programme's own, always wins. Nothing is + * approved for being on a kids' channel; each title here was looked at (Paul, 30 November 2026: the known children's + * programmes are fine; questionable ones are listed for his decision instead, in audit-20261130-kids). */ -internal val KidsApproved: Set = emptySet() +internal val KidsApprovedSeries = listOf( + // Tots and Junior: British and American children's television. + "Clangers", "Clifford the Big Red Dog", "Pingu in the City", "Byker Grove", "The Story of Tracy Beaker", "The Demon Headmaster", + // Orbit X and Vortex: Saturday-morning cartoons and family anime. + "She-Ra: Princess of Power", "Dragon Ball", "Dragon Ball Super: Beerus", "Magic Knight Rayearth", + // Terra and Wild: natural history and survival. + "Africa Earth's Wild Home", "Asia (2024)", "Blue Planet III", "Life on Earth", "The Blue Planet", "Our Planet", "Universe", + "Into the Wild Frontier", "Survival with Ray Mears") + +/** Family films (PixelZ and Wonder), by IMDb ID: all rated U, G or PG where rated, kept here so a copy re-filed without its rating still plays. */ +internal val KidsApprovedFilms = listOf( + "tt0120623", "tt0230011", "tt0034492", "tt0397892", "tt1217209", "tt0328880", "tt3606752", "tt0092067", "tt0070016", "tt0413895", + "tt0371606", "tt0120630", "tt2380307", "tt0327597", "tt0121164", "tt1323594", "tt3469046", "tt0032455", "tt0120910", "tt0432283", + "tt0424095", "tt1798188", "tt2294629", "tt4520988", "tt0299172", "tt0347149", "tt0268380", "tt1080016", "tt0438097", "tt2096673", + "tt0097814", "tt4729430", "tt4302938", "tt2267968", "tt0275847", "tt12801262", "tt1277953", "tt0396555", "tt3521164", "tt1453405", + "tt0198781", "tt0096283", "tt7146812", "tt0327084", "tt1623288", "tt0110008", "tt0876563", "tt0104652", "tt5848272", "tt5109280", + "tt1446192", "tt0070608", "tt0358082", "tt0126029", "tt0165982", "tt1865505", "tt9362722", "tt4633694", "tt0166813", "tt0245429", + "tt4624424", "tt0398286", "tt0065421", "tt0347618", "tt0481499", "tt0120917", "tt0257778", "tt0317705", "tt0061852", "tt0076363", + "tt0780521", "tt0076618", "tt0138749", "tt0485601", "tt0472181", "tt2576852", "tt0114709", "tt0435761", "tt0133240", "tt1860353", + "tt8097030", "tt0312004", "tt0113824", "tt1449283", "tt5198068", "tt1568921") + +internal val KidsApproved: Set by lazy { (KidsApprovedSeries.map(::kidsSeriesKey) + KidsApprovedFilms.map(::kidsFilmKey)).toSet() } diff --git a/android/app/src/main/java/tv/orbit/classic/KidsRatings.kt b/android/app/src/main/java/tv/orbit/classic/KidsRatings.kt index 5c47f6c9..21cc4d79 100644 --- a/android/app/src/main/java/tv/orbit/classic/KidsRatings.kt +++ b/android/app/src/main/java/tv/orbit/classic/KidsRatings.kt @@ -21,9 +21,29 @@ internal val KidsSuitableRatings = setOf("G", "PG", "PG-13", "TV-Y", "TV-Y7", "T /** 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") -/** One rating as given, judged: UK ratings may carry a GB- or UK- prefix, US ones a US- prefix. Anything else is unrated. */ +/** + * Other boards' ratings where they map reliably (Paul, 30 November 2026), only with their country prefix: a bare "12+" or + * "M" could be any board's and stays unrated. Anything a board marks for older teens or adults is restricted. + */ +internal val KidsBoardRatings: Map = buildMap { + fun board(country: String, suitable: List, restricted: List) { + suitable.forEach { put("$country-$it", KidsVerdict.Suitable) }; restricted.forEach { put("$country-$it", KidsVerdict.Restricted) } + } + board("AU", listOf("G", "PG"), listOf("M", "MA15+", "R18+", "X18+")) + board("RU", listOf("0+", "6+", "12+"), listOf("16+", "18+")) + board("BR", listOf("L", "10", "12"), listOf("14", "16", "18")) + board("DE", listOf("0", "6", "12"), listOf("16", "18")) + board("FSK", listOf("0", "6", "12"), listOf("16", "18")) + board("CA", listOf("G", "PG", "C", "C8"), listOf("14+", "18+")) + board("ES", listOf("APTA", "TP", "7", "12"), listOf("16", "18")) + board("IE", listOf("G", "PG", "12A"), listOf("15A", "16", "18")) +} + +/** One rating as given, judged: UK ratings may carry a GB- or UK- prefix, US ones a US- prefix, others their board's. 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 + val raw = rating?.trim()?.uppercase()?.takeIf { it.isNotEmpty() } ?: return KidsVerdict.Unrated + KidsBoardRatings[raw]?.let { return it } + val r = raw.removePrefix("GB-").removePrefix("UK-").removePrefix("US-") return when (r) { in KidsSuitableRatings -> KidsVerdict.Suitable; in KidsRestrictedRatings -> KidsVerdict.Restricted; else -> KidsVerdict.Unrated } } @@ -37,17 +57,17 @@ internal fun kidsVerdict(vararg ratings: String?): KidsVerdict { } } -/** 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) +/** What's known of one booked item: its own rating (a film's), its series' rating (an episode's), and the keys it may be approved under ([KidsApproved]). */ +internal data class KidsItem(val rating: String?, val seriesRating: String?, val approvalKeys: List) -/** The key a title is approved under: a series by its name, a film by its name and year. */ +/** The key a title is approved under: a series by its name (covering its episodes), a film by its IMDb ID, its stable identity. */ internal fun kidsSeriesKey(title: String) = "series:${seriesKey(title)}" -internal fun kidsFilmKey(title: String, year: Int?) = "film:${seriesKey(title)}|${year ?: ""}" +internal fun kidsFilmKey(imdb: String) = "film:${imdb.lowercase().removePrefix("imdb.")}" /** May Kids watch it: suitable, or unrated and explicitly approved. Restricted is never overridden. */ internal fun kidsMay(item: KidsItem?, approved: Set = KidsApproved): Boolean = when (item?.let { kidsVerdict(it.rating, it.seriesRating) }) { KidsVerdict.Suitable -> true - KidsVerdict.Unrated -> item.approvalKey in approved + KidsVerdict.Unrated -> item.approvalKeys.any { it in approved } else -> false } @@ -65,23 +85,31 @@ internal object KidsRatings { data class Row(val type: String, val title: String, val year: Int?, val rating: String) /** - * 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. + * Reads what's needed for booked programmes not already known, from the catalogue. A film: by its own id; re-filed under a + * new number, by its IMDb ID, then by its title and year, then by its title alone when every film of that name is judged + * the same. An episode: by its series. Read only. */ - fun refresh(entries: List, rows: (ids: Collection) -> Map, films: (titles: Collection) -> Map, String>) { + fun refresh(entries: List, rows: (ids: Collection) -> Map, films: (titles: Collection) -> Map, String>, + imdbs: (imdbs: Collection) -> Map = { emptyMap() }) { val missing = entries.filter { it.media.item.id !in byItem }.distinctBy { it.media.item.id } if (missing.isEmpty()) { loaded = true; return } val found = rows(missing.flatMap { listOf(it.media.item.id, it.seriesId) }) + fun imdbOf(item: SampleItem) = item.ref.lowercase().takeIf { it.startsWith("imdb.tt") }?.removePrefix("imdb.") val filmsWithout = missing.filter { it.media.item.type == "Movie" && found[it.media.item.id]?.rating.isNullOrBlank() } + val byImdb = if (filmsWithout.isEmpty()) emptyMap() else imdbs(filmsWithout.mapNotNull { imdbOf(it.media.item) }) val byTitle = if (filmsWithout.isEmpty()) emptyMap() else films(filmsWithout.map { it.media.item.title }) + fun titleAlone(title: String): String? = byTitle.filterKeys { it.first == title.trim().lowercase() }.values.toList() + .takeIf { r -> r.isNotEmpty() && r.map(::kidsVerdict).distinct().size == 1 }?.first() 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)) + val imdb = imdbOf(item) + val own = found[item.id]?.rating?.ifBlank { null } ?: imdb?.let { byImdb[it] } + ?: byTitle[item.title.trim().lowercase() to item.year] ?: titleAlone(item.title) + KidsItem(own, null, listOfNotNull(imdb?.let(::kidsFilmKey))) } else { val series = found[e.seriesId] - KidsItem(found[item.id]?.rating?.ifBlank { null }, series?.rating?.ifBlank { null }, kidsSeriesKey(series?.title ?: item.title.substringBefore(" / "))) + KidsItem(found[item.id]?.rating?.ifBlank { null }, series?.rating?.ifBlank { null }, listOf(kidsSeriesKey(series?.title ?: item.title.substringBefore(" / ")))) } } loaded = true diff --git a/android/app/src/test/java/tv/orbit/classic/KidsRatingsTest.kt b/android/app/src/test/java/tv/orbit/classic/KidsRatingsTest.kt index 59a81d39..965dde9a 100644 --- a/android/app/src/test/java/tv/orbit/classic/KidsRatingsTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/KidsRatingsTest.kt @@ -22,9 +22,9 @@ class KidsRatingsTest { 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"), + "nr" to KidsRatings.Row("Movie", "Holiday Inn", 1942, "NR"), "foreign" to KidsRatings.Row("Movie", "Elsewhere", 2001, "AT-14"), "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, ""), + "clangers" to KidsRatings.Row("Series", "Clangers", 1969, "NR"), "byker" to KidsRatings.Row("Series", "Byker Grove", 1989, ""), "unknown" to KidsRatings.Row("Series", "Some Unrated Show", 2001, ""), // An episode rated more leniently than its series never gets through. "mild-episode" to KidsRatings.Row("Episode", "Pilot", 1999, "TV-PG")) @@ -32,10 +32,10 @@ class KidsRatingsTest { KidsRatings.resetForTest() KidsRatings.refresh(listOf(entry("joker", film("joker", "Joker", 2019)), entry("hook", film("hook", "Hook", 1991)), 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("nr", film("nr", "Holiday Inn", 1942)), entry("nr", film("nr-imdb", "Holiday Inn", 1942).copy(ref = "imdb.tt0034862")), 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"))), + entry("clangers", episode("c1e1")), entry("byker", episode("bg1e1")), entry("unknown", episode("u1e1"))), 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() }) } @@ -63,8 +63,7 @@ class KidsRatingsTest { 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"))) + assertTrue(KidsRatings.hidden(611, episode("u1e1"))) // Not read yet: it waits. assertTrue(KidsRatings.hidden(611, episode("never-seen"))) KidsRatings.resetForTest() @@ -72,9 +71,11 @@ class KidsRatingsTest { } @Test fun approvalLetsUnratedThroughButNeverRestricted() { - val approved = setOf(kidsSeriesKey("Clangers"), kidsFilmKey("Holiday Inn", 1942), kidsFilmKey("Joker", 2019), kidsSeriesKey("The Sopranos")) + val approved = setOf(kidsSeriesKey("Clangers"), kidsFilmKey("tt0034862"), kidsFilmKey("tt7286456"), kidsSeriesKey("The Sopranos")) assertTrue(kidsMay(KidsRatings.of("c1e1"), approved)) - assertTrue(kidsMay(KidsRatings.of("nr"), approved)) + // A film by its IMDb ID, its stable identity, not by its title. + assertTrue(kidsMay(KidsRatings.of("nr-imdb"), approved)) + assertFalse(kidsMay(KidsRatings.of("nr"), approved)) assertFalse(kidsMay(KidsRatings.of("joker"), approved)) assertFalse(kidsMay(KidsRatings.of("s1e2"), approved)) assertFalse(kidsMay(KidsRatings.of("bg1e1"), approved)) @@ -83,7 +84,10 @@ class KidsRatingsTest { @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)) } + listOf("AU-G", "RU-0+", "BR-L", "CA-PG", "DE-12").forEach { assertEquals(it, KidsVerdict.Suitable, kidsVerdict(it)) } + listOf("AU-MA15+", "RU-16+", "BR-14", "ES-16", "CA-14+").forEach { assertEquals(it, KidsVerdict.Restricted, kidsVerdict(it)) } + // A bare number or letter could be any board's. + listOf("NR", "Not Rated", "Unrated", "12+", "16+", "M", "L", "14", "AT-14", "", null).forEach { assertEquals("$it", KidsVerdict.Unrated, kidsVerdict(it)) } assertEquals(KidsVerdict.Restricted, kidsVerdict("TV-PG", "TV-MA")) assertEquals(KidsVerdict.Unrated, kidsVerdict("TV-PG", "NR")) } @@ -98,6 +102,24 @@ class KidsRatingsTest { assertFalse(KidsRatings.hidden(301, film("joker", "Joker", 2019))) } + @Test fun theReviewedAllowlistKeepsKnownChildrensProgrammes() { + Profiles.current = kids + // Clangers (NR) and Byker Grove (no rating) are on the reviewed list, so they play. + assertFalse(KidsRatings.hidden(614, episode("c1e1"))) + assertFalse(KidsRatings.hidden(611, episode("bg1e1"))) + // Nothing gets through for being on a kids' channel. + assertTrue(KidsRatings.hidden(612, film("unrated", "Something", 2001))) + } + + @Test fun aFilmReFiledWithoutItsYearIsFoundByTitleOnlyWhenEveryCopyAgrees() { + KidsRatings.resetForTest() + KidsRatings.refresh(listOf(entry("a", film("toy", "Toy Story", 0).copy(year = null)), entry("b", film("tangled", "Tangled", 0).copy(year = null))), + rows = { emptyMap() }, films = { mapOf(("toy story" to 1995) to "G", ("tangled" to 2010) to "PG", ("tangled" to 2001) to "R") }) + Profiles.current = kids + assertFalse(KidsRatings.hidden(613, film("toy", "Toy Story", 0))) + assertTrue(KidsRatings.hidden(613, film("tangled", "Tangled", 0))) + } + /** 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)