Implemented feature parity between Rekordbox and OneLibrary exporters

This commit is contained in:
patben8 committed 2026-09-27 22:37:14 +02:00
1 parent 157c2c0a04
commit 0b909a84f4
5 files changed
+268 -23

No files matched your search

+86 -13
View File
@@ -58,7 +58,9 @@ from sqlalchemy import text
from ...core.export import ExportPayload, ExportTrack, WrittenLibrary
from ...core import waveform
from ...core.cue_colors import effective_color
from . import anlz_writer as W
from . import artwork, palette
from . import timebase
from .beatgrid import beats_from_markers
from .capabilities import capabilities_for
@@ -80,6 +82,29 @@ SEED = _FIXTURES / "seed.sql"
#: Rekordbox counts cue positions in frames at 150 fps, not milliseconds.
FRAMES_PER_SECOND = 150
#: `djmdContent.ContentLink` — NOT optional, and a bit field. Measured by giving
#: five tracks of a Konduktor-written library different values and loading it
#: in Rekordbox 7: with it NULL the song-list preview is plain blue with a "?"
#: beside CUE; any value colours the preview; the 0x200000 bit (0x2C060E here,
#: 0x0C060E without it) clears the "?"; and 0x3D060E — what the real library's
#: MP3/M4A tracks carry — adds two more bits that draw an extra badge, most
#: likely claiming phrase/vocal analysis this exporter does not write. So the
#: value that claims only what is written: 0x2C060E.
CONTENT_LINK = 2885134
#: Rekordbox's playlist side file, beside master.db. It lists every playlist
#: node with a `Timestamp` matching the row's `updated_at` (ms); a playlist the
#: file does not vouch for is not shown. The skeleton is a real Rekordbox 7
#: file's, minus its nodes — pyrekordbox adds ours as it creates them.
PLAYLISTS_XML = "masterPlaylists6.xml"
PLAYLISTS_XML_SKELETON = (
'<?xml version="1.0" encoding="UTF-8"?>\n\n'
'<MASTER_PLAYLIST Version="3.0.0" AutomaticSync="0">\n'
' <PRODUCT Name="rekordbox" Version="7.2.18" Company="Pioneer DJ"/>\n'
' <PLAYLISTS>\n </PLAYLISTS>\n'
'</MASTER_PLAYLIST>\n'
)
OTHER_PLAYLIST = "Other"
@@ -128,8 +153,16 @@ class RekordboxExporter:
finally:
con.close()
# BEFORE the database is opened: pyrekordbox keeps masterPlaylists6.xml
# in step with every playlist it creates — but only if the file exists
# at open time. Without it Rekordbox opened the library, generated its
# own file listing our playlists with Timestamp 0, and showed NONE of
# them (measured by swapping an export into a real Rekordbox 7).
playlists_xml = root / PLAYLISTS_XML
playlists_xml.write_text(PLAYLISTS_XML_SKELETON, encoding="utf-8")
db = MasterDatabase(path=str(library), key=key)
extra: list[Path] = []
extra: list[Path] = [playlists_xml]
ids: dict[str, str] = {}
try:
self._seed_registry(db, models)
@@ -143,6 +176,7 @@ class RekordboxExporter:
rows[item.source_id] = content
ids[item.source_id] = str(content.ID)
extra += self._write_anlz(item, content, root, db)
extra += self._write_art(item, content, root)
self._write_playlists(db, payload, rows)
# A brand-new file: a running Rekordbox cannot have it open, so its
# process-wide veto protects nothing here.
@@ -156,7 +190,7 @@ class RekordboxExporter:
@staticmethod
def _replay_cues(library: Path, payload: ExportPayload, ids: dict) -> None:
"""Write the cues through the ORDINARY adapter, not by hand.
"""Write the cues through the ORDINARY cue-row code, not by hand.
Same reason the Traktor exporter replays commands: `set_cue` already
owns every convention a cue row needs — the sparse `Kind` bank, frames
@@ -168,24 +202,33 @@ class RekordboxExporter:
from .adapter import RekordboxAdapter
adapter = RekordboxAdapter(library)
# The store, not the adapter's commands: the adapter refuses memory cues
# (editing them in a user's library is off-limits) and takes no colour.
# Building a NEW library is neither an edit nor lossy by choice, so the
# exporter writes both — through the same `_write_cue` every edit uses.
store = adapter._store
try:
for item in payload.tracks:
track_id = ids.get(item.source_id)
if track_id is None or not item.cues:
continue
for cue in item.cues.cues:
# Memory cues are a Rekordbox-only concept the generic model
# preserves but never writes; a cue with no slot has no pad
# to land on.
if cue.role != "hotcue" or cue.slot is None:
if cue.role == "memory" or cue.slot is None:
# rekordbox's own "unset" for a memory cue with no colour.
code, _rgb = palette.code_for(cue.color)
store.add_memory_cue(
track_id, start_sec=cue.start, cue_type=cue.type,
length_sec=cue.length, name=cue.name, color_code=code or None,
)
continue
adapter.set_cue(
track_id,
slot=cue.slot,
start_sec=cue.start,
cue_type=cue.type,
length_sec=cue.length,
name=cue.name,
# What Konduktor SHOWS — stored colour, else the type's (blue
# cue, green loop) — as a palette code, which is what
# rekordbox draws from. White (a grid companion) has no swatch:
# code 0, i.e. uncoloured.
code, _rgb = palette.code_for(effective_color(cue))
store.set_cue(
track_id, slot=cue.slot, start_sec=cue.start, cue_type=cue.type,
length_sec=cue.length, name=cue.name, color_code=code or None,
)
adapter.save()
finally:
@@ -265,6 +308,7 @@ class RekordboxExporter:
# NOT `track.key`: that is the SOURCE platform's notation, so a Traktor
# export would put "10m" where Rekordbox shows "Cm".
content.KeyID = self._lookup(db, "key", render_key(track.key_wheel, track.key_mode))
content.ContentLink = CONTENT_LINK
db.flush()
return content
@@ -350,6 +394,35 @@ class RekordboxExporter:
written.append(W.write_anlz(dat.with_suffix(".2EX"), [W.path_tag(path), *two_ex]))
return written
# ---- artwork ------------------------------------------------------------------
@staticmethod
def _write_art(item: ExportTrack, content, root: Path) -> list[Path]:
"""The cover, as a rekordbox-managed track carries it.
Three JPEGs under `share/PIONEER/Artwork/<uuid[:3]>/<uuid[3:]>/` — the
same UUID split as the analysis folder — named `artwork.jpg` (the cover,
fit to 800 px), `artwork_m.jpg` (240) and `artwork_s.jpg` (80), the last
two letterboxed square. `djmdContent.ImagePath` names `artwork.jpg`,
rooted at `share/` like `AnalysisDataPath`. All measured on a real
Rekordbox 7 library.
"""
if not item.art:
return []
jpegs = artwork.library_jpegs(item.art[0])
if jpegs is None:
return []
track_uuid = str(content.UUID)
rel = f"/PIONEER/Artwork/{track_uuid[:3]}/{track_uuid[3:]}"
folder = root / "share" / rel.lstrip("/")
folder.mkdir(parents=True, exist_ok=True)
written = []
for name, data in zip(("artwork.jpg", "artwork_m.jpg", "artwork_s.jpg"), jpegs):
(folder / name).write_bytes(data)
written.append(folder / name)
content.ImagePath = f"{rel}/artwork.jpg"
return written
# ---- playlists ---------------------------------------------------------------
def _write_playlists(self, db, payload: ExportPayload, rows: dict) -> None: