mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added OneLibrary testing fixtures
This commit is contained in:
1 parent
7960a5a68f
commit
bdc62f2c1b
35 files changed
+792
-7
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,32 @@
|
||||
# Goober: a rekordbox-written stick, before and after rekordbox edited it
|
||||
|
||||
The stick Ben keeps for measuring the Pioneer formats, as rekordbox 7 left it:
|
||||
11 tracks, 2 playlists, **both** libraries (`exportLibrary.db` and the legacy
|
||||
`export.pdb` + `exportExt.pdb`). `test_onelibrary_anlz.py`,
|
||||
`test_onelibrary_pdb.py` and `test_onelibrary_tracks.py` run against copies of it.
|
||||
|
||||
## What is here
|
||||
|
||||
- `PIONEER/rekordbox/` holds the three databases, **untouched**: bytes rekordbox
|
||||
wrote (snapshot `s0`, 2026-10-01).
|
||||
- `PIONEER/USBANLZ/` holds every track's `.DAT` and `.EXT`, trimmed by dropping
|
||||
whole tags: only `PPTH`, `PQTZ`, `PCOB`, `PCO2` and `PQT2` are kept, byte for
|
||||
byte. The waveforms are gone, and so are the `.2EX` files.
|
||||
- `after/` holds the same tags after **rekordbox 7 itself** edited the stick
|
||||
(snapshot `s1`, one edit per track):
|
||||
- `black-bloc-recoloured.EXT`: pad C recoloured to `0x2D` `#FF0045`.
|
||||
- `wtf-87bpm.DAT` / `.EXT`: "Result – WTF" changed from 174 to 87 BPM.
|
||||
- `demo2-pad-e-added.EXT`: a hot cue added on pad E of "Demo Track 2".
|
||||
|
||||
There is no audio. The adapter resolves paths and never needs the files, so the
|
||||
time base falls back to rekordbox's MP3 default, the same offset for reading and
|
||||
writing.
|
||||
|
||||
## Why
|
||||
|
||||
Konduktor's edits are pinned against what rekordbox wrote for the SAME edit, not
|
||||
against Konduktor's own reader. A recolour and a grid edit must reproduce
|
||||
rekordbox's bytes exactly (colour bytes, the blanked `PQT2`, loop beats cleared).
|
||||
The pdb tests prove that an in-place edit of a rekordbox-written `export.pdb`
|
||||
leaves everything else as rekordbox wrote it. The full diff of the measurement is
|
||||
in `.claude/discussions/discuss-onelibrary-editing-2026-10-01.md`.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
source .venv/bin/activate
|
||||
|
||||
fail=0
|
||||
for t in test_layering.py test_save_fidelity.py test_timebase.py test_stem_file.py test_stem_swap.py test_engine_manager.py test_stems_batch.py test_stem_playback.py test_traktor_adapter.py test_rekordbox_adapter.py test_rekordbox_fidelity.py test_onelibrary_adapter.py test_onelibrary_fidelity.py test_import.py test_grid_detect.py test_auto_hotcues.py test_grid_batch.py test_bulk_remove.py test_folders.py test_picker.py test_relocate.py test_library_id.py test_exports.py test_export.py test_export_pioneer.py test_device_export.py test_phase3.py test_history.py test_discard.py; do
|
||||
for t in test_layering.py test_save_fidelity.py test_timebase.py test_stem_file.py test_stem_swap.py test_engine_manager.py test_stems_batch.py test_stem_playback.py test_traktor_adapter.py test_rekordbox_adapter.py test_rekordbox_fidelity.py test_onelibrary_adapter.py test_onelibrary_fidelity.py test_onelibrary_anlz.py test_onelibrary_pdb.py test_onelibrary_tracks.py test_import.py test_grid_detect.py test_auto_hotcues.py test_grid_batch.py test_bulk_remove.py test_folders.py test_picker.py test_relocate.py test_library_id.py test_exports.py test_export.py test_export_pioneer.py test_device_export.py test_phase3.py test_history.py test_discard.py; do
|
||||
echo "──────────────────────────────────────────"
|
||||
echo "▶ $t"
|
||||
echo "──────────────────────────────────────────"
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
"""Cue and beatgrid edits on a OneLibrary stick: the ANLZ files.
|
||||
|
||||
Two kinds of check, on temp copies of two real rekordbox-written drives:
|
||||
|
||||
* **against rekordbox's own edit** (`fixtures/onelibrary-goober/after/`): the
|
||||
same edit made in rekordbox 7 and in Konduktor must produce the same bytes —
|
||||
a recolour changes only the colour bytes, a grid edit blanks `PQT2` and
|
||||
clears the loop beat lengths exactly as rekordbox did;
|
||||
* **fidelity**: nothing reaches the drive before Save, only the tags an edit
|
||||
touches change (in place, order kept), a pad keeps its colour and name
|
||||
through a move, memory cues stay uneditable, and an `.EXT` with no `PCO2`
|
||||
keeps every pad when the first edit creates one.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
APPDATA = Path(tempfile.mkdtemp(prefix="konduktor-olanlz-appdata-"))
|
||||
os.environ["KONDUKTOR_DATA_DIR"] = str(APPDATA)
|
||||
|
||||
from konduktor.adapters.onelibrary.adapter import OneLibraryAdapter # noqa: E402
|
||||
from konduktor.adapters.rekordbox import anlz_file as A # noqa: E402
|
||||
from konduktor.adapters.rekordbox import anlz_writer as W # noqa: E402
|
||||
from konduktor.core.adapter import InvalidCommand, NotFound, Unsupported # noqa: E402
|
||||
from konduktor.core.model import CuePoint, GridMarker # noqa: E402
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
GOOBER = HERE / "fixtures" / "onelibrary-goober"
|
||||
DEMO = HERE / "fixtures" / "onelibrary"
|
||||
TRACK_1 = "/Contents/Loopmasters/UnknownAlbum/Demo Track 1.mp3"
|
||||
|
||||
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
|
||||
|
||||
|
||||
def _raises(fn, exc) -> bool:
|
||||
try:
|
||||
fn()
|
||||
except exc:
|
||||
return True
|
||||
except Exception: # noqa: BLE001
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def copy_of(fixture: Path, name: str) -> Path:
|
||||
root = Path(tempfile.mkdtemp(prefix="konduktor-olanlz-")) / name
|
||||
shutil.copytree(fixture, root, ignore=shutil.ignore_patterns("after", "rekordbox-edited", "README.md"))
|
||||
return root
|
||||
|
||||
|
||||
def tag(path: Path, kind: str, list_kind: int | None = None) -> bytes | None:
|
||||
f = A.parse_file(path)
|
||||
return next((t.data for t in f.tags
|
||||
if t.type == kind and (list_kind is None or t.list_kind == list_kind)), None)
|
||||
|
||||
|
||||
def tags_by_key(source) -> dict:
|
||||
"""Tags keyed by (type, list kind), from a path or from bytes."""
|
||||
out = {}
|
||||
parsed = A.parse(source) if isinstance(source, bytes) else A.parse_file(source)
|
||||
for t in parsed.tags:
|
||||
key = (t.type, t.list_kind)
|
||||
out[key if key not in out else (*key, len(out))] = t.data
|
||||
return out
|
||||
|
||||
|
||||
def dat_of(adapter, track_id: str) -> Path:
|
||||
return adapter._store.layout.resolve(adapter._store.content(track_id).analysisDataFilePath)
|
||||
|
||||
|
||||
# ---- against rekordbox's own edits -----------------------------------------------
|
||||
print("== the same edit as rekordbox 7 made, the same bytes ==")
|
||||
drive = copy_of(GOOBER, "Goober")
|
||||
a = OneLibraryAdapter(drive)
|
||||
by = lambda prefix: next(t for t in a.tracks if t.title.startswith(prefix)) # noqa: E731
|
||||
black_bloc, wtf, demo2 = by("Justin Hawkes"), by("Result"), by("Demo Track 2")
|
||||
|
||||
before_dat = dat_of(a, black_bloc.id).read_bytes()
|
||||
a.set_cue_color(black_bloc.id, 2, "#FF0045")
|
||||
a.set_grid_marker_bpm(wtf.id, 0, 87.0)
|
||||
a.set_cue(demo2.id, slot=4, start_sec=47.5, cue_type="cue")
|
||||
a.save()
|
||||
|
||||
ext = dat_of(a, black_bloc.id).with_suffix(".EXT")
|
||||
check("a recolour: the PCO2 hot list is rekordbox's, byte for byte",
|
||||
tag(ext, "PCO2", A.LIST_HOT) == tag(GOOBER / "after" / "black-bloc-recoloured.EXT", "PCO2", A.LIST_HOT))
|
||||
check("and the .DAT, which holds no colour, is untouched", dat_of(a, black_bloc.id).read_bytes() == before_dat)
|
||||
|
||||
ext = dat_of(a, wtf.id).with_suffix(".EXT")
|
||||
check("a grid edit blanks PQT2 exactly as rekordbox does",
|
||||
tag(ext, "PQT2") == tag(GOOBER / "after" / "wtf-87bpm.EXT", "PQT2"))
|
||||
check("and clears the memory loop's beat length exactly as rekordbox does",
|
||||
tag(ext, "PCO2", A.LIST_MEMORY) == tag(GOOBER / "after" / "wtf-87bpm.EXT", "PCO2", A.LIST_MEMORY))
|
||||
ours = [e.time for t in A.parse_file(dat_of(a, wtf.id)).tags if t.type == "PQTZ" for e in t.entries]
|
||||
theirs = [e.time for t in A.parse_file(GOOBER / "after" / "wtf-87bpm.DAT").tags if t.type == "PQTZ"
|
||||
for e in t.entries]
|
||||
check("PQTZ: the same number of beats as rekordbox's", len(ours) == len(theirs), f"{len(ours)} vs {len(theirs)}")
|
||||
# rekordbox re-derives its anchor and works at its own tempo precision (its first
|
||||
# beat moved 83 -> 89 ms, steps alternate 689/690); Konduktor keeps the marker.
|
||||
check("each within 10 ms of rekordbox's (its anchor moves; ours stays put)",
|
||||
max(abs(x - y) for x, y in zip(ours, theirs)) <= 10)
|
||||
check("from the marker where it was, 60/87 s apart",
|
||||
ours[0] == 83 and all(abs(ours[k] - 83 - k * 60000 / 87) <= 0.5 for k in range(len(ours))))
|
||||
check("bpmx100 follows the first marker, as rekordbox's did", a._store.content(wtf.id).bpmx100 == 8700)
|
||||
|
||||
pads = {c.slot: c for c in a.track_cues(demo2.id).cues if c.role == "hotcue"}
|
||||
theirs = {e.hot_cue - 1: e for t in A.parse_file(GOOBER / "after" / "demo2-pad-e-added.EXT").tags
|
||||
if t.type == "PCO2" and t.list_kind == A.LIST_HOT for e in t.entries}
|
||||
check("a new pad lands where rekordbox's did, the other pads as they were",
|
||||
sorted(pads) == sorted(theirs) and all(abs(pads[s].start * 1000 - theirs[s].time) < 30
|
||||
or s == 4 for s in pads), str(sorted(pads)))
|
||||
a.close()
|
||||
|
||||
# ---- fidelity on the demo drive --------------------------------------------------
|
||||
print("== nothing reaches the drive before Save; only touched tags change ==")
|
||||
drive = copy_of(DEMO, "Dingus")
|
||||
a = OneLibraryAdapter(drive)
|
||||
dat = dat_of(a, TRACK_1)
|
||||
ext = dat.with_suffix(".EXT")
|
||||
original = {p: p.read_bytes() for p in (dat, ext)}
|
||||
cues = {c.slot: c for c in a.track_cues(TRACK_1).cues if c.role == "hotcue"}
|
||||
check("hot cues are editable, memory cues are not",
|
||||
all(c.editable == (c.role == "hotcue") for c in a.track_cues(TRACK_1).cues))
|
||||
|
||||
a.set_cue(TRACK_1, slot=5, start_sec=10.0, cue_type="cue", name="Drop")
|
||||
a.set_cue_color(TRACK_1, 5, "#FF0045")
|
||||
a.set_cue(TRACK_1, slot=5, start_sec=11.0, cue_type="cue")
|
||||
pad = next(c for c in a.track_cues(TRACK_1).cues if c.slot == 5)
|
||||
check("a moved pad keeps its colour and its name",
|
||||
(round(pad.start, 3), pad.color, pad.name) == (11.0, "#FF0045", "Drop"), str(pad))
|
||||
check("the edit shows at once", a.dirty and round(pad.start, 3) == 11.0)
|
||||
check("but the drive's files are untouched", all(p.read_bytes() == b for p, b in original.items()))
|
||||
|
||||
a.set_cue_type(TRACK_1, 0, "cue") # pad A was a loop
|
||||
check("a loop retyped to a cue loses its length",
|
||||
next(c for c in a.track_cues(TRACK_1).cues if c.slot == 0).length == 0.0)
|
||||
check("a cue cannot become a loop without a length",
|
||||
_raises(lambda: a.set_cue_type(TRACK_1, 5, "loop"), InvalidCommand))
|
||||
a.delete_cue(TRACK_1, 3)
|
||||
check("a pad can be deleted (pad D, which lives in the .EXT's PCOB)",
|
||||
3 not in {c.slot for c in a.track_cues(TRACK_1).cues if c.role == "hotcue"})
|
||||
check("deleting an empty pad is NotFound", _raises(lambda: a.delete_cue(TRACK_1, 7), NotFound))
|
||||
check("a pad beyond the bank is refused",
|
||||
_raises(lambda: a.set_cue(TRACK_1, slot=8, start_sec=1.0, cue_type="cue"), InvalidCommand))
|
||||
check("memory cues are not editable",
|
||||
_raises(lambda: a.set_cue(TRACK_1, slot=0, start_sec=1.0, cue_type="cue", role="memory"), Unsupported))
|
||||
check("a colour must be one of rekordbox's swatches",
|
||||
_raises(lambda: a.set_cue_color(TRACK_1, 5, "#123456"), InvalidCommand))
|
||||
a.place_cues(TRACK_1, [CuePoint(slot=1, start=30.0, length=0.0, type="cue"),
|
||||
CuePoint(slot=6, start=31.0, length=0.0, type="cue")])
|
||||
starts = {c.slot: round(c.start, 2) for c in a.track_cues(TRACK_1).cues if c.role == "hotcue"}
|
||||
check("place_cues fills empty pads and leaves occupied ones", starts.get(6) == 31.0 and starts.get(1) != 30.0)
|
||||
|
||||
markers = a.track_cues(TRACK_1).grid_markers
|
||||
# A per-beat grid has no markers: one at the governing tempo, on its beats, is
|
||||
# indistinguishable from none and collapses on read (as on the Rekordbox side).
|
||||
a.add_grid_marker(TRACK_1, markers[-1].start + 10 * 60 / markers[-1].bpm)
|
||||
check("a marker at the governing tempo collapses into it",
|
||||
len(a.track_cues(TRACK_1).grid_markers) == len(markers))
|
||||
a.add_grid_marker(TRACK_1, 100.0, 100.0)
|
||||
check("a marker with a new tempo is a new segment",
|
||||
[m.bpm for m in a.track_cues(TRACK_1).grid_markers] == [128.0, 90.0, 100.0])
|
||||
a.move_grid_marker(TRACK_1, 1, 200.0)
|
||||
moved = a.track_cues(TRACK_1).grid_markers
|
||||
check("a moved marker is clamped before its neighbour", moved[1].start < moved[2].start)
|
||||
a.delete_grid_marker(TRACK_1, 2)
|
||||
check("and deleted", len(a.track_cues(TRACK_1).grid_markers) == len(markers))
|
||||
|
||||
a.save()
|
||||
after = {p: tags_by_key(p) for p in (dat, ext)}
|
||||
before = {p: tags_by_key(b) for p, b in original.items()}
|
||||
changed = {p.suffix: sorted(f"{k[0]}/{k[1]}" for k in before[p] if before[p][k] != after[p].get(k))
|
||||
for p in original}
|
||||
check("the .DAT: only the pad 1-3 list and the grid changed",
|
||||
changed[".DAT"] == ["PCOB/1", "PQTZ/None"], str(changed[".DAT"]))
|
||||
check("the .EXT: only its cue lists changed (memory: the loop beats a grid edit clears)",
|
||||
set(changed[".EXT"]) <= {"PCOB/1", "PCO2/1", "PCO2/0"}, str(changed[".EXT"]))
|
||||
check("tag order is kept in both files",
|
||||
all([t.type for t in A.parse(original[p]).tags] == [t.type for t in A.parse_file(p).tags]
|
||||
for p in original))
|
||||
check("the .DAT's memory list (no beat field there) is byte-identical",
|
||||
tag(dat, "PCOB", A.LIST_MEMORY) == before[dat][("PCOB", A.LIST_MEMORY)])
|
||||
backups = sorted((APPDATA / "onelibrary" / "backups" / "Dingus").iterdir())
|
||||
check("both analysis files were backed up first",
|
||||
all((backups[-1] / p.relative_to(drive)).read_bytes() == b for p, b in original.items()))
|
||||
a.close()
|
||||
b = OneLibraryAdapter(drive)
|
||||
check("everything reads back after a reopen",
|
||||
{c.slot: round(c.start, 2) for c in b.track_cues(TRACK_1).cues if c.role == "hotcue"} == starts
|
||||
and next(c for c in b.track_cues(TRACK_1).cues if c.slot == 5).name == "Drop")
|
||||
b.close()
|
||||
|
||||
print("== another app wrote an analysis file since Konduktor read it ==")
|
||||
drive = copy_of(DEMO, "Dingus")
|
||||
a = OneLibraryAdapter(drive)
|
||||
a.set_cue(TRACK_1, slot=6, start_sec=5.0, cue_type="cue")
|
||||
time.sleep(0.01)
|
||||
os.utime(dat_of(a, TRACK_1).with_suffix(".EXT"))
|
||||
check("Save refuses rather than undo it", _raises(a.save, InvalidCommand) and a.dirty)
|
||||
a.close()
|
||||
|
||||
print("== an .EXT with no PCO2 keeps every pad on the first edit ==")
|
||||
drive = copy_of(DEMO, "Dingus")
|
||||
probe = OneLibraryAdapter(drive)
|
||||
ext = dat_of(probe, TRACK_1).with_suffix(".EXT")
|
||||
want = sorted(c.slot for c in probe.track_cues(TRACK_1).cues if c.role == "hotcue")
|
||||
memory = sum(c.role == "memory" for c in probe.track_cues(TRACK_1).cues)
|
||||
probe.close()
|
||||
f = A.parse_file(ext)
|
||||
f.tags = [t for t in f.tags if t.type != "PCO2"]
|
||||
ext.write_bytes(f.to_bytes())
|
||||
a = OneLibraryAdapter(drive)
|
||||
check("read from PCOB alone, the pads are all there", sorted(
|
||||
c.slot for c in a.track_cues(TRACK_1).cues if c.role == "hotcue") == want)
|
||||
a.set_cue(TRACK_1, slot=6, start_sec=5.0, cue_type="cue")
|
||||
got = a.track_cues(TRACK_1).cues
|
||||
check("after the edit creates PCO2, every old pad AND the new one read",
|
||||
sorted(c.slot for c in got if c.role == "hotcue") == sorted(want + [6]), str([c.slot for c in got]))
|
||||
check("and the memory cue survives", sum(c.role == "memory" for c in got) == memory)
|
||||
a.close()
|
||||
|
||||
print("== a track without analysis files ==")
|
||||
drive = copy_of(DEMO, "Dingus")
|
||||
probe = OneLibraryAdapter(drive)
|
||||
dat = dat_of(probe, TRACK_1)
|
||||
probe.close()
|
||||
for p in (dat, dat.with_suffix(".EXT")):
|
||||
p.unlink()
|
||||
a = OneLibraryAdapter(drive)
|
||||
check("refuses a cue edit (it has nowhere to store one)",
|
||||
_raises(lambda: a.set_cue(TRACK_1, slot=0, start_sec=1.0, cue_type="cue"), InvalidCommand))
|
||||
check("and a grid edit", _raises(lambda: a.replace_grid(TRACK_1, [GridMarker(start=0, bpm=120)]),
|
||||
InvalidCommand))
|
||||
a.close()
|
||||
|
||||
print("== the entry helpers ==")
|
||||
e = W.pcp2_entry(hot_cue=2, kind=1, time_ms=5, loop_ms=None, rgb=(1, 2, 3), beats=None, code=9,
|
||||
comment="A name longer than forty bytes in UTF-16")
|
||||
d = A.decode_entry(e)
|
||||
check("a long name grows the entry past 88 bytes and round-trips",
|
||||
len(e) > 88 and d.comment == "A name longer than forty bytes in UTF-16" and d.color_code == 9)
|
||||
check("a 44-byte compact entry has no colour bytes to patch",
|
||||
A.entry_with_colour(A.raw_entries(A.Tag("PCO2", tag(HERE / "fixtures" / "onelibrary" / "rekordbox-edited"
|
||||
/ "nemean.EXT", "PCO2", A.LIST_MEMORY)))[-1],
|
||||
9, (1, 2, 3)) is None)
|
||||
|
||||
print()
|
||||
print("RESULT:", "FAILED" if failed else "ALL PASSED")
|
||||
sys.exit(1 if failed else 0)
|
||||
@@ -0,0 +1,152 @@
|
||||
"""The legacy Device Library (`export.pdb`) kept in step with a stick's OneLibrary.
|
||||
|
||||
On a temp copy of Goober (`fixtures/onelibrary-goober/`), whose three databases
|
||||
are rekordbox's own bytes. Pins:
|
||||
|
||||
* reading: every rekordbox track row decodes, and re-encodes to the same
|
||||
meaningful bytes (rekordbox leaves stale bytes in alignment padding and
|
||||
between rows — `track_extent`);
|
||||
* ids are mirrored: rekordbox exported both libraries from the same ids, so a
|
||||
no-op rebuild changes NOTHING, and a no-op save leaves the file byte-identical;
|
||||
* an edit reaches the pdb (title, rating, artist, a new playlist, a reorder —
|
||||
the last two are what rekordbox's own edits failed to carry over), every table
|
||||
the edit does not touch stays byte-identical, and `exportExt.pdb` is never
|
||||
written;
|
||||
* another app's write to `export.pdb` since open is refused, not undone.
|
||||
|
||||
Verified in rekordbox 7 on the real Goober (2026-10-01): both library views
|
||||
matched after exactly these edits.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
os.environ["KONDUKTOR_DATA_DIR"] = tempfile.mkdtemp(prefix="konduktor-olpdb-appdata-")
|
||||
|
||||
from konduktor.adapters.onelibrary import device_library # noqa: E402
|
||||
from konduktor.adapters.onelibrary.adapter import OneLibraryAdapter # noqa: E402
|
||||
from konduktor.adapters.rekordbox import pdb # noqa: E402
|
||||
from konduktor.core.adapter import InvalidCommand # noqa: E402
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
GOOBER = HERE / "fixtures" / "onelibrary-goober"
|
||||
DEMO = HERE / "fixtures" / "onelibrary"
|
||||
|
||||
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
|
||||
|
||||
|
||||
def copy_of(fixture: Path, name: str) -> Path:
|
||||
root = Path(tempfile.mkdtemp(prefix="konduktor-olpdb-")) / name
|
||||
shutil.copytree(fixture, root, ignore=shutil.ignore_patterns("after", "rekordbox-edited", "README.md"))
|
||||
return root
|
||||
|
||||
|
||||
PDB = GOOBER / "PIONEER" / "rekordbox" / "export.pdb"
|
||||
raw = PDB.read_bytes()
|
||||
|
||||
print("== reading rekordbox's rows ==")
|
||||
tracks = pdb.table_rows(raw, pdb.TRACKS)
|
||||
check("every track row is found (as many as the reader sees)", len(tracks) == len(pdb.read(raw).tracks) == 11)
|
||||
same = [pdb.track_row(*pdb.track_fields(r)) for r in tracks]
|
||||
check("each re-encodes to the same bytes up to its 4-byte alignment padding",
|
||||
all(a[:len(a) - 3] == b[:len(a) - 3] and len(a) == len(b) for a, b in zip(tracks, same)))
|
||||
check("a row ends at its last string, not at the next row (stale heap tails)",
|
||||
all(pdb.track_extent(r) == len(r) for r in tracks))
|
||||
check("artists, keys, artwork and the playlist tree all read",
|
||||
[len(pdb.table_rows(raw, t)) for t in (pdb.ARTISTS, pdb.KEYS, pdb.ARTWORK, pdb.PLAYLIST_TREE)]
|
||||
== [5, 4, 3, 2])
|
||||
|
||||
print("== ids are mirrored: nothing to do on an unedited stick ==")
|
||||
drive = copy_of(GOOBER, "Goober")
|
||||
a = OneLibraryAdapter(drive)
|
||||
rebuilt = device_library.rebuild(raw, a._store._require_db().session)
|
||||
check("a rebuild of an unedited stick changes nothing", rebuilt is None)
|
||||
a.set_track_metadata(a.tracks[0].id, {"title": a.tracks[0].title}) # dirty, but a no-op
|
||||
a.save()
|
||||
check("a save that changes nothing in it leaves export.pdb byte-identical",
|
||||
(drive / "PIONEER" / "rekordbox" / "export.pdb").read_bytes() == raw)
|
||||
a.close()
|
||||
|
||||
print("== an edit reaches the Device Library, and only the edit ==")
|
||||
drive = copy_of(GOOBER, "Goober")
|
||||
P = drive / "PIONEER" / "rekordbox"
|
||||
ext_before = (P / "exportExt.pdb").read_bytes()
|
||||
a = OneLibraryAdapter(drive)
|
||||
by = lambda prefix: next(t for t in a.tracks if t.title.startswith(prefix)) # noqa: E731
|
||||
tian, bensley, alkyn = by("Tian"), by("Bensley"), by("Alkyn")
|
||||
a.set_track_metadata(tian.id, {"title": tian.title + " X"})
|
||||
a.set_track_metadata(bensley.id, {"rating": 3})
|
||||
a.set_track_metadata(alkyn.id, {"artist": "Alkyn"})
|
||||
demos = next(n for n in a.playlist_tree() if n.name == "demos")
|
||||
order = a.playlist_entries(demos.id)
|
||||
a.set_playlist_entries(demos.id, order[::-1])
|
||||
probe = a.create_playlist("Probe")
|
||||
a.set_playlist_entries(probe, [alkyn.id])
|
||||
a.save()
|
||||
after = (P / "export.pdb").read_bytes()
|
||||
A, B = pdb.read(raw), pdb.read(after)
|
||||
old = {t["id"]: t for t in A.tracks}
|
||||
new = {t["id"]: t for t in B.tracks}
|
||||
diffs = {i: {k for k in old[i] if old[i][k] != new[i][k] and k != "index_shift"} for i in old}
|
||||
check("only the edited fields of the edited tracks changed",
|
||||
{i: d for i, d in diffs.items() if d} == {6: {"title"}, 7: {"rating"}, 8: {"artist_id"}},
|
||||
str({i: d for i, d in diffs.items() if d}))
|
||||
check("the new artist is mirrored under OneLibrary's own id",
|
||||
B.artists.get(new[8]["artist_id"]) == "Alkyn" and new[8]["artist_id"] == 6)
|
||||
tree = sorted((p["name"], p["sort"]) for p in B.playlists)
|
||||
check("the new playlist reached it, on top (rekordbox's own edit did not carry it over)",
|
||||
tree == [("Para Ben", 1), ("Probe", 0), ("demos", 2)], str(tree))
|
||||
demos_entries = [t for _i, t, p in sorted(B.entries) if p == int(demos.id)]
|
||||
check("and so did the reorder", [new[t]["file_path"] for t in demos_entries] == order[::-1])
|
||||
for table, name in ((pdb.COLORS, "colours"), (pdb.KEYS, "keys"), (pdb.ARTWORK, "artwork"),
|
||||
(pdb.GENRES, "genres"), (pdb.LABELS, "labels"), (pdb.ALBUMS, "albums"),
|
||||
(pdb.HISTORY, "history"), (16, "browse columns"), (17, "menus")):
|
||||
check(f"untouched table ({name}) is byte-identical",
|
||||
pdb.table_rows(raw, table) == pdb.table_rows(after, table))
|
||||
check("an unchanged track row keeps rekordbox's own bytes (stale padding and all)",
|
||||
[r for r in pdb.table_rows(after, pdb.TRACKS) if pdb.row_id(pdb.TRACKS, r) == 1]
|
||||
== [r for r in tracks if pdb.row_id(pdb.TRACKS, r) == 1])
|
||||
check("the file did not grow", len(after) == len(raw))
|
||||
check("exportExt.pdb is never written", (P / "exportExt.pdb").read_bytes() == ext_before)
|
||||
check("the previous export.pdb was backed up",
|
||||
any(p.read_bytes() == raw for p in
|
||||
(Path(os.environ["KONDUKTOR_DATA_DIR"]) / "onelibrary" / "backups").rglob("export.pdb")))
|
||||
a.close()
|
||||
|
||||
print("== another app wrote export.pdb since open ==")
|
||||
drive = copy_of(GOOBER, "Goober")
|
||||
a = OneLibraryAdapter(drive)
|
||||
a.set_track_metadata(a.tracks[0].id, {"rating": 5})
|
||||
time.sleep(0.01)
|
||||
os.utime(drive / "PIONEER" / "rekordbox" / "export.pdb")
|
||||
try:
|
||||
a.save()
|
||||
refused = False
|
||||
except InvalidCommand:
|
||||
refused = True
|
||||
check("Save refuses", refused and a.dirty)
|
||||
a.close()
|
||||
|
||||
print("== a stick with no Device Library ==")
|
||||
drive = copy_of(DEMO, "Dingus")
|
||||
a = OneLibraryAdapter(drive)
|
||||
a.set_track_metadata(a.tracks[0].id, {"rating": 2})
|
||||
a.save()
|
||||
check("saving does not create one", not (drive / "PIONEER" / "rekordbox" / "export.pdb").exists())
|
||||
a.close()
|
||||
|
||||
print()
|
||||
print("RESULT:", "FAILED" if failed else "ALL PASSED")
|
||||
sys.exit(1 if failed else 0)
|
||||
@@ -0,0 +1,312 @@
|
||||
"""Adding tracks to a OneLibrary stick and removing them (decisions 3, 6 and 7).
|
||||
|
||||
On temp copies of Goober (`fixtures/onelibrary-goober/`, with its Device Library)
|
||||
and generated MP3s, through `importer.run` — the path every add route takes:
|
||||
|
||||
* placement: the LIBRARY decides — a file already on the stick is used in
|
||||
place; anything else goes to `Contents/<Artist>/<Album>/` as rekordbox lays a
|
||||
stick out (`UnknownArtist`/`UnknownAlbum`, names cut to 48 characters),
|
||||
through `.konduktor-incoming/`;
|
||||
* an added track arrives ready to prep: analysis files (grid, cues, memory
|
||||
cues), artwork, a row shaped like rekordbox's, the track count, and its row
|
||||
in the Device Library;
|
||||
* nothing is left behind: a cancel mid-copy, a Discard, a crash (cleared on the
|
||||
next EDITABLE open only);
|
||||
* removal: every row naming the track goes (playlists renumbered), and its
|
||||
audio, analysis files and unshared artwork are deleted AFTER the save that
|
||||
stopped naming them — never before.
|
||||
"""
|
||||
import hashlib
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
os.environ["KONDUKTOR_DATA_DIR"] = tempfile.mkdtemp(prefix="konduktor-oltracks-appdata-")
|
||||
|
||||
from stem_test_support import make_mp3 # noqa: E402
|
||||
from konduktor import importer # noqa: E402
|
||||
from konduktor.adapters.onelibrary.adapter import OneLibraryAdapter # noqa: E402
|
||||
from konduktor.adapters.rekordbox import pdb # noqa: E402
|
||||
from konduktor.core.adapter import NewTrack # noqa: E402
|
||||
from konduktor.core.model import CuePoint, GridMarker, Track, TrackCues # noqa: E402
|
||||
from konduktor.jobs import Job, JobCancelled, JobHandle # noqa: E402
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
GOOBER = HERE / "fixtures" / "onelibrary-goober"
|
||||
|
||||
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
|
||||
|
||||
|
||||
def copy_of(name: str = "Goober") -> Path:
|
||||
root = Path(tempfile.mkdtemp(prefix="konduktor-oltracks-")) / name
|
||||
shutil.copytree(GOOBER, root, ignore=shutil.ignore_patterns("after", "README.md"))
|
||||
return root
|
||||
|
||||
|
||||
def fingerprint(root: Path) -> str:
|
||||
h = hashlib.sha1()
|
||||
for p in sorted(root.rglob("*")):
|
||||
if p.is_file():
|
||||
h.update(str(p.relative_to(root)).encode() + p.read_bytes())
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def rows(root: Path, sql: str):
|
||||
import sqlcipher3.dbapi2 as sqlcipher
|
||||
from pyrekordbox.devicelib_plus.database import BLOB
|
||||
from pyrekordbox.utils import deobfuscate
|
||||
|
||||
con = sqlcipher.connect(str(root / "PIONEER" / "rekordbox" / "exportLibrary.db"))
|
||||
con.execute(f"PRAGMA key='{deobfuscate(BLOB)}'")
|
||||
con.row_factory = lambda cur, row: dict(zip([d[0] for d in cur.description], row))
|
||||
try:
|
||||
return con.execute(sql).fetchall()
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
|
||||
def jpeg() -> bytes:
|
||||
from PIL import Image
|
||||
|
||||
buf = io.BytesIO()
|
||||
Image.new("RGB", (300, 200), (200, 40, 90)).save(buf, "JPEG")
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
SRC = Path(tempfile.mkdtemp(prefix="konduktor-oltracks-src-"))
|
||||
ONE = make_mp3(SRC / "Kick One.mp3", seconds=20)
|
||||
TWO = make_mp3(SRC / "Kick Two.mp3", seconds=20, seed=5)
|
||||
COVER = jpeg()
|
||||
|
||||
|
||||
class Source:
|
||||
"""Two tracks: one fully prepped (grid, hot cue, memory loop, cover), one bare."""
|
||||
|
||||
def __init__(self):
|
||||
self.t = {
|
||||
str(ONE): Track(id=str(ONE), title="Kick One", artist="Konduktor: Test", album="Probe EP",
|
||||
bpm=120.0, length=20, rating=4, filepath=str(ONE)),
|
||||
str(TWO): Track(id=str(TWO), title="Kick Two", length=20, filepath=str(TWO)),
|
||||
}
|
||||
|
||||
@property
|
||||
def tracks(self):
|
||||
return list(self.t.values())
|
||||
|
||||
def track(self, i):
|
||||
return self.t.get(i)
|
||||
|
||||
def track_cues(self, i):
|
||||
if i != str(ONE):
|
||||
return None
|
||||
return TrackCues(grid_markers=[GridMarker(start=0.5, bpm=120.0)], cues=[
|
||||
CuePoint(role="hotcue", slot=1, start=2.5, length=0.0, type="cue", color="#FF0045", name="In"),
|
||||
CuePoint(role="hotcue", slot=1, start=4.5, length=0.0, type="cue"), # pad taken -> memory
|
||||
CuePoint(role="memory", start=8.5, length=2.0, type="loop"),
|
||||
])
|
||||
|
||||
def cover_art(self, i):
|
||||
return (COVER, "image/jpeg") if i == str(ONE) else None
|
||||
|
||||
|
||||
class CancelOnFirstBytes(JobHandle):
|
||||
def progress(self, done=None, **kw):
|
||||
super().progress(done=done, **kw)
|
||||
if done:
|
||||
self._job._cancel.set()
|
||||
|
||||
|
||||
def run(adapter, handle_cls=JobHandle, track_ids=(str(ONE), str(TWO))):
|
||||
plan = importer.plan(Source(), adapter, None, track_ids=list(track_ids))
|
||||
return importer.run(Source(), adapter, plan, handle_cls(Job(id="t", kind="import")))
|
||||
|
||||
|
||||
# ---- placement -----------------------------------------------------------------
|
||||
print("== the library places the audio ==")
|
||||
drive = copy_of()
|
||||
a = OneLibraryAdapter(drive)
|
||||
caps = a.capabilities()
|
||||
check("an editable stick adds, removes, and places its own audio",
|
||||
caps.tracks.addable and caps.tracks.removable and caps.tracks.places_audio)
|
||||
check("a browsing one does neither", not OneLibraryAdapter(drive, read_only=True).capabilities().tracks.addable)
|
||||
on_stick = drive / "Contents" / "Here.mp3"
|
||||
on_stick.parent.mkdir(parents=True, exist_ok=True)
|
||||
on_stick.write_bytes(b"x")
|
||||
check("a file already on the stick is used where it is", a.place_audio(on_stick, Track(id="x")) is None)
|
||||
target = a.place_audio(ONE, Track(id="x", artist="A/B: C", album="Album."))
|
||||
final = a._store.final_of(target)
|
||||
check("anything else is copied in through .konduktor-incoming/",
|
||||
target.parent == drive / ".konduktor-incoming" and target.suffix == ".mp3")
|
||||
check("to Contents/<Artist>/<Album>/, with characters FAT refuses replaced",
|
||||
final == drive / "Contents" / "A_B_ C" / "Album" / "Kick One.mp3", str(final))
|
||||
check("no artist or album: UnknownArtist / UnknownAlbum (rekordbox's names)",
|
||||
a._store.final_of(a.place_audio(TWO, Track(id="y"))).parent
|
||||
== drive / "Contents" / "UnknownArtist" / "UnknownAlbum")
|
||||
long = SRC / ("L" * 60 + ".mp3")
|
||||
long.write_bytes(b"x")
|
||||
check("a long file name is cut to 48 characters, as rekordbox does",
|
||||
len(a._store.final_of(a.place_audio(long, Track(id="z"))).name) == 48)
|
||||
taken = drive / "Contents" / "UnknownArtist" / "UnknownAlbum" / "Kick Two.mp3"
|
||||
taken.parent.mkdir(parents=True, exist_ok=True)
|
||||
taken.write_bytes(b"x")
|
||||
check("a name already taken on the stick gets a suffix",
|
||||
a._store.final_of(a.place_audio(TWO, Track(id="y"))).name == "Kick Two-2.mp3")
|
||||
a.close()
|
||||
|
||||
# ---- adding ----------------------------------------------------------------------
|
||||
print("== an import into the stick ==")
|
||||
drive = copy_of()
|
||||
a = OneLibraryAdapter(drive)
|
||||
before_n = rows(drive, "SELECT numberOfContents AS n FROM property")[0]["n"]
|
||||
result = run(a)
|
||||
one_id, two_id = result["track_ids"]
|
||||
check("both tracks are added", result["tracks"] == 2)
|
||||
check("the import saved, so the copies are in place and the incoming folder is gone",
|
||||
(drive / one_id.lstrip("/")).is_file() and (drive / two_id.lstrip("/")).is_file()
|
||||
and not (drive / ".konduktor-incoming").exists())
|
||||
check("laid out as rekordbox does",
|
||||
one_id == "/Contents/Konduktor_ Test/Probe EP/Kick One.mp3"
|
||||
and two_id == "/Contents/UnknownArtist/UnknownAlbum/Kick Two.mp3", f"{one_id} {two_id}")
|
||||
check("the projection plays them from there", a.track(one_id).filepath == str(drive / one_id.lstrip("/")))
|
||||
cues = a.track_cues(one_id)
|
||||
hot = [c for c in cues.cues if c.role == "hotcue"]
|
||||
memory = sorted((c for c in cues.cues if c.role == "memory"), key=lambda c: c.start)
|
||||
check("a hot cue keeps its pad, colour and name",
|
||||
[(c.slot, round(c.start, 2), c.color, c.name) for c in hot] == [(1, 2.5, "#FF0045", "In")], str(hot))
|
||||
check("a memory loop, and a hot cue whose pad was taken, cross as memory cues",
|
||||
[(round(c.start, 2), c.type) for c in memory] == [(4.5, "cue"), (8.5, "loop")], str(memory))
|
||||
check("its grid crosses", [(round(m.start, 3), m.bpm) for m in cues.grid_markers] == [(0.5, 120.0)],
|
||||
str(cues.grid_markers))
|
||||
check("a file with no grid gets Konduktor's", len(a.track_cues(two_id).grid_markers) == 1)
|
||||
dat = drive / rows(drive, f"SELECT analysisDataFilePath AS p FROM content WHERE path = '{one_id}'")[0]["p"].lstrip("/")
|
||||
check("its .DAT, .EXT and .2EX are on the stick",
|
||||
all(dat.with_suffix(s).is_file() for s in (".DAT", ".EXT", ".2EX")))
|
||||
|
||||
row = rows(drive, f"SELECT * FROM content WHERE path = '{one_id}'")[0]
|
||||
check("the row is shaped like rekordbox's own (search NULL, no counters, '' texts)",
|
||||
row["titleForSearch"] is None and row["cueUpdateCount"] is None and row["hasModified"] == 0
|
||||
and row["subtitle"] == "" and row["isrc"] == "" and row["contentLink"] == 788224
|
||||
and row["analysedBits"] == 41, str(row))
|
||||
check("with the file's facts", row["fileName"] == "Kick One.mp3" and row["fileType"] == 1
|
||||
and row["samplingRate"] == 44100 and row["bpmx100"] == 12000 and row["rating"] == 4)
|
||||
check("dates as YYYY-MM-DD text", len(row["dateAdded"]) == 10 and len(row["dateCreated"] or "") == 10)
|
||||
check("the track count follows",
|
||||
rows(drive, "SELECT numberOfContents AS n FROM property")[0]["n"] == before_n + 2)
|
||||
image = rows(drive, f"SELECT path FROM image WHERE image_id = {row['image_id']}")[0]["path"]
|
||||
art = drive / "PIONEER" / "Artwork" / "00001"
|
||||
n = row["image_id"]
|
||||
check("the cover is written as rekordbox writes it: a/b pairs, 80 and 240 px",
|
||||
image == f"/PIONEER/Artwork/00001/b{n}.jpg"
|
||||
and all((art / f"{x}{n}{s}.jpg").is_file() for x in "ab" for s in ("", "_m")))
|
||||
check("and served as the track's art", a.cover_art(one_id)[1] == "image/jpeg")
|
||||
|
||||
lib = pdb.read((drive / "PIONEER" / "rekordbox" / "export.pdb").read_bytes())
|
||||
new = {t["file_path"]: t for t in lib.tracks}
|
||||
check("the Device Library lists both, with OneLibrary's ids",
|
||||
new.get(one_id, {}).get("id") == row["content_id"] and two_id in new)
|
||||
check("their analysis paths and artwork (the a<n> file) reach it too",
|
||||
new[one_id]["analyze_path"] == row["analysisDataFilePath"]
|
||||
and lib.artwork.get(new[one_id]["artwork_id"]) == f"/PIONEER/Artwork/00001/a{n}.jpg")
|
||||
a.close()
|
||||
|
||||
print("== nothing is left behind ==")
|
||||
drive = copy_of()
|
||||
before = fingerprint(drive)
|
||||
a = OneLibraryAdapter(drive)
|
||||
try:
|
||||
run(a, CancelOnFirstBytes)
|
||||
cancelled = False
|
||||
except JobCancelled:
|
||||
cancelled = True
|
||||
check("a cancel mid-copy leaves the stick exactly as it was",
|
||||
cancelled and fingerprint(drive) == before and not a.dirty)
|
||||
target = a.place_audio(ONE, Track(id="x", title="Kick"))
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(ONE, target)
|
||||
[pending] = a.add_tracks([NewTrack(track=Track(id="x", title="Kick"), audio_path=target)])
|
||||
check("an unsaved add plays from its incoming copy", a.track(pending).filepath == str(target))
|
||||
a.reload()
|
||||
check("Discard deletes the copy and leaves the stick as it was",
|
||||
not target.exists() and fingerprint(drive) == before and a.track(pending) is None)
|
||||
a.close()
|
||||
(drive / ".konduktor-incoming").mkdir()
|
||||
(drive / ".konduktor-incoming" / "crashed.mp3").write_bytes(b"x")
|
||||
OneLibraryAdapter(drive, read_only=True).close()
|
||||
check("a crash's leftovers survive a BROWSING open", (drive / ".konduktor-incoming").exists())
|
||||
OneLibraryAdapter(drive).close()
|
||||
check("and are cleared by the next editable one", not (drive / ".konduktor-incoming").exists())
|
||||
|
||||
# ---- removing ----------------------------------------------------------------------
|
||||
print("== removing tracks ==")
|
||||
drive = copy_of()
|
||||
a = OneLibraryAdapter(drive)
|
||||
by = lambda prefix: next(t for t in a.tracks if t.title.startswith(prefix)) # noqa: E731
|
||||
victim = by("Demo Track 1")
|
||||
audio = drive / victim.id.lstrip("/")
|
||||
audio.parent.mkdir(parents=True, exist_ok=True)
|
||||
audio.write_bytes(b"audio") # the fixture carries no audio
|
||||
dat = a._store.layout.resolve(a._store.content(victim.id).analysisDataFilePath)
|
||||
tian = by("Tian") # holds image 3, shared with nobody
|
||||
n = a._store.content(tian.id).image_id
|
||||
art = drive / "PIONEER" / "Artwork" / "00001"
|
||||
art.mkdir(parents=True, exist_ok=True)
|
||||
for x in "ab":
|
||||
for s in ("", "_m"):
|
||||
(art / f"{x}{n}{s}.jpg").write_bytes(b"jpg")
|
||||
demos = next(p for p in a.playlist_tree() if p.name == "demos")
|
||||
count = rows(drive, "SELECT numberOfContents AS n FROM property")[0]["n"]
|
||||
|
||||
check("removing two tracks reports two", a.remove_tracks([victim.id, tian.id]) == 2)
|
||||
check("they leave the library and its playlists at once",
|
||||
a.track(victim.id) is None and victim.id not in (a.playlist_entries(demos.id) or []))
|
||||
check("but nothing is deleted before Save", audio.exists() and dat.exists() and (art / f"b{n}.jpg").exists())
|
||||
a.save()
|
||||
check("Save deletes the audio, the analysis files and the unshared artwork",
|
||||
not audio.exists() and not dat.exists() and not dat.with_suffix(".EXT").exists()
|
||||
and not any((art / f"{x}{n}{s}.jpg").exists() for x in "ab" for s in ("", "_m")))
|
||||
check("and prunes the folders that left empty", not dat.parent.exists())
|
||||
check("the drive's top-level folders stay", (drive / "Contents").is_dir() and (drive / "PIONEER" / "USBANLZ").is_dir())
|
||||
seqs = [r["sequenceNo"] for r in rows(drive, f"SELECT sequenceNo FROM playlist_content "
|
||||
f"WHERE playlist_id = {demos.id} ORDER BY sequenceNo")]
|
||||
check("the playlist is renumbered from 1", seqs == list(range(1, len(seqs) + 1)), str(seqs))
|
||||
check("no row anywhere names them",
|
||||
not rows(drive, f"SELECT 1 FROM content WHERE path IN ('{victim.id}', '{tian.id}')")
|
||||
and not rows(drive, f"SELECT 1 FROM image WHERE image_id = {n}"))
|
||||
check("the track count follows", rows(drive, "SELECT numberOfContents AS n FROM property")[0]["n"] == count - 2)
|
||||
lib = pdb.read((drive / "PIONEER" / "rekordbox" / "export.pdb").read_bytes())
|
||||
check("and the Device Library drops them, their entries and the artwork row",
|
||||
not {victim.id, tian.id} & {t["file_path"] for t in lib.tracks}
|
||||
and all(t != 1 for _i, t, _p in lib.entries) and n not in lib.artwork)
|
||||
a.close()
|
||||
|
||||
print("== removing a track added this session, before Save ==")
|
||||
drive = copy_of()
|
||||
before = fingerprint(drive)
|
||||
a = OneLibraryAdapter(drive)
|
||||
target = a.place_audio(ONE, Track(id="x", title="Kick"))
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(ONE, target)
|
||||
[pending] = a.add_tracks([NewTrack(track=Track(id="x", title="Kick"), audio_path=target)])
|
||||
a.remove_tracks([pending])
|
||||
check("its copy is deleted at once", not target.exists())
|
||||
a.save()
|
||||
check("and the save leaves no trace of it",
|
||||
not rows(drive, f"SELECT 1 FROM content WHERE path = '{pending}'")
|
||||
and not (drive / pending.lstrip("/")).exists())
|
||||
a.close()
|
||||
|
||||
print()
|
||||
print("RESULT:", "FAILED" if failed else "ALL PASSED")
|
||||
sys.exit(1 if failed else 0)
|
||||
Reference in new issue
Block a user