mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added support for comment 2
This commit is contained in:
1 parent
90beeef226
commit
eccd352ae5
9 files changed
+65
-5
No files matched your search
@@ -1020,7 +1020,10 @@ diff — no COLLECTION splicing needed.
|
|||||||
child (`CollectionService.stem_keys`, resolved via `entries_for`), else `TRACK`.
|
child (`CollectionService.stem_keys`, resolved via `entries_for`), else `TRACK`.
|
||||||
- **Track metadata**: `set_track_metadata(track_id, fields)` edits only the SAFE
|
- **Track metadata**: `set_track_metadata(track_id, fields)` edits only the SAFE
|
||||||
set — title, artist, album, genre, label, remixer, producer, mix,
|
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
|
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
|
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
|
Edit Tags dialog AND the inline table editing (double-click cell, click rating
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TraktorExporter:
|
|||||||
Path(self.library_filename),
|
Path(self.library_filename),
|
||||||
[
|
[
|
||||||
"title", "artist", "album", "genre", "label", "remixer",
|
"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,
|
producer=info.producer if info else None,
|
||||||
mix=info.mix if info else None,
|
mix=info.mix if info else None,
|
||||||
comment=info.comment 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),
|
bpm=beatgrid.effective_bpm(e),
|
||||||
key=info.key if info else None,
|
key=info.key if info else None,
|
||||||
key_wheel=wheel,
|
key_wheel=wheel,
|
||||||
|
|||||||
@@ -362,7 +362,10 @@ class TraktorStore:
|
|||||||
# (it's the primary key), bpm/key (audio/grid territory), and read-only info
|
# (it's the primary key), bpm/key (audio/grid territory), and read-only info
|
||||||
# like bitrate/playcount.
|
# like bitrate/playcount.
|
||||||
_INFO_FIELDS = {"genre", "label", "remixer", "producer", "comment", "mix", "release_date"}
|
_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:
|
def set_track_metadata(self, track_id: str, fields: dict) -> None:
|
||||||
with self._lock:
|
with self._lock:
|
||||||
@@ -380,6 +383,10 @@ class TraktorStore:
|
|||||||
entry.album.title = v or None
|
entry.album.title = v or None
|
||||||
elif k in self._INFO_FIELDS:
|
elif k in self._INFO_FIELDS:
|
||||||
setattr(entry.info, k, v or None)
|
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":
|
elif k == "rating":
|
||||||
stars = max(0, min(5, int(v))) if v is not None else 0
|
stars = max(0, min(5, int(v))) if v is not None else 0
|
||||||
# Traktor RANKING = stars * 51; unrated has no RANKING attr.
|
# Traktor RANKING = stars * 51; unrated has no RANKING attr.
|
||||||
@@ -422,6 +429,7 @@ class TraktorStore:
|
|||||||
genre=getattr(track, "genre", None) or None,
|
genre=getattr(track, "genre", None) or None,
|
||||||
label=getattr(track, "label", None) or None,
|
label=getattr(track, "label", None) or None,
|
||||||
comment=getattr(track, "comment", 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,
|
remixer=getattr(track, "remixer", None) or None,
|
||||||
producer=getattr(track, "producer", None) or None,
|
producer=getattr(track, "producer", None) or None,
|
||||||
mix=getattr(track, "mix", None) or None,
|
mix=getattr(track, "mix", None) or None,
|
||||||
@@ -1118,6 +1126,8 @@ class TraktorStore:
|
|||||||
if field == "rating":
|
if field == "rating":
|
||||||
r = entry.info.ranking if entry.info else None
|
r = entry.info.ranking if entry.info else None
|
||||||
return round(r / 51) if r else 0
|
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
|
return getattr(entry.info, field, None) if entry.info else None
|
||||||
|
|
||||||
def count_playlists(self) -> int:
|
def count_playlists(self) -> int:
|
||||||
@@ -1159,7 +1169,8 @@ class TraktorStore:
|
|||||||
# Report BOTH writes: a failed tag write must not be masked by a
|
# Report BOTH writes: a failed tag write must not be masked by a
|
||||||
# successful art write on the same track.
|
# successful art write on the same track.
|
||||||
written = []
|
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}
|
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))
|
written.append(file_tags.write_tags(path, meta, popm_email=TRAKTOR_POPM_EMAIL))
|
||||||
if track_id in self._track_art:
|
if track_id in self._track_art:
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ class Track(BaseModel):
|
|||||||
producer: str | None = None
|
producer: str | None = None
|
||||||
mix: str | None = None
|
mix: str | None = None
|
||||||
comment: 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
|
bpm: float | None = None
|
||||||
# The platform's own display string, shown verbatim ("10m", "8A", "Am").
|
# The platform's own display string, shown verbatim ("10m", "8A", "Am").
|
||||||
key: str | None = None
|
key: str | None = None
|
||||||
|
|||||||
@@ -136,6 +136,42 @@ with tempfile.TemporaryDirectory() as d:
|
|||||||
check("marker count reached the track projection",
|
check("marker count reached the track projection",
|
||||||
adapter.track(tid2).grid_marker_count == grid_before + 1)
|
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 --------------------------------------
|
# ---- analysed grid vs plain replace --------------------------------------
|
||||||
print("== set_analysed_grid writes Traktor's own shape, replace_grid does not ==")
|
print("== set_analysed_grid writes Traktor's own shape, replace_grid does not ==")
|
||||||
with tempfile.TemporaryDirectory() as d:
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
|||||||
+3
-1
@@ -11,6 +11,8 @@ export interface Track {
|
|||||||
producer: string | null
|
producer: string | null
|
||||||
mix: string | null
|
mix: string | null
|
||||||
comment: string | null
|
comment: string | null
|
||||||
|
/** A second free-text comment (Traktor's "Comment 2"). */
|
||||||
|
comment2: string | null
|
||||||
bpm: number | null
|
bpm: number | null
|
||||||
/** The platform's own display string, shown verbatim: "10m", "8A", "Am". */
|
/** The platform's own display string, shown verbatim: "10m", "8A", "Am". */
|
||||||
key: string | null
|
key: string | null
|
||||||
@@ -116,7 +118,7 @@ export type MediaKind = 'audio' | 'stem' | 'video'
|
|||||||
export type PlaylistKind = 'folder' | 'playlist' | 'smart'
|
export type PlaylistKind = 'folder' | 'playlist' | 'smart'
|
||||||
export type TrackField =
|
export type TrackField =
|
||||||
| 'title' | 'artist' | 'album' | 'genre' | 'label' | 'remixer'
|
| 'title' | 'artist' | 'album' | 'genre' | 'label' | 'remixer'
|
||||||
| 'producer' | 'mix' | 'release_date' | 'comment' | 'rating'
|
| 'producer' | 'mix' | 'release_date' | 'comment' | 'comment2' | 'rating'
|
||||||
|
|
||||||
export interface CuePoint {
|
export interface CuePoint {
|
||||||
name: string | null
|
name: string | null
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const TEXT_FIELDS: { key: keyof Track; label: string; textarea?: boolean }[] = [
|
|||||||
{ key: 'mix', label: 'Mix' },
|
{ key: 'mix', label: 'Mix' },
|
||||||
{ key: 'release_date', label: 'Release date' },
|
{ key: 'release_date', label: 'Release date' },
|
||||||
{ key: 'comment', label: 'Comment', textarea: true },
|
{ key: 'comment', label: 'Comment', textarea: true },
|
||||||
|
{ key: 'comment2', label: 'Comment 2', textarea: true },
|
||||||
]
|
]
|
||||||
|
|
||||||
export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
|
export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
|||||||
col.accessor('producer', { id: 'producer', header: 'Producer', size: 140, cell: editable('producer') }),
|
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('mix', { id: 'mix', header: 'Mix', size: 120, cell: editable('mix') }),
|
||||||
col.accessor('comment', { id: 'comment', header: 'Comment', size: 200, cell: editable('comment') }),
|
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', {
|
col.accessor('bpm', {
|
||||||
id: 'bpm',
|
id: 'bpm',
|
||||||
header: 'BPM',
|
header: 'BPM',
|
||||||
|
|||||||
Reference in new issue
Block a user