Report of list titles missing from the library (env-gated, read-only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 07:35:56 +00:00
co-authored by Claude Opus 5.5
parent b16ab169b0
commit f8d172e341
@@ -0,0 +1,41 @@
package tv.orbit.classic
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
/**
* Titles the channels' lists name that the library doesn't have (Paul, 26 November 2026: what to request). Read-only: matched
* against the catalogue export (SIM_CATALOGUE) by the same names and years the refresh uses. Writes SIM_OUT/missing.tsv.
*/
class MissingTitlesReportTest {
@Test fun report() {
val cat = System.getenv("SIM_CATALOGUE")?.let(::File)
assumeTrue(cat != null && cat.exists())
val rows = cat!!.readLines().map { it.split('\t') }.filter { it.size >= 5 }
val films = rows.filter { it[1] == "Movie" }.groupBy { seriesKey(it[2]) }
val series = rows.filter { it[1] == "Series" }.map { seriesKey(it[2]) }
val seriesSet = series.toSet()
val out = StringBuilder("channel\tname\tkind\tentry\treason\n")
for (p in BuiltInChannels) {
val choices = ChannelChoices()
for (e in refreshEntries(p, choices)) {
val reason = when (e.kind) {
RefreshEntry.Kind.FILM -> {
val id = FilmIdentity.of(e.text); val named = films[seriesKey(id.title)].orEmpty()
when {
named.isEmpty() -> "not in library"
id.imdb != null && named.none { it[4].equals(id.imdb, true) } && id.year != null && named.none { it[3].toIntOrNull()?.let { y -> kotlin.math.abs(y - id.year) <= 1 } == true } -> "only other films of that name"
id.year != null && named.none { it[3].toIntOrNull()?.let { y -> kotlin.math.abs(y - id.year) <= 1 } == true } && named.none { id.imdb != null && it[4].equals(id.imdb, true) } -> "only other years: " + named.mapNotNull { it[3].ifEmpty { null } }.distinct().joinToString(",")
else -> null
}
}
RefreshEntry.Kind.SERIES -> { val k = seriesKey(e.text); if (k in seriesSet || series.any { it.startsWith("$k ") }) null else "not in library" }
else -> null
} ?: continue
out.append("${p.number}\t${p.name}\t${e.kind}\t${e.text}\t$reason\n")
}
}
File(System.getenv("SIM_OUT")!!).also { it.mkdirs() }.resolve("missing.tsv").writeText(out.toString())
}
}