From 5719c9517af0569612df158d407e2f858679120d Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Mon, 9 Nov 2026 19:54:26 +0100 Subject: [PATCH 1/5] traktor: make NMLPath immutable and hashable NMLPath kept its parts in a mutable list and was unhashable, so paths could not be used as dictionary keys while also being mutable behind the scenes. - store parts as a tuple, make the class a frozen, slotted dataclass - take the optional volume id as a constructor argument instead of setting the private attribute after construction - derive equality and hashing from the dataclass: the volume id is excluded, so a playlist path (volume name only) equals the collection path of the same file --- plistsync/services/traktor/path.py | 36 ++++++++--------------- tests/services/traktor/test_trakorpath.py | 25 ++++++++++++++-- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/plistsync/services/traktor/path.py b/plistsync/services/traktor/path.py index 64c518bf..335ca8c1 100644 --- a/plistsync/services/traktor/path.py +++ b/plistsync/services/traktor/path.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +from dataclasses import dataclass, field from pathlib import PurePosixPath, PureWindowsPath from typing import TYPE_CHECKING, Literal, Self @@ -12,19 +13,18 @@ from lxml.etree import _Element +@dataclass(frozen=True, slots=True, init=False) class NMLPath: """OS-agnostik representation of a File Path in Traktor. Follows the logic in NML Playlists: volume/:directory/:file """ - _parts: list[str] + _parts: tuple[str, ...] + # Not part of equality: playlist paths only carry the volume name. + _volume_id: str | None = field(compare=False, default=None) - # We treat volume id as optional, and use the volume by default - # Should only be changed through our location helpers - _volume_id: str | None - - def __init__(self, path: str): + def __init__(self, path: str, volume_id: str | None = None): """Construct a TraktorPath from a Traktor-style path string. As used by Traktors NML files in the playlist section: volume/:directory/:file @@ -33,15 +33,16 @@ def __init__(self, path: str): raise ValueError( f"Invalid Traktor path: {path}, follow schema volume/:directory/:file" ) - self._parts = [p for p in path.split("/:") if p] - self._volume_id = None + object.__setattr__(self, "_parts", tuple(p for p in path.split("/:") if p)) + object.__setattr__(self, "_volume_id", volume_id) @property def volume(self) -> str: return self._parts[0] @property - def volume_id(self) -> str | None: + def volume_id(self) -> str: + """Optional volume ID, falling back to the volume name.""" if self._volume_id is not None: return self._volume_id return self.volume @@ -53,7 +54,7 @@ def directories(self) -> str: return "/:" + "/:".join(self._parts[1:-1]) + "/:" @property - def parts(self) -> list[str]: + def parts(self) -> tuple[str, ...]: return self._parts @property @@ -90,10 +91,7 @@ def from_nml_location(cls, loc: _Element) -> Self: raise ValueError("Could not find DIR, FILE or VOLUME in NML LOCATION entry") dir_parts = [p for p in dir.split("/:") if p] - tp = cls("/:".join([vol, *dir_parts, file])) - tp._volume_id = volid - - return tp + return cls("/:".join([vol, *dir_parts, file]), volume_id=volid) def to_nml_location(self, parent: _Element | None = None) -> _Element: """ @@ -164,13 +162,3 @@ def __str__(self) -> str: def __repr__(self) -> str: return f"{type(self).__name__}(path={str(self)!r})" - - def __eq__(self, value: object) -> bool: - """ - Check tracks are the same. - - Currently not comparing volume ids. - """ - if not isinstance(value, NMLPath): - return False - return str(self) == str(value) diff --git a/tests/services/traktor/test_trakorpath.py b/tests/services/traktor/test_trakorpath.py index c1983e0d..d46c112c 100644 --- a/tests/services/traktor/test_trakorpath.py +++ b/tests/services/traktor/test_trakorpath.py @@ -28,7 +28,7 @@ def test_from_path_mac(self, path, expected_parts): assert tp.volume is not None assert tp.directories is not None assert tp.file is not None - assert tp.parts == list(expected_parts) + assert tp.parts == expected_parts assert isinstance(tp.pure_path, PurePosixPath) assert str(tp.pure_path).startswith("/Volumes/") @@ -63,7 +63,7 @@ def test_from_path_windows(self, path, expected_parts): assert tp.volume is not None assert tp.directories is not None assert tp.file is not None - assert tp.parts == list(expected_parts) + assert tp.parts == expected_parts assert isinstance(tp.pure_path, PureWindowsPath) assert str(tp.pure_path).startswith(tp.volume) @@ -93,7 +93,7 @@ def test_from_nml_location(self, collection): def test_directory_structure(self): # Test the directory structure of a valid TraktorPath valid_path = NMLPath("C:/:foo/:bar/:baz/:file.flac") - assert valid_path.parts == ["C:", "foo", "bar", "baz", "file.flac"] + assert valid_path.parts == ("C:", "foo", "bar", "baz", "file.flac") assert valid_path.volume == "C:" assert valid_path.directories == "/:foo/:bar/:baz/:" assert valid_path.file == "file.flac" @@ -108,6 +108,25 @@ def test_to_nml_location_standalone(self): assert loc.get("VOLUME") == "D:" assert loc.get("VOLUMEID") == "D:" + def test_path_is_immutable_and_hashable(self): + path = NMLPath("D:/:Music/:track.flac") + + with pytest.raises(AttributeError): + path._parts = ("D:", "changed.flac") # type: ignore + + assert {path: "track"}[NMLPath("D:/:Music/:track.flac")] == "track" + + def test_volume_id_is_optional_and_not_part_of_equality(self): + """Playlist paths only carry the volume name, collection ones an id.""" + playlist_path = NMLPath("D:/:Music/:track.flac") + collection_path = NMLPath("D:/:Music/:track.flac", volume_id="6580a7aa") + + assert collection_path.volume_id == "6580a7aa" + assert playlist_path.volume_id == "D:" + assert collection_path == playlist_path + assert hash(collection_path) == hash(playlist_path) + assert collection_path.to_nml_location().get("VOLUMEID") == "6580a7aa" + def test_to_nml_location_with_parent(self): path = NMLPath("Macintosh HD/:Users/:paul/:Music/:track.mp3") parent = Element("ENTRY") From d33dc721bafd42ad42e5b86082e95e292f7b3bc6 Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Mon, 9 Nov 2026 19:54:49 +0100 Subject: [PATCH 2/5] traktor: cache the collection path index Every path lookup ran an XPath query over the whole COLLECTION node, and a track inserted into the library forced the next lookup to scan again. - build a NMLPath -> NMLTrack index on first use and reuse it afterwards - keep the index in sync on insert instead of dropping it --- plistsync/services/traktor/library.py | 35 +++++++++++------------ tests/services/traktor/test_collection.py | 23 +++++++++++++++ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/plistsync/services/traktor/library.py b/plistsync/services/traktor/library.py index 35f42c23..9b107031 100644 --- a/plistsync/services/traktor/library.py +++ b/plistsync/services/traktor/library.py @@ -38,14 +38,14 @@ class NMLLibrary( Allows to parse and interact with a Traktor NML file. I.e. traktor export playlist - Sadly nml files do not contain unique identifiers for tracks, thus we need to - iterate over all tracks to find a match. Might be less efficient than other - collections. + NML files have no unique track identifiers, so track lookups use the file path + (indexed lazily) or a metadata scan. """ path: Path tree: _ElementTree backup_before_write: bool + _track_index_cache: dict[NMLPath, NMLTrack] | None def __init__(self, path: Path | str, backup_before_write: bool): self.path = Path(path) @@ -54,6 +54,7 @@ def __init__(self, path: Path | str, backup_before_write: bool): self.backup_before_write = backup_before_write # An NML file is a XML file self.tree = etree.parse(self.path) + self._track_index_cache = None @classmethod def from_config(cls, config: TraktorConfig) -> Self: @@ -232,22 +233,9 @@ def find_by_ids(self, ids: Iterable[TrackID]) -> NMLTrack | None: def find_by_traktor_path(self, traktor_path: NMLPath) -> NMLTrack | None: """Find a track by its file path. - Parameter - --------- - traktor_path : TraktorPath - The file path of the track to find. This should be the full path including - the filename. In traktor notation /:foo/:bar.mp3. If a volume is specified, - it should will be ignored for the search. + The volume id is ignored, playlist paths only contain the volume name. """ - entry = self._collection.xpath( - f".//ENTRY/LOCATION[@DIR={xpath_string_escape(traktor_path.directories)}]" - f"[@FILE={xpath_string_escape(traktor_path.file)}]" - f"[@VOLUME={xpath_string_escape(traktor_path.volume)}]/.." - ) - if len(entry) == 0: - return None - - return NMLTrack(entry[0]) + return self._track_index().get(traktor_path) # --------------------------- TrackStream protocol --------------------------- # @@ -267,6 +255,15 @@ def __len__(self) -> int: # ---------------------------------- Helper ---------------------------------- # + def _track_index(self) -> dict[NMLPath, NMLTrack]: + """Return a path index for the collection, building the cache on first use.""" + if self._track_index_cache is None: + index: dict[NMLPath, NMLTrack] = {} + for track in self.tracks: + index.setdefault(track.traktor_path, track) + self._track_index_cache = index + return self._track_index_cache + @property def _collection(self): collection = self.tree.find("COLLECTION") @@ -317,6 +314,8 @@ def insert_track(self, track: NMLTrack | NMLPlaylistTrack, force: bool = False): count = int(collection.get("ENTRIES", "0")) collection.set("ENTRIES", str(count + 1)) inserted = NMLTrack(entry) + if self._track_index_cache is not None: + self._track_index_cache.setdefault(inserted.traktor_path, inserted) log.debug(f"Inserted track into COLLECTION: {inserted.traktor_path}") return inserted diff --git a/tests/services/traktor/test_collection.py b/tests/services/traktor/test_collection.py index 5618dce0..99ff631c 100644 --- a/tests/services/traktor/test_collection.py +++ b/tests/services/traktor/test_collection.py @@ -79,6 +79,26 @@ def test_find_by_path(self): track = self.collection.find_by_traktor_path(tp_nonexistent) assert track is None + def test_find_by_path_builds_index_once( + self, collection: NMLLibrary, monkeypatch: pytest.MonkeyPatch + ): + """Repeated path lookups reuse the index instead of rescanning the tree.""" + scans = 0 + scan_tracks = NMLLibrary.tracks.fget + assert scan_tracks is not None + + def counting_tracks(library: NMLLibrary): + nonlocal scans + scans += 1 + return scan_tracks(library) + + monkeypatch.setattr(NMLLibrary, "tracks", property(counting_tracks)) + + collection.find_by_traktor_path(NMLPath("D:/:Music/:a.flac")) + collection.find_by_traktor_path(NMLPath("D:/:Music/:b.flac")) + + assert scans == 1 + def test_write_persists(self, collection: NMLLibrary) -> None: """Calling write should persist the collection""" new_name = "Updated name" @@ -222,6 +242,9 @@ def test_library_insert_track(self, track_path): inserted = self.collection.insert_track(playlist_track) assert inserted is not None assert inserted.traktor_path == traktor_path + found = self.collection.find_by_traktor_path(traktor_path) + assert found is not None + assert found.traktor_path == traktor_path collection_node = self.collection.tree.find("COLLECTION") assert collection_node is not None From 3d92afdc4aa13c80e15bdf2252df7401e5f893a0 Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Mon, 9 Nov 2026 19:55:09 +0100 Subject: [PATCH 3/5] traktor: implement InfoLookup for NMLLibrary NML collections only offered identifier lookups, so matching fell back to iterating every track in the calling code. find_by_info scans the collection and returns tracks whose metadata contains every supplied, non-empty field as a case-insensitive substring. Artists and albums match when any requested value is contained in any value of the track. --- plistsync/services/traktor/library.py | 36 +++++++++++++++++++++-- tests/services/traktor/test_collection.py | 32 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/plistsync/services/traktor/library.py b/plistsync/services/traktor/library.py index 9b107031..24235a66 100644 --- a/plistsync/services/traktor/library.py +++ b/plistsync/services/traktor/library.py @@ -7,7 +7,7 @@ from lxml import etree -from plistsync.core.collection import IDLookup, Library, TrackStream +from plistsync.core.collection import IDLookup, InfoLookup, Library, TrackStream from plistsync.core.ids import FilePath, PlaylistID from plistsync.logger import log @@ -24,7 +24,7 @@ from lxml.etree import _Element, _ElementTree - from plistsync.core import TrackID + from plistsync.core import TrackID, TrackInfo from .track import NMLPlaylistTrack @@ -33,6 +33,7 @@ class NMLLibrary( Library[NMLTrack, NMLPlaylist, TraktorConfig], TrackStream[NMLTrack], IDLookup[NMLTrack], + InfoLookup[NMLTrack], ): """A Traktor NML Library. @@ -237,6 +238,37 @@ def find_by_traktor_path(self, traktor_path: NMLPath) -> NMLTrack | None: """ return self._track_index().get(traktor_path) + # --------------------------- InfoLookup protocol ---------------------------- # + + def find_by_info(self, info: TrackInfo) -> Iterable[NMLTrack]: + """Find tracks by metadata, scanning the collection. + + Every supplied, non-empty field must match as a case-insensitive substring; + artists and albums match if any requested value is contained in any value of + the track. Results preserve collection order. + + TODO: make this behaviour consistent across services. + """ + title = (info.get("title") or "").casefold() + artists = {a.casefold() for a in info.get("artists") or [] if a} + albums = {a.casefold() for a in info.get("albums") or [] if a} + + if not (title or artists or albums): + return + + def matches(needles: set[str], candidates: Iterable[str]) -> bool: + folded = [c.casefold() for c in candidates] + return any(n in c for n in needles for c in folded) + + for track in self.tracks: + if title and title not in (track.title or "").casefold(): + continue + if artists and not matches(artists, track.artists): + continue + if albums and not matches(albums, track.albums): + continue + yield track + # --------------------------- TrackStream protocol --------------------------- # @property diff --git a/tests/services/traktor/test_collection.py b/tests/services/traktor/test_collection.py index 99ff631c..fb74b864 100644 --- a/tests/services/traktor/test_collection.py +++ b/tests/services/traktor/test_collection.py @@ -125,6 +125,38 @@ def test_find_by_ids(self, collection: NMLLibrary): track = collection.find_by_ids(set()) assert track is None + def test_find_by_info(self, collection: NMLLibrary): + tracks = list( + collection.find_by_info( + { + "title": "drag", + "artists": ["amos"], + "albums": ["watermark volume"], + } + ) + ) + + assert len(tracks) == 1 + assert tracks[0].title == "Dragger" + + # A single field is enough to search + assert [t.title for t in collection.find_by_info({"title": "dragger"})] == [ + "Dragger" + ] + + # But every field that is supplied has to match + assert ( + list(collection.find_by_info({"title": "Dragger", "artists": ["nope"]})) + == [] + ) + assert ( + list(collection.find_by_info({"title": "Dragger", "albums": ["nope"]})) + == [] + ) + + assert list(collection.find_by_info({"title": "not in the collection"})) == [] + assert list(collection.find_by_info({})) == [] + @pytest.mark.parametrize( [ "backup", From 26cb4ffac492dc40f28fc51930c916b852f8a0ad Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Mon, 9 Nov 2026 19:55:19 +0100 Subject: [PATCH 4/5] traktor: resolve playlist track metadata from the library NMLPlaylistTrack.info always returned an empty TrackInfo, because playlist entries only store a path while metadata lives in the main collection. Playlist tracks can now hold a reference to the owning NMLLibrary and resolve their path through it. Playlists pass their library on load, on lookup and on assignment, so tracks keep the link across playlist edits. --- plistsync/services/traktor/playlist.py | 26 +++++++--------- plistsync/services/traktor/track.py | 38 ++++++++++++++--------- tests/services/traktor/test_collection.py | 21 +++++++++++++ tests/services/traktor/test_track.py | 35 +++++++++++++++++++++ 4 files changed, 91 insertions(+), 29 deletions(-) diff --git a/plistsync/services/traktor/playlist.py b/plistsync/services/traktor/playlist.py index c860dde2..fe4cb852 100644 --- a/plistsync/services/traktor/playlist.py +++ b/plistsync/services/traktor/playlist.py @@ -9,10 +9,7 @@ from plistsync.core.collection import IDLookup from plistsync.core.ids import FilePath, PlaylistID -from plistsync.core.playlist import ( - PlaylistInfo, - ServicePlaylist, -) +from plistsync.core.playlist import PlaylistInfo, ServicePlaylist from plistsync.logger import log from .config import TraktorConfig @@ -30,9 +27,7 @@ from lxml.etree import _Element from plistsync.core import TrackID - from plistsync.core.playlist import ( - Snapshot, - ) + from plistsync.core.playlist import Snapshot from .library import NMLLibrary from .track import NMLTrack @@ -161,9 +156,9 @@ def tracks(self, value: list[NMLPlaylistTrack] | Sequence[NMLTrack]): def convert(t: NMLPlaylistTrack | NMLTrack): # convert tracks to playlist tracks if isinstance(t, NMLPlaylistTrack): - return t + return NMLPlaylistTrack(t.entry, library=self.library) else: - return NMLPlaylistTrack.from_track(t) + return NMLPlaylistTrack.from_track(t, library=self.library) self._tracks = list(map(convert, value)) @@ -210,10 +205,11 @@ def _overwrite_track_entries(self, tracks: list[NMLPlaylistTrack]) -> None: # Append new entries (avoid reusing Elements that may already have parents) for track in tracks: self.playlist_node.append( - NMLPlaylistTrack.from_traktor_path(track.traktor_path).entry + NMLPlaylistTrack.from_traktor_path( + track.traktor_path, library=self.library + ).entry ) - if self.library.find_by_traktor_path(track.traktor_path) is None: - self.library.insert_track(track) + self.library.insert_track(track) self.playlist_node.set("ENTRIES", str(len(tracks))) @@ -221,7 +217,9 @@ def _overwrite_track_entries(self, tracks: list[NMLPlaylistTrack]) -> None: def _fetch_tracks(self): entries = self.playlist_node.xpath(".//ENTRY/PRIMARYKEY[@TYPE='TRACK']/..") - self._tracks = [NMLPlaylistTrack(entry) for entry in entries] + self._tracks = [ + NMLPlaylistTrack(entry, library=self.library) for entry in entries + ] return self._tracks # --------------------------- IDLookup protocol ------------------------------ # @@ -258,4 +256,4 @@ def find_by_traktor_path(self, traktor_path: NMLPath) -> NMLPlaylistTrack | None ", using first one." ) - return NMLPlaylistTrack(entries[0]) + return NMLPlaylistTrack(entries[0], library=self.library) diff --git a/plistsync/services/traktor/track.py b/plistsync/services/traktor/track.py index b809284d..d2f47c24 100644 --- a/plistsync/services/traktor/track.py +++ b/plistsync/services/traktor/track.py @@ -127,6 +127,9 @@ class NMLPlaylistTrack(Track): but it will also remove tracks from a playlist if they are neither found on disk nor in the main collection. + To get meaningful data in NMLPlaylistTrack.info, link the track to an + NMLLibrary instance. + ``` # macOS @@ -145,8 +148,9 @@ class NMLPlaylistTrack(Track): """ entry: _Element + library: NMLLibrary | None - def __init__(self, entry: _Element): + def __init__(self, entry: _Element, library: NMLLibrary | None = None): """Initialize a NMLPlaylistTrack with an XML entry. Parameters @@ -156,28 +160,35 @@ def __init__(self, entry: _Element): """ self.entry = entry + self.library = library @classmethod - def from_traktor_path(cls, traktor_path: NMLPath) -> NMLPlaylistTrack: + def from_traktor_path( + cls, traktor_path: NMLPath, library: NMLLibrary | None = None + ) -> NMLPlaylistTrack: """Create a NMLPlaylistTrack with underlying XML Entry from a Traktor path.""" entry = Element("ENTRY") primary_key = SubElement(entry, "PRIMARYKEY") primary_key.set("TYPE", "TRACK") primary_key.set("KEY", str(traktor_path)) - return cls(entry) + return cls(entry, library=library) @classmethod - def from_path(cls, path: PurePath) -> NMLPlaylistTrack: + def from_path( + cls, path: PurePath, library: NMLLibrary | None = None + ) -> NMLPlaylistTrack: """Create a NMLPlaylistTrack with underlying XML Entry from a path. This path must be absolute and contain the volume name see also :py:func:`TraktorPath.from_path` Avoid using path.resolve(), as it might break depending on the OS. """ - return cls.from_traktor_path(NMLPath.from_path(path)) + return cls.from_traktor_path(NMLPath.from_path(path), library=library) @classmethod - def from_track(cls, track: Track) -> NMLPlaylistTrack: + def from_track( + cls, track: Track, library: NMLLibrary | None = None + ) -> NMLPlaylistTrack: """Create a NMLPlaylistTrack. Includes underlying XML Entry from any @@ -187,7 +198,7 @@ def from_track(cls, track: Track) -> NMLPlaylistTrack: raise ValueError( "Track does not have a path, cannot create NMLPlaylistTrack." ) - return cls.from_path(track.path) + return cls.from_path(track.path, library=library) def to_nml_track( self, collection: NMLLibrary, insert_if_not_found: bool = True @@ -231,11 +242,8 @@ def ids(self) -> frozenset[TrackID]: @property def info(self) -> TrackInfo: - info = TrackInfo() - - # PS 2025-08-23: - # NMLPlaylistTrack does not have metadata, only path. - # We _could_ get the data from the main collection, but since conversion - # is so easy, I dont think its worth the added complexity. - - return info + # Playlist entries only carry a path, metadata lives in the linked library. + if self.library is None: + return TrackInfo() + track = self.library.find_by_traktor_path(self.traktor_path) + return track.info if track is not None else TrackInfo() diff --git a/tests/services/traktor/test_collection.py b/tests/services/traktor/test_collection.py index fb74b864..504d7dde 100644 --- a/tests/services/traktor/test_collection.py +++ b/tests/services/traktor/test_collection.py @@ -157,6 +157,16 @@ def test_find_by_info(self, collection: NMLLibrary): assert list(collection.find_by_info({"title": "not in the collection"})) == [] assert list(collection.find_by_info({})) == [] + def test_playlist_tracks_include_library_metadata(self, collection: NMLLibrary): + playlist = collection.get_playlist_or_raise( + id="6868ecd66b354d37a33b965dae7a82e7" + ) + + track = playlist.tracks[0] + + assert track.title + assert track.artists + @pytest.mark.parametrize( [ "backup", @@ -382,6 +392,17 @@ def test_overwrite_tracks(self, track_path): p1.tracks = [NMLPlaylistTrack.from_path(track_path)] assert len(p1) == 1 + def test_overwrite_tracks_preserves_library_link(self): + """Replacing playlist tracks keeps the owning library reference.""" + p1 = self.collection.get_playlist(name=self.name) + assert p1 is not None + track = p1.tracks[0] + + with p1.edit(): + p1.tracks = [track] + + assert p1.tracks[0].library is self.collection + @pytest.mark.skipif( sys.platform == "linux", reason=""" diff --git a/tests/services/traktor/test_track.py b/tests/services/traktor/test_track.py index 8a4541b3..b0592135 100644 --- a/tests/services/traktor/test_track.py +++ b/tests/services/traktor/test_track.py @@ -7,6 +7,7 @@ from plistsync.services.traktor.track import NMLPlaylistTrack from tests.abc.tracks import TestTrack +from tests.core.mock_track import MockTrack class TestNMLTrack(TestTrack): @@ -31,6 +32,40 @@ def test_path(self): class TestNMLPlaylistTrackToNMLTrack: + def test_info_is_empty_without_library(self): + playlist_track = NMLPlaylistTrack.from_traktor_path( + NMLPath("D:/:Music/:missing.flac") + ) + + assert playlist_track.info == {} + + def test_info_uses_linked_library(self, collection): + traktor_path = NMLPath( + "D:/:SYNC/:library/:Amoss, Fre4knc/:Watermark Volume 2/" + ":04 Dragger [1028kbps].flac" + ) + playlist_track = NMLPlaylistTrack.from_traktor_path( + traktor_path, library=collection + ) + + assert playlist_track.info.get("title") == "Dragger" + + def test_info_is_empty_when_library_has_no_track(self, collection): + playlist_track = NMLPlaylistTrack.from_traktor_path( + NMLPath("D:/:Music/:missing.flac"), library=collection + ) + + assert playlist_track.info == {} + + def test_from_track_preserves_library_link(self, collection, sample_track): + playlist_track = NMLPlaylistTrack.from_track(sample_track, library=collection) + + assert playlist_track.library is collection + + def test_from_track_requires_path(self): + with pytest.raises(ValueError, match="does not have a path"): + NMLPlaylistTrack.from_track(MockTrack()) + def test_to_nml_track_returns_existing(self, collection): traktor_path = NMLPath.from_path( "D:/SYNC/library/Amoss, Fre4knc/Watermark Volume 2/04 Dragger [1028kbps].flac" From 72c53d9dce1684a1f7a8ac3c4ce245daa48b0a5c Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Mon, 9 Nov 2026 19:57:45 +0100 Subject: [PATCH 5/5] docs: note traktor metadata search - mark Traktor as supporting metadata lookups in the capability table - mention in the matching guide that the metadata search itself depends on the service, with a local collection matching substrings --- CHANGELOG.md | 1 + docs/library/guides/matching.md | 5 +++++ docs/services/index.md | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b91eb34..1647ef30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added auth providers for `Plex`, `Spotify` and `Tidal`, including a reusable `OAuth2Provider` implementing the authorization code flow with PKCE, and `Service.auth()` for resolving a service's registered provider. - Registering playlists to a synced playlists now has a `mode`, to select which source takes priority. CLI: `plistsync sync register --mode`. Supported Modes are `append|skip-duplicates|take-incoming|take-existing`. +- traktor: `NMLLibrary` now implements `InfoLookup` (`find_by_info`), allowing metadata searches; playlist tracks resolve their metadata through the linked library. File-path lookups are backed by a lazily built index. ### Changes diff --git a/docs/library/guides/matching.md b/docs/library/guides/matching.md index d8ba68e4..2c8a199d 100644 --- a/docs/library/guides/matching.md +++ b/docs/library/guides/matching.md @@ -156,6 +156,11 @@ Metadata and fuzzy matching are the fallback when no identifier produces a relia Each {class}`~plistsync.core.track.Track` exposes its metadata through the {py:attr}`~plistsync.core.track.Track.info` property. This layer is purely metadata based. +How a collection searches depends on the service: Spotify searches its own catalog, +Traktor scans its local collection and treats each supplied field as a case-insensitive +substring. See the {doc}`service overview <../../services/index>` for which services +support metadata lookups at all. + Collections without {class}`~plistsync.core.collection.IDLookup` or {class}`~plistsync.core.collection.InfoLookup` fall back to streaming every track through the same comparison, which is much slower. ```{note} diff --git a/docs/services/index.md b/docs/services/index.md index 69fbcc13..d468af52 100644 --- a/docs/services/index.md +++ b/docs/services/index.md @@ -26,7 +26,7 @@ you can check whether a service fits what you want to do before setting it up. | {doc}`Spotify ` | ✓ | ✓ | ✓ | ✓ | | {doc}`Tidal ` | ✓ | ✓ | ✓ | — | | {doc}`Plex ` | ✓ | ✓ | ✓ | — | -| {doc}`Traktor ` | — | ✓ | ✓ | — | +| {doc}`Traktor ` | — | ✓ | ✓ | ✓ | | {doc}`Local ` | — | — | ✓ | — | ```