Added support for comment 2

This commit is contained in:
patben8 committed 2026-09-26 22:25:59 +02:00
1 parent 90beeef226
commit eccd352ae5
9 files changed
+65 -5

No files matched your search

+1 -1
View File
@@ -75,7 +75,7 @@ class TraktorExporter:
Path(self.library_filename),
[
"title", "artist", "album", "genre", "label", "remixer",
"producer", "mix", "release_date", "comment", "rating",
"producer", "mix", "release_date", "comment", "comment2", "rating",
],
)
@@ -109,6 +109,8 @@ def to_track(e) -> Track:
producer=info.producer if info else None,
mix=info.mix if info else None,
comment=info.comment if info else None,
# Traktor's "Comment 2" is stored in INFO@RATING (stars are RANKING).
comment2=info.rating if info else None,
bpm=beatgrid.effective_bpm(e),
key=info.key if info else None,
key_wheel=wheel,
+13 -2
View File
@@ -362,7 +362,10 @@ class TraktorStore:
# (it's the primary key), bpm/key (audio/grid territory), and read-only info
# like bitrate/playcount.
_INFO_FIELDS = {"genre", "label", "remixer", "producer", "comment", "mix", "release_date"}
EDITABLE_FIELDS = {"title", "artist", "album", "rating"} | _INFO_FIELDS
EDITABLE_FIELDS = {"title", "artist", "album", "rating", "comment2"} | _INFO_FIELDS
# Fields that live only in the collection: Traktor itself writes no file tag
# for "Comment 2" (verified on an m4a it had just edited), so neither do we.
_COLLECTION_ONLY_FIELDS = {"comment2"}
def set_track_metadata(self, track_id: str, fields: dict) -> None:
with self._lock:
@@ -380,6 +383,10 @@ class TraktorStore:
entry.album.title = v or None
elif k in self._INFO_FIELDS:
setattr(entry.info, k, v or None)
elif k == "comment2":
# Traktor's "Comment 2" is INFO@RATING — a free-text
# attribute, unrelated to the star rating (RANKING).
entry.info.rating = v or None
elif k == "rating":
stars = max(0, min(5, int(v))) if v is not None else 0
# Traktor RANKING = stars * 51; unrated has no RANKING attr.
@@ -422,6 +429,7 @@ class TraktorStore:
genre=getattr(track, "genre", None) or None,
label=getattr(track, "label", None) or None,
comment=getattr(track, "comment", None) or None,
rating=getattr(track, "comment2", None) or None, # "Comment 2"
remixer=getattr(track, "remixer", None) or None,
producer=getattr(track, "producer", None) or None,
mix=getattr(track, "mix", None) or None,
@@ -1118,6 +1126,8 @@ class TraktorStore:
if field == "rating":
r = entry.info.ranking if entry.info else None
return round(r / 51) if r else 0
if field == "comment2":
return entry.info.rating if entry.info else None
return getattr(entry.info, field, None) if entry.info else None
def count_playlists(self) -> int:
@@ -1159,7 +1169,8 @@ class TraktorStore:
# Report BOTH writes: a failed tag write must not be masked by a
# successful art write on the same track.
written = []
if fields := self._journal.fields_for(track_id):
fields = self._journal.fields_for(track_id) - self._COLLECTION_ONLY_FIELDS
if fields:
meta = {f: self._entry_field_value(entry, f) for f in fields}
written.append(file_tags.write_tags(path, meta, popm_email=TRAKTOR_POPM_EMAIL))
if track_id in self._track_art:
+4
View File
@@ -41,6 +41,10 @@ class Track(BaseModel):
producer: str | None = None
mix: str | None = None
comment: str | None = None
# A second free-text comment. Traktor's "Comment 2", which it keeps only in
# the collection (`INFO@RATING` — not the star rating, that is RANKING) and
# never writes into the audio file.
comment2: str | None = None
bpm: float | None = None
# The platform's own display string, shown verbatim ("10m", "8A", "Am").
key: str | None = None
+36
View File
@@ -136,6 +136,42 @@ with tempfile.TemporaryDirectory() as d:
check("marker count reached the track projection",
adapter.track(tid2).grid_marker_count == grid_before + 1)
# ---- "Comment 2" ----------------------------------------------------------
# Traktor keeps it in INFO@RATING — a free-text attribute despite its name; the
# stars are RANKING. Mixing the two up would corrupt either field silently.
print("== Comment 2 is INFO@RATING, collection-only ==")
with tempfile.TemporaryDirectory() as d:
work = Path(d) / "collection.nml"
shutil.copy2(REAL, work)
adapter = TraktorAdapter(work)
with_c2 = [t for t in adapter.tracks if t.comment2]
check("real Comment 2 values are projected", len(with_c2) > 0, "none found")
check("comment2 is advertised as editable",
"comment2" in adapter.capabilities().tracks.editable_fields)
t = next(t for t in adapter.tracks if t.title and t.rating and not t.comment2)
adapter.set_track_metadata(t.id, {"comment2": "Konduktor C2"})
after = adapter.track(t.id)
check("comment2 edit is visible in the projection", after.comment2 == "Konduktor C2")
check("comment2 edit leaves the star rating alone", after.rating == t.rating)
outcome = adapter.save()
check("comment2 alone writes no file tags", not outcome.tag_results,
str(outcome.tag_results))
text = work.read_text(encoding="utf-8")
check("stored as INFO RATING", 'RATING="Konduktor C2"' in text)
reopened = TraktorAdapter(work).track(t.id)
check("comment2 round-trips through save",
reopened.comment2 == "Konduktor C2" and reopened.rating == t.rating)
# Clearing it removes the attribute entirely.
a2 = TraktorAdapter(work)
a2.set_track_metadata(t.id, {"comment2": ""})
a2.save()
check("clearing comment2 drops the attribute",
'RATING="Konduktor C2"' not in work.read_text(encoding="utf-8")
and TraktorAdapter(work).track(t.id).comment2 is None)
# ---- analysed grid vs plain replace --------------------------------------
print("== set_analysed_grid writes Traktor's own shape, replace_grid does not ==")
with tempfile.TemporaryDirectory() as d: