Fixed issue with Traktor 4.5 collection round-trip

This commit is contained in:
patben8 committed 2026-10-16 15:53:52 +02:00
1 parent 1f2ca18e8a
commit 0aeb5019ad
4 files changed
+44 -2

No files matched your search

+6
View File
@@ -1220,6 +1220,12 @@ serialization path.** It enforces:
cue lines, in Traktor's shape (`HOTCUE="-1"`, `n.n.`), add + delete cue lines, in Traktor's shape (`HOTCUE="-1"`, `n.n.`), add + delete
round-trips byte for byte, new cues (hot ones too) are INSERTED by START, round-trips byte for byte, new cues (hot ones too) are INSERTED by START,
and a pad + memory cue at one START project once, as the pad. and a pad + memory cue at one START project once, as the pad.
And **`>` / quotes in attribute values** (Q): Traktor leaves `>` raw, and
an empty element holding one (4.5's default "Recently added" query
`$IMPORTDATE >= MONTHS_AGO(1)`, a comment, a file name) once came back
self-closed (`/>`, which Traktor never writes); a value containing
`name='x'` once came back with a bare `"` (malformed). Both were in the
fork's `format_traktor_layout`, fixed there (2026-10-16).
The guard that catches serialization regressions like the lxml reformatting bug. The guard that catches serialization regressions like the lxml reformatting bug.
- `test_phase3.py` — full create/add/reorder/rename/delete/save cycle stays - `test_phase3.py` — full create/add/reorder/rename/delete/save cycle stays
Traktor-valid, backup-first, COLLECTION byte-identical, original untouched; Traktor-valid, backup-first, COLLECTION byte-identical, original untouched;
+1 -1
View File
@@ -14,5 +14,5 @@ Pillow>=11 # a Rekordbox add writes the cover's artwork files
dulwich>=0.22 # version history, beside the library dulwich>=0.22 # version history, beside the library
platformdirs>=4.0 platformdirs>=4.0
# From GitHub, NOT PyPI — see requirements.txt for why. # From GitHub, NOT PyPI — see requirements.txt for why.
traktor-nml-utils @ git+https://github.com/MrPatben8/traktor-nml-utils.git@39a9c15f29d6b0ea2ce61cd7d548501eea38319d traktor-nml-utils @ git+https://github.com/MrPatben8/traktor-nml-utils.git@d7f472aaf5be53e53921de351e948233e9c1d1e8
pyrekordbox @ git+https://github.com/dylanljones/pyrekordbox.git@43137cb91f8297c768d2a8bdce5b27b2225f0a2d pyrekordbox @ git+https://github.com/dylanljones/pyrekordbox.git@43137cb91f8297c768d2a8bdce5b27b2225f0a2d
+1 -1
View File
@@ -24,7 +24,7 @@ scikit-learn>=1.5
# what it had: pyrekordbox renamed `devicelib_plus` to `onelibrary` upstream, # what it had: pyrekordbox renamed `devicelib_plus` to `onelibrary` upstream,
# every local test passed, and the released app could not export or read a # every local test passed, and the released app could not export or read a
# OneLibrary stick. Move a pin deliberately, with ./run_tests.sh. # OneLibrary stick. Move a pin deliberately, with ./run_tests.sh.
traktor-nml-utils @ git+https://github.com/MrPatben8/traktor-nml-utils.git@39a9c15f29d6b0ea2ce61cd7d548501eea38319d traktor-nml-utils @ git+https://github.com/MrPatben8/traktor-nml-utils.git@d7f472aaf5be53e53921de351e948233e9c1d1e8
# Rekordbox (master.db is SQLCipher-encrypted SQLite + per-track ANLZ analysis # Rekordbox (master.db is SQLCipher-encrypted SQLite + per-track ANLZ analysis
# files). Both ship prebuilt Python 3.14 wheels — no Rust/OpenSSL source build. # files). Both ship prebuilt Python 3.14 wheels — no Rust/OpenSSL source build.
# #
+36
View File
@@ -1305,5 +1305,41 @@ with tempfile.TemporaryDirectory() as d:
check("both cues stay in the file", check("both cues stay in the file",
sum(1 for c in entry.cue_v2 if c.grid is None and c.hotcue == -1) == 2) sum(1 for c in entry.cue_v2 if c.grid is None and c.hotcue == -1) == 2)
print("== Q. '>' and quotes in attribute values round-trip (Traktor leaves '>' raw) ==")
# The real collection's queries hold no '>', so Traktor-written values with one
# are injected into a copy: Traktor 4.5's default "Recently added" smartlist,
# a '<' query (Traktor escapes it), and '>' / name='x' in a comment and a file
# name. All four once came back self-closed ("<X .../>"), which Traktor never
# writes, and a quoting step rewrote name='x' into a bare '"' (malformed XML).
import re as _re # noqa: E402
with tempfile.TemporaryDirectory() as d:
work = Path(d) / "collection.nml"
data = REAL.read_bytes()
queries = list(_re.finditer(rb'QUERY="[^"]*"', data))
swaps = [
(queries[0].group(0), b'QUERY="$IMPORTDATE >= MONTHS_AGO(1)"'),
(queries[1].group(0), b'QUERY="$RATING &lt; 3"'),
(_re.search(rb' COMMENT="[^"]*"', data).group(0), b" COMMENT=\"Classic > Move key='8A'\""),
(_re.search(rb' FILE="[^"]*"', data).group(0), b' FILE="Break Down > Build Up.wav"'),
]
for old, new in swaps:
data = data.replace(old, new, 1)
work.write_bytes(data)
store = TraktorStore(work)
out = store._render()
check("no-op render is byte-identical", out == data, f"{diff_count(data, out)} lines differ")
check("nothing is self-closed ('/>' — Traktor never writes it)", b"/>" not in out)
entry = store._nml.collection.entry[0]
tid = f"{entry.location.volume}{entry.location.dir}{entry.location.file}"
store.set_track_metadata(tid, {"comment": "x > y key='8A' \"z\""})
store.save()
saved = work.read_bytes()
check("an edited comment with '>' keeps </INFO>",
b"COMMENT=\"x > y key='8A' &quot;z&quot;\"" in saved and b"/>" not in saved)
reread = TraktorStore(work)._nml.collection.entry[0].info.comment
check("…and reads back unchanged", reread == "x > y key='8A' \"z\"", repr(reread))
print("\nRESULT:", "FAILED" if failed else "ALL PASSED") print("\nRESULT:", "FAILED" if failed else "ALL PASSED")
sys.exit(1 if failed else 0) sys.exit(1 if failed else 0)