diff --git a/CLAUDE.md b/CLAUDE.md index e8276ac..bcd66da 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1020,7 +1020,10 @@ diff — no COLLECTION splicing needed. child (`CollectionService.stem_keys`, resolved via `entries_for`), else `TRACK`. - **Track metadata**: `set_track_metadata(track_id, fields)` edits only the SAFE set — title, artist, album, genre, label, remixer, producer, mix, - release_date, comment, rating (0–5 stars → `RANKING = stars*51`). Path, BPM and + release_date, comment, comment2, rating (0–5 stars → `RANKING = stars*51`). + **`comment2` is Traktor's "Comment 2", stored in `INFO@RATING`** — free + text despite the name, unrelated to the stars — and it is collection-only: + Traktor writes no file tag for it, so `_sync_file_tags` skips it too. Path, BPM and key are intentionally NOT editable via metadata (path = identity; BPM/key are audio/grid — BPM is edited through the grid path below). This is the set the Edit Tags dialog AND the inline table editing (double-click cell, click rating diff --git a/backend/konduktor/adapters/traktor/export.py b/backend/konduktor/adapters/traktor/export.py index 8f84663..6063889 100644 --- a/backend/konduktor/adapters/traktor/export.py +++ b/backend/konduktor/adapters/traktor/export.py @@ -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", ], ) diff --git a/backend/konduktor/adapters/traktor/projection.py b/backend/konduktor/adapters/traktor/projection.py index df9124e..38373fc 100644 --- a/backend/konduktor/adapters/traktor/projection.py +++ b/backend/konduktor/adapters/traktor/projection.py @@ -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, diff --git a/backend/konduktor/adapters/traktor/store.py b/backend/konduktor/adapters/traktor/store.py index fdc0510..134b922 100644 --- a/backend/konduktor/adapters/traktor/store.py +++ b/backend/konduktor/adapters/traktor/store.py @@ -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: diff --git a/backend/konduktor/core/model.py b/backend/konduktor/core/model.py index b000713..f0428d1 100644 --- a/backend/konduktor/core/model.py +++ b/backend/konduktor/core/model.py @@ -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 diff --git a/backend/test_traktor_adapter.py b/backend/test_traktor_adapter.py index 38c6318..d24310b 100644 --- a/backend/test_traktor_adapter.py +++ b/backend/test_traktor_adapter.py @@ -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: diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 695f126..5a4f1a7 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -11,6 +11,8 @@ export interface Track { producer: string | null mix: string | null comment: string | null + /** A second free-text comment (Traktor's "Comment 2"). */ + comment2: string | null bpm: number | null /** The platform's own display string, shown verbatim: "10m", "8A", "Am". */ key: string | null @@ -116,7 +118,7 @@ export type MediaKind = 'audio' | 'stem' | 'video' export type PlaylistKind = 'folder' | 'playlist' | 'smart' export type TrackField = | 'title' | 'artist' | 'album' | 'genre' | 'label' | 'remixer' - | 'producer' | 'mix' | 'release_date' | 'comment' | 'rating' + | 'producer' | 'mix' | 'release_date' | 'comment' | 'comment2' | 'rating' export interface CuePoint { name: string | null diff --git a/frontend/src/components/EditTagsDialog.tsx b/frontend/src/components/EditTagsDialog.tsx index 307017e..80ba4bd 100644 --- a/frontend/src/components/EditTagsDialog.tsx +++ b/frontend/src/components/EditTagsDialog.tsx @@ -26,6 +26,7 @@ const TEXT_FIELDS: { key: keyof Track; label: string; textarea?: boolean }[] = [ { key: 'mix', label: 'Mix' }, { key: 'release_date', label: 'Release date' }, { key: 'comment', label: 'Comment', textarea: true }, + { key: 'comment2', label: 'Comment 2', textarea: true }, ] export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) { diff --git a/frontend/src/lib/trackColumns.tsx b/frontend/src/lib/trackColumns.tsx index c4aa0eb..671073e 100644 --- a/frontend/src/lib/trackColumns.tsx +++ b/frontend/src/lib/trackColumns.tsx @@ -179,6 +179,7 @@ export const TRACK_COLUMNS: ColumnDef[] = [ col.accessor('producer', { id: 'producer', header: 'Producer', size: 140, cell: editable('producer') }), col.accessor('mix', { id: 'mix', header: 'Mix', size: 120, cell: editable('mix') }), col.accessor('comment', { id: 'comment', header: 'Comment', size: 200, cell: editable('comment') }), + col.accessor('comment2', { id: 'comment2', header: 'Comment 2', size: 200, cell: editable('comment2') }), col.accessor('bpm', { id: 'bpm', header: 'BPM',