diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index c5acf041..69f14c44 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 242 - versionName = "0.108.82-smart-setup" + versionCode = 243 + versionName = "0.108.83-smart-setup" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/assets/phone/companion.html b/android/app/src/main/assets/phone/companion.html index 049774b1..c8c78d4d 100644 --- a/android/app/src/main/assets/phone/companion.html +++ b/android/app/src/main/assets/phone/companion.html @@ -309,7 +309,7 @@ function create() { } else { body = `
Review
${esc(d.name)}
Yours${d.number ? ' · ' + d.number : ''} · ${STYLES.find(s => s[0] === d.style)[1]} · ${HOURS.find(([h]) => sameHours(h, d.hours))?.[1] || 'Set hours'}
- ${d.shows.slice(0, 8).map(s => `
${d.core.includes(s.id) ? '★ ' : ''}${esc(s.title)}${d.style === 'Shaped' ? ` · ${esc(d.slots[s.id] || 'Evening')}` : ''}
`).join('')}${d.shows.length > 8 ? `
and ${d.shows.length - 8} more
` : ''}
` + note; + ${d.shows.slice(0, 8).map(s => `
${d.core.includes(s.id) ? '★ ' : ''}${esc(s.title)}${d.style === 'Shaped' ? ` · ${esc(d.slots[s.id] || 'Evening')}` : ''}
`).join('')}${d.shows.length > 8 ? `
and ${d.shows.length - 8} more
` : ''}` + clashCard() + note; next = ``; } return top + body + `
${next}
`; @@ -325,6 +325,23 @@ async function switchTo(id, pin) { else { toast(e.message); } } } +// The clash check (Paul, 7 November 2026): picks your other channels already show. Orbit never airs one title on two channels +// at once, so it's for knowing, and each can be taken out here. +function clashCard() { + const c = state.create, d = c.draft, cl = c.clashes; + if (!cl) return '
Checking your other channels…
'; + const hits = d.shows.filter(x => cl[x.id]?.length); + if (!hits.length) return '
None of these are on your other channels.
'; + return `
Also on your other channels
` + + hits.map(x => `
${esc(x.title)}
+
${cl[x.id].map(esc).join(', ')}
`).join('') + + '
Orbit never shows the same title on two channels at the same time, so keeping them is fine.
'; +} +async function checkClashes() { + const c = state.create; c.clashes = null; render(); + try { c.clashes = (await api('/api/clashes', {shows: c.draft.shows.map(x => ({id: x.id, title: x.title})), number: c.draft.number})).clashes; } catch (e) { c.clashes = {}; } + render(); +} function startCreate(draft) { draft.slots = draft.slots || {}; draft.core = draft.core || []; state.create = {step: 0, draft, offered: [], note: '', busy: false, mode: 'describe', browse: {type: '', genre: '', studio: '', rating: ''}, shape: null}; render(); } // Smart setup: what the library has to browse by, and the Director's layout for the chosen shows. async function loadFacets() { if (state.facets) return; try { state.facets = await api('/api/facets'); } catch (e) { state.create.note = e.message; } render(); } @@ -455,7 +472,7 @@ document.addEventListener('click', e => { if (d.cnext) { const c = state.create; if (c.step === 0) { c.draft.name = ($('#cname')?.value || '').trim(); if (!c.draft.name) { toast('Give it a name first'); return; } } if (c.step === 1 && !c.draft.shows.length) return; - c.step++; c.note = ''; render(); scrollTo(0, 0); if (c.step === 2 && c.draft.style === 'Shaped') shapeShows(); return; } + c.step++; c.note = ''; render(); scrollTo(0, 0); if (c.step === 2 && c.draft.style === 'Shaped') shapeShows(); if (c.step === 4) checkClashes(); return; } if (d.csuggest) { suggestShows(); return; } if (d.ctoggle) { const dr = state.create.draft, id = d.ctoggle; if ($('#cdesc')) dr.description = $('#cdesc').value.trim(); if (dr.shows.some(s => s.id === id)) dr.shows = dr.shows.filter(s => s.id !== id); @@ -470,6 +487,8 @@ document.addEventListener('click', e => { if (d.ccore) { const c = state.create, id = d.ccore; c.coreSet = true; c.draft.core = c.draft.core.includes(id) ? c.draft.core.filter(x => x !== id) : [...c.draft.core, id].slice(-5); render(); return; } if (d.chours !== undefined) { state.create.draft.hours = HOURS[+d.chours][0]; render(); return; } + if (d.cout) { const dr = state.create.draft; dr.shows = dr.shows.filter(x => x.id !== d.cout); dr.core = dr.core.filter(x => x !== d.cout); delete dr.slots[d.cout]; + if (!dr.shows.length) { state.create.step = 1; } render(); return; } if (d.cmake) { makeChannel(); return; } if (d.homedone) { try { localStorage.setItem('orbit.home', '1'); } catch {} closeSheet(); return; } if (d.install) { installAsk?.prompt(); installAsk = null; try { localStorage.setItem('orbit.home', '1'); } catch {} closeSheet(); return; } diff --git a/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt b/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt index 34ee7b71..a40a6d30 100644 --- a/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt +++ b/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt @@ -48,7 +48,9 @@ internal class ChannelMaker( /** Smart setup: browse the library, its genres and networks, and how the Director would lay chosen titles out. */ val browse: suspend (genre: String?, studio: String?, ratings: Set, type: String?) -> List = { _, _, _, _ -> emptyList() }, val facets: suspend () -> Pair, List> = { emptyList() to emptyList() }, - val shapeOf: suspend (List) -> List = { emptyList() }) + val shapeOf: suspend (List) -> List = { emptyList() }, + /** For each title, the other channels already showing it (Paul, 7 November 2026: "check conflicts with the rest of the channels"). */ + val carriedBy: (picks: Map, number: Int?) -> Map> = { _, _ -> emptyMap() }) internal enum class CreateStep(val title: String) { Start("Create a channel"), Name("Name and number"), Shows("Shows and films"), Style("How it plays"), Hours("When it's on") } diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index e9635005..dc1121bb 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI } /** The sign-in headers for this kind of server. */ internal fun authHeaders(token: String?): Map = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.82\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.83\"") + (token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap()) - ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.82\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.83\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ 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 a9e84b50..228b72c6 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -544,6 +544,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea browse = { genre, studio, ratings, type -> withContext(Dispatchers.IO) { catalogue.browseRows(genre, studio, ratings, type) } }, facets = { withContext(Dispatchers.IO) { catalogue.facets() } }, shapeOf = { ids -> withContext(Dispatchers.IO) { catalogue.shapeRows(ids) } }, + carriedBy = { picks, number -> titlesCarriedBy(picks, scheduledChannels.values.filter { it.number != number }) }, create = { asked, shows -> // Shaped on the TV, or from the phone without a layout: the Director lays it out from the catalogue. val channel = if (asked.style == PlayStyle.Shaped && asked.slots.isEmpty()) withContext(Dispatchers.IO) { diff --git a/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt b/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt index 87095dcc..43b42e3a 100644 --- a/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt +++ b/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt @@ -324,6 +324,13 @@ internal object PhoneLink { json(out, 200, JSONObject().put("slots", JSONObject(shape.slots.mapValues { it.value.name })).put("core", JSONArray(shape.core.toList())) .put("week", weekCheck(series, films) ?: JSONObject.NULL)) } + "POST /api/clashes" -> { + val o = runCatching { JSONObject(r.body) }.getOrNull() ?: return json(out, 400, JSONObject()) + val picks = runCatching { o.getJSONArray("shows").let { a -> (0 until minOf(a.length(), 200)).map { a.getJSONObject(it) } + .filter { EmbyClient.validId(it.optString("id")) }.associate { it.getString("id") to it.optString("title").take(160) } } }.getOrDefault(emptyMap()) + val carried = runBlocking { withContext(mainDispatcher) { h.maker.carriedBy(picks, o.optInt("number").takeIf { it > 0 }) } } + json(out, 200, JSONObject().put("clashes", JSONObject(carried.mapValues { JSONArray(it.value) }))) + } "POST /api/channels" -> { if (!OrbitCompanion.grownUp) return json(out, 403, JSONObject().put("error", "Kids is watching. Switch to Adult to make channels.")) val o = runCatching { JSONObject(r.body) }.getOrNull() ?: return json(out, 400, JSONObject().put("error", "Unreadable")) diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index 5d24f9fc..64180002 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -39,7 +39,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B next.instanceFollowRedirects = false next.connectTimeout = 10_000 next.readTimeout = 20_000 - next.setRequestProperty("User-Agent", "OrbitTV/0.108.82") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.83") next.setRequestProperty("Accept-Encoding", "identity") session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) } if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) { diff --git a/android/app/src/main/java/tv/orbit/classic/SmartSetup.kt b/android/app/src/main/java/tv/orbit/classic/SmartSetup.kt index 6a9b6a76..4989d0dc 100644 --- a/android/app/src/main/java/tv/orbit/classic/SmartSetup.kt +++ b/android/app/src/main/java/tv/orbit/classic/SmartSetup.kt @@ -51,3 +51,24 @@ internal fun shapedParts(slots: Map): List = Slot.entries slots.filterValues { it == s }.keys.toList().takeIf { it.isNotEmpty() }?.let { DayPart(s.fromHour, s.toHour, it) } } internal fun shapedWeights(core: Set): Map = core.associate { seriesKey(it) to TIER_CORE } + +/** + * Which of the [picks] (item id to title) the [channels] already show, by their plans: id to channel names. A title counts by + * its item or by its name, since a library can hold more than one copy of a show. Orbit never airs a shared title on two + * channels at once, so this is for the viewer to know, not a problem to fix. + */ +internal fun titlesCarriedBy(picks: Map, channels: Collection): Map> { + if (picks.isEmpty()) return emptyMap() + val byKey = picks.entries.groupBy({ seriesKey(it.value) }, { it.key }) + val out = LinkedHashMap>() + channels.sortedBy { it.number }.forEach { channel -> + val label = "${channel.number} ${ChannelBrands.displayName(channel)}" + val hit = HashSet() + channel.plan.entries.forEach { e -> + if (e.seriesId in picks) hit += e.seriesId + byKey[seriesKey(guideTitleParts(e.media.item.title).first)]?.let(hit::addAll) + } + hit.forEach { out.getOrPut(it) { mutableListOf() } += label } + } + return out +} diff --git a/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt b/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt index 386d07e7..1ac92a99 100644 --- a/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt @@ -38,4 +38,15 @@ class SmartSetupTest { assertNull(programmingOf(channel.copy(style = PlayStyle.Standard)).tierWeights) assertTrue(programmingOf(channel.copy(style = PlayStyle.Standard)).dayParts.isEmpty()) } + + @Test fun theClashCheckFindsPicksOtherChannelsShowByItemOrByName() { + val minute = 60_000L; val now = 1_793_000_000_000L + fun media(id: String, title: String) = ScheduledMedia(SampleItem(title, "Episode", 30, "", id, 30 * minute), "s-$id", 30 * minute) + val loop = SampleChannel(listOf(media("e1", "Better Call Saul / S1 E1 / Uno"), media("e2", "Aquaman")), "Orbit Signature", 109) + val plan = ChannelPlan(listOf(ScheduleEntry("bcs-copy", EpisodeMark(1, 1), media("e1", "Better Call Saul / S1 E1 / Uno"), now), + ScheduleEntry("aq", EpisodeMark(0, 1), media("e2", "Aquaman"), now + 30 * minute)), ScheduleCursor()) + val carried = titlesCarriedBy(mapOf("bcs" to "Better Call Saul", "aq" to "Aquaman", "dw" to "Doctor Who"), listOf(ScheduledChannel(loop, plan))) + assertEquals(setOf("bcs", "aq"), carried.keys) // another copy of the show still counts + assertTrue(carried.getValue("bcs").single().startsWith("109 ")) + } }