"""Writing a brand-new Traktor collection from nothing. Everywhere else in Konduktor the write target was parsed from a file Traktor wrote, and `test_save_fidelity.py` guards that nothing else in it moves. An export has no original, so the guarantee has to be different: **the result must be a collection Traktor would have written** — the right skeleton, a coherent playlist tree, and prep that survived the crossing intact. The property with the most riding on it is the LOCATION: Traktor stores a volume NAME plus a volume-relative path, never a host path, which is the whole reason a USB export is portable. If an export ever wrote absolute host paths it would work perfectly on the machine that made it and resolve to nothing at the gig. Runs against the 8,485-entry fixture collection, so the tracks have real prep — flexible grids, hot cues on specific pads — rather than anything invented here. """ import json import os import re import tempfile from pathlib import Path os.environ["KONDUKTOR_DATA_DIR"] = tempfile.mkdtemp() from konduktor.adapters.traktor.driver import TraktorDriver # noqa: E402 from konduktor.adapters.traktor.export import SKELETON # noqa: E402 from konduktor.core import export as core_export # noqa: E402 from konduktor.core.export import ExportPayload, ExportPlaylist, ExportTrack # noqa: E402 failed = False def check(label, cond, detail=""): global failed print(f" [{'PASS' if cond else 'FAIL'}] {label}" + (f" — {detail}" if detail and not cond else "")) if not cond: failed = True FIXTURE = Path(__file__).resolve().parents[1] / "collection.nml" src = TraktorDriver().open(FIXTURE) exporter = core_export.for_platform("traktor") print("== the target declares itself without a library to read ==") check("traktor is a target", exporter is not None) # All three platforms Konduktor can OPEN can now also be written from nothing. # The two registries stay separate anyway: they answer different questions, and # a future read-only platform would be in one and not the other. check("so are rekordbox and onelibrary", core_export.for_platform("rekordbox") is not None and core_export.for_platform("onelibrary") is not None) check("a platform with no exporter is not a target", core_export.for_platform("serato") is None) caps = exporter.capabilities() check("static capabilities answer with no path", caps.platform == "traktor" and caps.writable) check("and describe the FORMAT, not an instance", caps.cues.hotcue_slots == 8) # ---- build a payload out of real tracks -------------------------------------- # One with a flexible (multi-marker) grid, one with several hot cues: the two # things most likely to be quietly lost. flexible = next(t for t in src.tracks if (t.grid_marker_count or 0) > 1) cued = next(t for t in src.tracks if (t.cue_count or 0) >= 3 and t.id != flexible.id) plain = next(t for t in src.tracks if t.id not in (flexible.id, cued.id)) chosen = [flexible, cued, plain] dest = Path(tempfile.mkdtemp()) / "GIG" dest.mkdir(parents=True) items = [] for track in chosen: audio = dest / "Music" / "Library" / Path(track.filepath).name audio.parent.mkdir(parents=True, exist_ok=True) audio.write_bytes(b"\0" * 64) items.append(ExportTrack(track=track, destination=audio, cues=src.track_cues(track.id))) payload = ExportPayload( name="GIG", tracks=items, playlists=[ ExportPlaylist(name="Peak Time", track_ids=[flexible.id, cued.id], folders=["House"]), ExportPlaylist(name="Warmup", track_ids=[cued.id], folders=["House", "Slow"]), ], ) result = exporter.write(payload, dest) written = result.library check("the exporter reports what it wrote", result.all_paths == [written]) text = written.read_text(encoding="utf-8") print("== the skeleton is what Traktor writes ==") check("named collection.nml", written.name == "collection.nml") check("the XML declaration is there", text.startswith('' in text) check("a HEAD element", "' in text) # Playlists cannot sit at the top level; they hang off a $ROOT FOLDER node. check("PLAYLISTS wraps a $ROOT folder", '' in text) check("INDEXING is present", '' in text) check("the ENTRIES header matches the entry count", f'' in text, re.search(r'