Titles approved outside the app join their channels' lists, only ever added (build 71)
approve-add reads install-restore/approve.json with confirm ADD while Orbit is closed. Each title joins its channel's list as a Chair placement does; copies of a work already there are skipped, so a second run changes nothing; the channel files touched are kept in approved-<time>/; one bad entry refuses the lot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ plugins {
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
}
|
||||
/** The release's build number: versionCode is this x 10 plus the edition's channel. */
|
||||
val ORBIT_BUILD = 70
|
||||
val ORBIT_BUILD = 71
|
||||
android {
|
||||
namespace = "tv.orbit.classic"
|
||||
compileSdk = 36
|
||||
|
||||
@@ -20,7 +20,10 @@ import java.security.MessageDigest
|
||||
* only while Orbit's screen isn't open, only files a snapshot takes, each checked against its checksum first, and the
|
||||
* current data is kept aside before anything is replaced.
|
||||
*
|
||||
* Apart from `restore`, it only ever copies; it never changes the schedules, the library or the sign-in.
|
||||
* - `approve-add` (23 November 2026): titles you approved outside the app, from install-restore/approve.json, added to their
|
||||
* channels' lists with `confirm ADD` while Orbit's screen isn't open. See [ApprovedTitles]: it only adds.
|
||||
*
|
||||
* Apart from `restore` and `approve-add`, it only ever copies; it never changes the schedules, the library or the sign-in.
|
||||
*/
|
||||
class InstallSnapshotReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
@@ -42,6 +45,21 @@ class InstallSnapshotReceiver : BroadcastReceiver() {
|
||||
tv.orbit.classic.arcade.hive.HiveLegacy.adoptCopy(File(context.filesDir, "arcade"), incoming, intent.getStringExtra("sha256"),
|
||||
intent.getStringExtra("confirm"), intent.getStringExtra("from"), System.currentTimeMillis())
|
||||
} finally { incoming.delete() }
|
||||
} else if (intent.getStringExtra("do") == "approve-add") {
|
||||
// Titles you approved outside the app ([ApprovedTitles]): adb pushes install-restore/approve.json; it's read once and removed.
|
||||
val incoming = File(context.getExternalFilesDir(null), "install-restore/approve.json")
|
||||
try {
|
||||
val target = Workspaces.current(context)
|
||||
resultData = when {
|
||||
intent.getStringExtra("confirm") != "ADD" -> "refused: needs confirm ADD"
|
||||
OrbitScreen.open -> "refused: Orbit is open; force-stop it first"
|
||||
!incoming.exists() -> "refused: no approve.json"
|
||||
else -> ServerMove.userOf(target.scheduleDir)?.let { user ->
|
||||
ApprovedTitles.add(target.scheduleDir, user, org.json.JSONArray(incoming.readText()), System.currentTimeMillis()) } ?: "refused: no saved schedules"
|
||||
}
|
||||
} catch (e: Exception) { resultData = "failed: ${e.javaClass.simpleName}" } finally { incoming.delete() }
|
||||
android.util.Log.i("OrbitInstall", "approve-add: $resultData")
|
||||
return
|
||||
} else if (intent.getStringExtra("do").orEmpty().startsWith("move-")) {
|
||||
// Reading two catalogues takes a few seconds: off the main thread, answered when done.
|
||||
val pending = goAsync()
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Titles you approved outside the app (Stage 3 replacements, 23 November 2026), added to channels' lists exactly as the
|
||||
* Director's Chair places a title: each joins its channel's list at the next top-up, and nothing already booked moves.
|
||||
*
|
||||
* - it only adds: nothing on a list is removed or changed, and a title you approve comes off that channel's "rejected" list
|
||||
* (your approval is the newer decision), as it does in the Chair;
|
||||
* - a title already on the channel, as the same item or another copy of the same work (name and year), isn't added twice,
|
||||
* so running it again changes nothing;
|
||||
* - every channel file it touches is kept as it was in approved-<time>/ beside the schedules, to put back if wanted;
|
||||
* - each entry is checked first, and any bad entry refuses the lot.
|
||||
*
|
||||
* An entry: {"c": channel, "i": item id, "t": title, "y": year or null, "k": "Movie" or "Series", "p": provider ref or "", "r": why}.
|
||||
*/
|
||||
internal object ApprovedTitles {
|
||||
private val REF = Regex("(imdb|tmdb|tvdb)\\.[A-Za-z0-9_-]{1,40}")
|
||||
|
||||
fun add(dir: File, userId: String, entries: JSONArray, nowMs: Long): String {
|
||||
val rows = (0 until entries.length()).map { entries.getJSONObject(it) }
|
||||
if (rows.isEmpty()) return "refused: nothing to add"
|
||||
val wanted = rows.map { o ->
|
||||
val channel = o.optInt("c", -1).takeIf { it in 100..999 } ?: return "refused: a bad channel"
|
||||
val id = o.optString("i").takeIf(EmbyClient::validId) ?: return "refused: a bad item id"
|
||||
val type = o.optString("k").takeIf { it == "Movie" || it == "Series" } ?: return "refused: a bad type for $id"
|
||||
val title = o.optString("t").trim().take(160).takeIf { it.isNotEmpty() } ?: return "refused: no title for $id"
|
||||
val ref = o.optString("p").takeIf { it.isEmpty() || REF.matches(it) } ?: return "refused: a bad ref for $id"
|
||||
channel to Suggestion(id, title, if (o.isNull("y")) null else o.optInt("y"), type, "", o.optString("r").take(200).ifBlank { "Approved by you" }, ref = ref)
|
||||
}
|
||||
val store = ScheduleStore(dir)
|
||||
val keep = File(dir, "approved-$nowMs")
|
||||
val report = StringBuilder()
|
||||
var added = 0
|
||||
for ((channel, list) in wanted.groupBy({ it.first }, { it.second }).toSortedMap()) {
|
||||
val before = store.loadChoices(userId, channel)
|
||||
fun work(s: Suggestion) = filmKey(s.title) + "|" + (s.year ?: "")
|
||||
val have = before.accepted.map { it.id }.toMutableSet(); val works = before.accepted.map(::work).toMutableSet()
|
||||
val fresh = list.filter { s -> s.id !in have && work(s) !in works && have.add(s.id) && works.add(work(s)) }
|
||||
report.append(" $channel+${fresh.size}")
|
||||
if (fresh.isEmpty()) continue
|
||||
File(dir, "choices-$channel.json").takeIf { it.exists() }?.let { keep.mkdirs(); it.copyTo(File(keep, it.name), overwrite = true) }
|
||||
store.saveChoices(userId, channel, ChannelChoices(before.accepted + fresh, before.rejected - fresh.map { it.id }.toSet()))
|
||||
added += fresh.size
|
||||
}
|
||||
return "added $added:$report" + if (keep.exists()) " (kept ${keep.name})" else ""
|
||||
}
|
||||
|
||||
/** Entries as [add] takes them, for tests and tools. */
|
||||
fun entry(channel: Int, id: String, title: String, year: Int?, type: String, ref: String = "", why: String = "") =
|
||||
JSONObject().put("c", channel).put("i", id).put("t", title).put("y", year ?: JSONObject.NULL).put("k", type).put("p", ref).put("r", why)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
/** Titles approved outside the app (Stage 3 replacements, 23 November 2026): only ever added, never twice. */
|
||||
class ApprovedTitlesTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
private val user = "8d5f95222bdd4ad3b841f53e18c25056"
|
||||
|
||||
@Test fun approvedTitlesJoinTheirChannelsOnceAndNothingElseChanges() {
|
||||
val dir = tmp.newFolder("schedule")
|
||||
val store = ScheduleStore(dir)
|
||||
val existing = Suggestion("1001", "Robot Wars", 1998, "Series", "", "Placed by you")
|
||||
store.saveChoices(user, 108, ChannelChoices(listOf(existing), setOf("2002", "9999")))
|
||||
val list = JSONArray(listOf(
|
||||
ApprovedTitles.entry(108, "2002", "Deal or No Deal (UK)", 2005, "Series", "tvdb.79227", "Stage 3"),
|
||||
ApprovedTitles.entry(108, "2003", "Robot Wars", 1998, "Series"), // another copy of a title already there
|
||||
ApprovedTitles.entry(205, "3003", "River Cottage", 1999, "Series")))
|
||||
val first = ApprovedTitles.add(dir, user, list, 1_000L)
|
||||
assertTrue(first, first.startsWith("added 2: 108+1 205+1"))
|
||||
val play = store.loadChoices(user, 108)
|
||||
assertEquals(listOf("1001", "2002"), play.accepted.map { it.id })
|
||||
assertEquals("tvdb.79227", play.accepted.last().ref)
|
||||
assertEquals(setOf("9999"), play.rejected) // only the approved one leaves "rejected"
|
||||
assertEquals(listOf("3003"), store.loadChoices(user, 205).accepted.map { it.id })
|
||||
// Kept as it was before: the channel that had a file.
|
||||
assertTrue(java.io.File(dir, "approved-1000/choices-108.json").exists())
|
||||
// A second run adds nothing and keeps nothing.
|
||||
assertEquals("added 0: 108+0 205+0", ApprovedTitles.add(dir, user, list, 2_000L))
|
||||
assertTrue(!java.io.File(dir, "approved-2000").exists())
|
||||
}
|
||||
|
||||
@Test fun oneBadEntryRefusesTheLot() {
|
||||
val dir = tmp.newFolder("schedule")
|
||||
val list = JSONArray(listOf(ApprovedTitles.entry(205, "3003", "River Cottage", 1999, "Series"), ApprovedTitles.entry(205, "not an id!", "X", null, "Series")))
|
||||
assertTrue(ApprovedTitles.add(dir, user, list, 1L).startsWith("refused"))
|
||||
assertTrue(ScheduleStore(dir).loadChoices(user, 205).accepted.isEmpty())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user