From 9f8778c46ff282e15425f55a8c6f6c6018b54366 Mon Sep 17 00:00:00 2001 From: Vynull App Date: Mon, 23 Nov 2026 00:02:28 +0000 Subject: [PATCH] tools: read My Tag smart-list values as rekordbox does rekordbox reads a My Tag condition's value as a signed 32-bit integer attribute (JUCE getIntAttribute) whose bits are the tag ID: a positive value past the signed range saturates to its top, an underflow to its bottom, "0x1" and malformed text are tag 0, and "1,2147483648" is tag 1 (link-spec SMART_PLAYLIST_ORACLE.md, "My Tag condition semantics"). The dump helper parsed it with Python's int(), so a saturated value named the tag above the range and anything else unparsable was looked up as a tag name. juce_int now saturates like JUCE's conversion, and the helper resolves My Tag values with it; a value naming no tag keeps the ID it read. The operator and logical-operator reads already used juce_int; saturating can't change their outcome. --- library/rekordbox_dump_parse_test.go | 47 ++++++++++++++++++++++++++++ tools/rekordbox_dump.py | 21 ++++++++----- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/library/rekordbox_dump_parse_test.go b/library/rekordbox_dump_parse_test.go index 39e9bc6..09edb11 100644 --- a/library/rekordbox_dump_parse_test.go +++ b/library/rekordbox_dump_parse_test.go @@ -85,3 +85,50 @@ json.dump(out, sys.stdout) } } } + +// The helper resolves a My Tag condition's value as rekordbox reads it: a +// signed 32-bit integer attribute whose bits are the tag ID, saturating past +// the signed range, reading malformed text as tag 0 and a leading number +// from anything else (link-spec smart-mytag-matrix, rekordbox 7.2.19). +func TestDumpHelperReadsMyTagValuesLikeRekordbox(t *testing.T) { + if _, err := exec.LookPath("python3"); err != nil { + t.Skip("python3 not available") + } + const script = ` +import importlib.util, json, sys, types +sys.modules["sqlcipher3"] = types.ModuleType("sqlcipher3") +spec = importlib.util.spec_from_file_location("dump", "../tools/rekordbox_dump.py") +dump = importlib.util.module_from_spec(spec) +spec.loader.exec_module(dump) +tags = {"0": "Zero", "1": "One", "2147483647": "Max", "2147483648": "High", "4294967295": "All"} +def tag(value): + xml = '' % value + return dump.parse_smartlist(xml, tags)["conditions"][0]["left"] +values = ["1", "2147483647", "2147483648", "4294967295", "4294967296", "-2147483648", "-1", + "-2147483649", " 001", "+1", " 1 ", "0x1", "1,2147483648", "wat", "", "12345"] +json.dump({v: tag(v) for v in values}, sys.stdout) +` + raw, err := exec.Command("python3", "-c", script).CombinedOutput() + if err != nil { + t.Fatalf("python3: %v\n%s", err, raw) + } + var got map[string]string + if err := json.Unmarshal(raw, &got); err != nil { + t.Fatalf("decode %s: %v", raw, err) + } + for value, want := range map[string]string{ + "1": "One", "2147483647": "Max", + // Past the signed range saturates to its top, not the bits above it. + "2147483648": "Max", "4294967295": "Max", "4294967296": "Max", + // Negative values carry the high bit; underflow saturates to it. + "-2147483648": "High", "-1": "All", "-2147483649": "High", + " 001": "One", "+1": "One", " 1 ": "One", + "0x1": "Zero", "1,2147483648": "One", "wat": "Zero", + "": "", // blank stays blank and matches nothing + "12345": "12345", // no such tag + } { + if got[value] != want { + t.Errorf("ValueLeft %q resolved to %q, want %q", value, got[value], want) + } + } +} diff --git a/tools/rekordbox_dump.py b/tools/rekordbox_dump.py index d87b533..3d66688 100644 --- a/tools/rekordbox_dump.py +++ b/tools/rekordbox_dump.py @@ -70,9 +70,13 @@ def open_db(db_path, provided_key): def juce_int(s): """Read text as rekordbox does an integer attribute (JUCE getIntValue): an optionally signed run of leading digits after any spaces, 0 if none, - so "1.5" is 1 and "wat" is 0.""" + so "1.5" is 1, "0x1" is 0 and "wat" is 0, saturated to a signed 32-bit + int, so "2147483648" is 2147483647 (link-spec smart-mytag-matrix, + rekordbox 7.2.19).""" m = re.match(r"\s*([+-]?\d+)", s or "") - return int(m.group(1)) if m else 0 + if not m: + return 0 + return max(-(1 << 31), min(int(m.group(1)), (1 << 31) - 1)) def db_int(v, bits=32, signed=True): @@ -271,12 +275,13 @@ def parse_smartlist(xml_str, tags_by_id): a = cnd.attrib prop = a.get("PropertyName", "") left = a.get("ValueLeft", "") - if prop == "myTag" and left: - try: - uid = str(int(left) & 0xFFFFFFFF) # signed int32 → unsigned key - left = tags_by_id.get(uid, left) - except ValueError: - pass + if prop == "myTag" and left.strip(): + # rekordbox reads the tag ID as an integer attribute (juce_int), + # so a positive ID past the signed range saturates and malformed + # text is tag 0; the signed value's bits are djmdMyTag.ID. A blank + # value stays blank: it matches nothing either way. + uid = str(juce_int(left) & 0xFFFFFFFF) + left = tags_by_id.get(uid, uid) conds.append({ "property": prop, "operator": juce_int(a.get("Operator", "")),