Add rekordbox XML generator and validator

Walks a music folder tree and emits a rekordbox-compatible DJ_PLAYLISTS XML
where each directory becomes a playlist, preserving nesting as folder nodes.

- reads ID3, Vorbis and MP4 metadata (title, artist, album, BPM, key, ...)
- percent-encoded file:// locations, safe for umlauts and brackets in paths
- strips control characters that would make the XML unparseable
- skips 0-byte downloads and macOS AppleDouble stubs by default
- optional ffprobe fallback for durations mutagen cannot read

validate_rekordbox_xml.py checks the result before import: well-formedness,
resolvable locations, unique TrackIDs and intact playlist references.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-19 23:39:40 +02:00
co-authored by Claude Opus 5
commit 8bcb6256fa
5 changed files with 550 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
# rekordbox_xmlfilecreater
Turn a folder of music into a **rekordbox XML** — your directory structure becomes the playlist tree, with tags, cover-derived metadata, BPM and key carried over.
Point it at a music folder, get a `rekordbox.xml` you can load straight into rekordbox. No database writes, no imports that reorganise your files: the XML only *references* the tracks where they already are.
## Why
rekordbox can import an XML library (the format iTunes/Rekordbox share). Building one by hand for thousands of tracks is not realistic, and dragging folders into rekordbox one by one loses the structure. This script walks the tree once and emits the whole thing.
## Install
```bash
pip install mutagen
```
`ffprobe` (from [FFmpeg](https://ffmpeg.org/)) is optional — it is used only as a fallback to measure duration for files whose headers mutagen cannot read. Without it those tracks get a length of 0, which rekordbox fixes on analysis.
## Usage
```bash
python rekordbox_xml.py "D:/Music" -o rekordbox.xml
```
Options:
| Flag | Effect |
|---|---|
| `-o`, `--output` | output path (default `rekordbox.xml`) |
| `--keep-empty` | include 0-byte files (skipped by default as failed downloads) |
| `--keep-apple` | include `__MACOSX` folders and `._*` AppleDouble stubs |
| `-q`, `--quiet` | suppress progress output |
Then check it before importing:
```bash
python validate_rekordbox_xml.py rekordbox.xml
```
This confirms the XML is well-formed, every `Location` resolves to a file that exists, TrackIDs are unique, and no playlist points at a missing track.
## Import into rekordbox
1. **Preferences → View → Layout** → tick **rekordbox xml**
2. **Preferences → Advanced → Database → rekordbox xml** → set *Imported Library* to your file
3. The tree appears in the sidebar under **rekordbox xml**
4. Right-click a playlist or the collection → **Import Playlist** / **Import to Collection**
Nothing is written to your files, and nothing moves on disk.
## How the tree maps
```
Music/
├── Techno/
│ ├── track1.wav -> playlist "Techno"
│ └── Hard/
│ └── track2.wav -> playlist "Hard" nested under folder "Techno"
└── Charts/
└── track3.mp3 -> playlist "Charts"
```
A directory containing **only** tracks becomes a playlist. A directory containing **only** subdirectories becomes a folder. A directory with **both** becomes a folder holding a same-named playlist for its own tracks, plus the subdirectories.
## Formats and metadata
Reads `.wav` `.mp3` `.flac` `.m4a` `.aiff` `.aif` `.wma` `.ogg` `.opus` `.alac`.
Metadata is pulled from ID3 (MP3/WAV/AIFF), Vorbis comments (FLAC/OGG) and MP4 atoms (M4A): title, artist, album, genre, year, track/disc number, BPM, key, composer, label, remixer. Missing titles fall back to the filename.
## Notes
- **WAV tags**: rekordbox reads ID3v2 chunks in WAV. If your WAVs are untagged, the filename is used as the title — tag them first if you want more.
- **BPM/key**: only copied if already present in the tags. rekordbox computes its own on analysis, which is generally more reliable.
- **Character handling**: control characters that are illegal in XML 1.0 are stripped from tags — they otherwise make the file unparseable. Paths are percent-encoded, so umlauts, emoji and brackets in folder names are safe.
- **Re-running** regenerates the file from scratch; it does not merge with an existing XML.
Tested on a ~19,000-track library across ~700 folders (mixed WAV/MP3/M4A/AIFF).
## License
MIT