Added Rekordbox capabilities handling

This commit is contained in:
patben8 committed 2026-09-18 09:36:05 +02:00
1 parent 4592e13228
commit 010f67cd2d
14 files changed
+297 -43

No files matched your search

@@ -37,9 +37,14 @@ HOTCUE_SLOTS = 8
def capabilities_for(
path, version: str | None = None, *, cloud_synced: bool = False
) -> Capabilities:
# A cloud-synced library is refused PERMANENTLY, not pending a milestone:
# a local edit the server did not issue could propagate a broken sync state
# to the user's other machines, which version history cannot undo.
return Capabilities(
platform="rekordbox",
version=version,
writable=False,
readonly_cause="cloud_synced" if cloud_synced else "platform_incomplete",
cues=CueCapabilities(
hotcue_slots=HOTCUE_SLOTS,
slot_labels="letter",
@@ -41,6 +41,7 @@ def capabilities_for(path: Path, editable_fields: list[str]) -> Capabilities:
return Capabilities(
platform="traktor",
version=nml_version(path),
writable=True,
cues=CueCapabilities(
hotcue_slots=8,
slot_labels="number",
+17
View File
@@ -15,6 +15,13 @@ from typing import Literal
from pydantic import BaseModel
# Why a library cannot be edited. A FACT, not a sentence — the UI composes the
# wording (lib/platformCopy.ts), and the two causes need very different ones:
# "Konduktor cannot write this platform YET" is a roadmap gap the user should
# expect to close, whereas "this library is synced with Rekordbox Cloud" is a
# permanent refusal protecting their other machines.
ReadonlyCause = Literal["platform_incomplete", "cloud_synced"]
CueType = Literal["cue", "fade_in", "fade_out", "load", "loop"]
CueRole = Literal["hotcue", "memory"]
MediaKind = Literal["audio", "stem", "video"]
@@ -74,6 +81,16 @@ class SaveCapabilities(BaseModel):
class Capabilities(BaseModel):
platform: str
version: str | None = None
# Whether ANY edit can be persisted to this library.
#
# This is deliberately NOT the same as every individual capability being
# false. "The platform has no such feature" and "this library cannot be
# written at all" look identical to a UI that only sees the per-feature
# flags, and the second one needs saying out loud — silently inert controls
# read as a bug. When this is false the per-feature flags are still reported
# honestly, so the UI can show what the platform *would* support.
writable: bool = True
readonly_cause: ReadonlyCause | None = None
cues: CueCapabilities = CueCapabilities()
grid: GridCapabilities = GridCapabilities()
tracks: TrackCapabilities = TrackCapabilities()
+41
View File
@@ -195,6 +195,13 @@ with tempfile.TemporaryDirectory() as d:
print("== capabilities gate the UI ==")
caps = adapter.capabilities()
check("platform is rekordbox", caps.platform == "rekordbox")
# The distinction that makes the UI honest: "cannot be written at all" is
# not the same as every per-feature flag happening to be false.
check("the library reports itself as NOT writable", caps.writable is False)
check("and says why, as a fact the UI can word",
caps.readonly_cause == "platform_incomplete", str(caps.readonly_cause))
check("per-feature flags still describe what Rekordbox CAN do",
caps.cues.memory_cues and caps.grid.flexible)
check("8 hot cue slots, labelled by letter",
caps.cues.hotcue_slots == 8 and caps.cues.slot_labels == "letter")
check("memory cues are supported", caps.cues.memory_cues)
@@ -247,6 +254,40 @@ with tempfile.TemporaryDirectory() as d:
check("every mutating command raises Unsupported", not refused, ", ".join(refused))
check("the adapter is never dirty while read-only", adapter.dirty is False)
print("== a cloud-synced library is refused permanently, not pending a milestone ==")
# The one failure mode version history cannot undo: a local edit the sync
# server did not issue could corrupt the user's OTHER machines. Detection is
# a server-issued `usn`, so forge one on a throwaway copy and check it flips.
synced = Path(d) / "synced.db"
shutil.copy2(work, synced)
import sqlcipher3.dbapi2 as sqlcipher
from pyrekordbox.db6.database import BLOB
from pyrekordbox.utils import deobfuscate
con = sqlcipher.connect(str(synced))
con.execute(f"PRAGMA key='{deobfuscate(BLOB)}'")
con.execute("UPDATE djmdContent SET usn = 42 WHERE ID = (SELECT ID FROM djmdContent LIMIT 1)")
con.commit()
con.execute("PRAGMA wal_checkpoint(TRUNCATE)")
con.close()
for ext in ("-wal", "-shm"):
stale = Path(str(synced) + ext)
if stale.exists():
stale.unlink() # a stale WAL beside a copied .db corrupts it
cloud = RekordboxAdapter(synced)
ccaps = cloud.capabilities()
check("a server-issued usn marks the library cloud-synced", cloud.cloud_synced)
check("the read-only cause distinguishes it from a missing feature",
ccaps.readonly_cause == "cloud_synced", str(ccaps.readonly_cause))
try:
cloud.set_track_metadata(cloud.tracks[0].id, {"title": "x"})
check("a cloud-synced library refuses edits", False, "no refusal")
except Unsupported as ex:
check("a cloud-synced library refuses edits", True)
check("and the refusal names the real reason, not the milestone",
"Cloud" in str(ex), str(ex))
print("== reads that must still work ==")
page = adapter.query_tracks(limit=5)
check("query_tracks paginates", len(page.items) <= 5 and page.total == len(adapter.tracks))
+2
View File
@@ -80,6 +80,8 @@ with tempfile.TemporaryDirectory() as d:
adapter = TraktorAdapter(work)
caps = adapter.capabilities()
check("platform reported", caps.platform == "traktor")
check("the library is writable, with no read-only cause",
caps.writable is True and caps.readonly_cause is None)
check("version read from the NML header", caps.version == "20", str(caps.version))
check("8 hotcue slots", caps.cues.hotcue_slots == 8)
check("no memory cues on Traktor", caps.cues.memory_cues is False)