Jellyfin: Orbit speaks to Jellyfin servers as well as Emby
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m57s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m34s

Ported from release 0.108.44.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 04:02:20 +00:00
co-authored by Claude Opus 5.5
parent c1d985ed5e
commit e7d4243271
7 changed files with 131 additions and 22 deletions
@@ -37,11 +37,13 @@ class EmbyServerTest {
assertTrue(PlaybackUrls.isProvider(URI("https://emby.example.com:443/emby/Videos/1/stream")))
}
@Test fun checkServerAcceptsEmbyOnly() {
@Test fun checkServerAcceptsEmbyAndJellyfin() {
fun check(status: Int, body: String) = EmbyClient { EmbyReply(status, body) }.checkServer()
assertEquals("Home", check(200, """{"Id":"abc","Version":"4.8.0","ServerName":"Home"}"""))
assertEquals("Emby", check(200, """{"Id":"abc","Version":"4.8.0"}"""))
for ((status, body) in listOf(404 to "", 200 to "<html>", 200 to """{"Version":"4.8"}""", 200 to """{"Id":"a","Version":"10.9","ProductName":"Jellyfin Server"}""")) {
// Jellyfin too, since Orbit speaks to it (6 November 2026).
assertEquals("Jellyfin", check(200, """{"Id":"a","Version":"10.11.9","ProductName":"Jellyfin Server"}"""))
for ((status, body) in listOf(404 to "", 200 to "<html>", 200 to """{"Version":"4.8"}""")) {
try { check(status, body); fail("Accepted $body") } catch (_: EmbyCheckException) { }
}
}
@@ -0,0 +1,70 @@
package tv.orbit.classic
import org.junit.After
import org.junit.Assert.*
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
import java.net.HttpURLConnection
import java.net.URL
/**
* Orbit against a real Jellyfin server (Paul, 6 November 2026), run on this computer with a small made-up library:
* ORBIT_JELLYFIN=http://172.17.0.2:8096 ORBIT_JELLYFIN_ACCOUNT=<file with user= and password=> ./gradlew :app:testDebugUnitTest --tests '*JellyfinLiveTest*'
* The same code the box runs: sign-in, the catalogue, a channel read, the Drive-In's curated films and a stream.
*/
class JellyfinLiveTest {
@After fun reset() { CuratedDriveInEvents.list = emptyList(); CuratedDriveInEvents.copies = emptyMap(); EmbyServer.origin = EmbyServer.DEFAULT }
private class MemoryCatalogue : CatalogueSink {
val records = mutableListOf<CatalogueRecord>(); var next = 0L; var finished = false
override fun position(userId: String) = next
override fun write(userId: String, records: List<CatalogueRecord>, nextStart: Long, total: Long?, finished: Boolean) { this.records += records; next = nextStart; this.finished = finished }
fun idsByImdb(imdbs: Collection<String>) = imdbs.map { it.lowercase() }.associateWith { imdb ->
records.filter { it.type == "Movie" && it.providerIds.entries.any { (k, v) -> k.equals("Imdb", true) && v.lowercase() == imdb } }.map { it.id } }.filterValues { it.isNotEmpty() }
}
@Test fun orbitWorksWithJellyfin() {
val origin = System.getenv("ORBIT_JELLYFIN")?.let(EmbyServer::normalise)
val account = System.getenv("ORBIT_JELLYFIN_ACCOUNT")?.let(::File)
assumeTrue(origin != null && account != null && account.isFile)
val fields = account!!.readLines().filter { '=' in it }.associate { it.substringBefore('=') to it.substringAfter('=') }
EmbyServer.origin = origin!!
val transport = HttpsEmbyTransport("orbit-live-test", origin)
assertTrue(EmbyClient(transport).checkServer().isNotBlank())
assertEquals(ServerKind.Jellyfin, transport.kind)
val session = EmbyClient(transport).connect(fields.getValue("user"), fields.getValue("password"))
// A channel: Paradox finds Buffy, its three episodes playable.
val store = ScheduleStore(kotlin.io.path.createTempDirectory("jellyfin").toFile())
val catalogue = MemoryCatalogue()
session.importCatalogue(catalogue, CATALOGUE_PAGES_FULL_RUN)
assertTrue(catalogue.finished); assertTrue(catalogue.records.any { it.title == "Buffy the Vampire Slayer" })
val scheduler = ChannelScheduler(store, copies = catalogue::idsByImdb, original = false)
val paradox = SmartChannels.single { it.name == "Paradox" }
scheduler.setEnabled(session.accountId, paradox.number, true)
val loop = scheduler.seedLoop(session, session.accountId, paradox)
assertEquals(listOf("Buffy the Vampire Slayer"), store.loadPool(session.accountId, paradox.number)!!.series.map { it.title })
assertTrue(scheduler.topUp(session, session.accountId, paradox, loop).programmes > 0)
// The Drive-In: Universal's three films found by IMDb ID and verified; Hammer isn't in this library.
assertTrue(CuratedDriveInEvents.refresh(catalogue::idsByImdb))
assertEquals(listOf("universal"), CuratedDriveInEvents.list.map { it.key })
val universal = CuratedDriveInEvents.list.single()
val checks = session.readFilmChecks(universal.films.map { it to null })
assertTrue(checks.values.map { it.reason }.toString(), checks.values.all { it.film != null })
// A stream: prepared as the player does, then the first bytes read with the headers it sends.
val episode = store.loadPlan(session.accountId, paradox.number)!!.entries.first().media.item
session.rememberScheduledItems(listOf(episode))
val plan = session.prepare(episode)
assertTrue(plan.url, plan.url.startsWith(origin))
val connection = URL(session.mediaUrl(plan.url)).openConnection() as HttpURLConnection
session.mediaHeaders(plan.url).forEach { (k, v) -> connection.setRequestProperty(k, v) }
connection.setRequestProperty("Range", "bytes=0-1023")
assertTrue("stream ${connection.responseCode}", connection.responseCode in listOf(200, 206))
assertTrue(connection.inputStream.use { it.readNBytes(1024) }.size > 100)
connection.disconnect()
assertTrue(session.close())
}
}