0.90.0: film matching by identity (title, year, IMDb ID), with a baseline of every ambiguous film
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m47s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m28s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-03 14:12:36 +00:00
co-authored by Claude Opus 5.5
parent 69ddf45ee6
commit 81a5c61932
24 changed files with 431 additions and 55 deletions
@@ -287,8 +287,8 @@ class ChannelScheduleTest {
.put(JSONObject().put("Id", "original").put("Type", "Movie").put("Name", "Halloween").put("ProductionYear", 1978).put("RunTimeTicks", 60_000_000_000L)
.put("MediaSources", JSONArray().put(JSONObject().put("Id", "s3").put("Container", "mkv"))))
val transport = EmbyTransport { EmbyReply(200, JSONObject().put("Items", rows).toString()) }
assertEquals("original", findFilm(transport, user, { "t" }, "Halloween")?.id)
assertNull(findFilm(transport, user, { "t" }, "Halloween Ends"))
assertEquals("original", findFilm(transport, user, { "t" }, "Halloween (1978)").film?.id)
assertNull(findFilm(transport, user, { "t" }, "Halloween Ends").film)
}
@Test fun aDayJumpStaysBetweenNowAndAWeekAhead() {
@@ -0,0 +1,99 @@
package tv.orbit.classic
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Test
/** Which film a list entry means, against the library as it was on 3 November 2026, and what happens when it can't be found or played. */
class FilmMatchingTest {
private val user = "0123456789abcdef0123456789abcdef"
private fun source(id: String, container: String = "mkv") = JSONObject().put("Id", id).put("Container", container)
private fun candidate(id: String, name: String, year: Int?, imdb: String? = null, playable: Boolean = true) =
FilmCandidate(id, name, year, imdb, if (playable) listOf(source("s$id")) else listOf(source("s$id", "iso")), 90 * 60 * 10_000_000L)
private val baseline: JSONArray = JSONArray(javaClass.classLoader!!.getResource("film-matching-baseline.json")!!.readText())
@Test fun everyAmbiguousListEntryResolvesToTheIntendedFilm() {
var wrongToday = 0
for (i in 0 until baseline.length()) {
val row = baseline.getJSONObject(i)
val library = row.getJSONArray("library").let { list -> (0 until list.length()).map { list.getJSONObject(it) } }
.map { candidate(it.getString("id"), it.getString("name"), it.optInt("year").takeIf { y -> y > 0 }, it.optString("imdb").takeIf { s -> s.startsWith("tt") }) }
val entry = row.getString("entry")
val found = resolveFilm(FilmIdentity.of(entry), library).film
assertNotNull(entry, found)
val chosen = library.first { it.id == found!!.id }
assertEquals(entry, row.getInt("intended"), chosen.year)
assertEquals(entry, row.getString("imdb"), chosen.imdb)
if (!row.isNull("today") && row.getInt("today") != row.getInt("intended")) wrongToday++
}
assertEquals("films playing the wrong version on the box before this change", 60, wrongToday)
}
@Test fun theListEntryReadsItsYear() {
assertEquals(FilmIdentity("Halloween", 1978, "tt0077651"), FilmIdentity.of("Halloween (1978)"))
assertEquals(FilmIdentity("Blade Runner 2049"), FilmIdentity.of("Blade Runner 2049"))
assertEquals("2001: A Space Odyssey", FilmIdentity.of("2001: A Space Odyssey").title)
assertEquals(FilmIdentity("Lilo & Stitch", 2002, "tt0275847"), FilmIdentity.of("Lilo & Stitch (2002)"))
}
@Test fun aRemakeIsNeverTakenForTheOriginal() {
val library = listOf(candidate("remake", "Ghostbusters", 2016), candidate("original", "Ghostbusters", 1984))
assertEquals("original", resolveFilm(FilmIdentity.of("Ghostbusters (1984)"), library).film?.id)
assertEquals("remake", resolveFilm(FilmIdentity.of("Ghostbusters (2016)"), library).film?.id)
}
@Test fun anUnplayableOriginalMeansNoFilmNotTheRemake() {
val library = listOf(candidate("remake", "Dumbo", 2019), candidate("original", "Dumbo", 1941, playable = false))
val found = resolveFilm(FilmIdentity.of("Dumbo (1941)"), library)
assertNull(found.film)
assertTrue(found.note, found.note.contains("unplayable"))
}
@Test fun aTitleWithoutAYearIsOnlyTakenWhenTheLibraryHasOneFilmOfThatName() {
assertEquals("only", resolveFilm(FilmIdentity.of("Repo Man"), listOf(candidate("only", "Repo Man", 1984))).film?.id)
val two = resolveFilm(FilmIdentity.of("Batman"), listOf(candidate("a", "Batman", 1966), candidate("b", "Batman", 1989)))
assertNull(two.film)
assertTrue(two.note, two.note.contains("needs a year"))
}
@Test fun twoFilmsWithTheSameNameAndYearAreToldApartByIMDb() {
val library = listOf(candidate("other", "Ghost", 1990, "tt0087329"), candidate("swayze", "Ghost", 1990, "tt0099653"))
assertEquals("swayze", resolveFilm(FilmIdentity.of("Ghost (1990)"), library).film?.id)
assertNull(resolveFilm(FilmIdentity("Ghost", 1990), library).film)
}
@Test fun anotherCopyOfTheSameFilmIsFine() {
val library = listOf(candidate("a", "Alien", 1979, "tt0078748", playable = false), candidate("b", "Alien", 1979, "tt0078748"), candidate("c", "Alien", 1992))
val found = resolveFilm(FilmIdentity.of("Alien (1979)"), library)
assertEquals("b", found.film?.id)
assertTrue(found.note, found.note.contains("passed over"))
}
@Test fun aYearOutByOneCountsOnlyWhenNothingElseIsNear() {
assertEquals("x", resolveFilm(FilmIdentity("The Evil Dead", 1981), listOf(candidate("x", "The Evil Dead", 1982), candidate("y", "The Evil Dead", 2013))).film?.id)
assertNull(resolveFilm(FilmIdentity("Film", 2000), listOf(candidate("x", "Film", 1999), candidate("y", "Film", 2001))).film)
}
@Test fun aFilmMissingFromTheLibraryIsSaidSo() {
assertTrue(resolveFilm(FilmIdentity.of("Nothing Here (1990)"), emptyList()).note.contains("not in the library"))
}
@Test fun theSearchReadsPastTheFirstPage() {
val requests = mutableListOf<String>()
val transport = EmbyTransport { request ->
requests += request.path
val start = Regex("StartIndex=(\\d+)").find(request.path)!!.groupValues[1].toInt()
val rows = JSONArray()
if (start < 100) (0 until 50).forEach { rows.put(JSONObject().put("Id", "${"%032x".format(start + it + 1)}").put("Type", "Movie").put("Name", "A Halloween Story $it").put("ProductionYear", 2001)) }
else rows.put(JSONObject().put("Id", "f".repeat(32)).put("Type", "Movie").put("Name", "Halloween").put("ProductionYear", 1978)
.put("ProviderIds", JSONObject().put("Imdb", "tt0077651")).put("RunTimeTicks", 54_000_000_000L).put("MediaSources", JSONArray().put(source("e".repeat(32)))))
EmbyReply(200, JSONObject().put("Items", rows).put("TotalRecordCount", 101).toString())
}
assertEquals("f".repeat(32), findFilm(transport, user, { "t" }, "Halloween (1978)").film?.id)
assertEquals(3, requests.size)
assertTrue(requests.first().contains("Years=1977,1978,1979"))
assertTrue(requests.first().contains("ProviderIds"))
}
}