From aab23e6b8d31a0afb1fbb8c8e59a8d23083959da Mon Sep 17 00:00:00 2001 From: Uyanide Date: Fri, 3 Apr 2026 17:51:59 +0200 Subject: [PATCH] refactor: skip a enricher if fields it can provide are already filled --- lrx_cli/enrichers/__init__.py | 6 ++++++ lrx_cli/enrichers/audio_tag.py | 4 ++++ lrx_cli/enrichers/base.py | 4 ++++ lrx_cli/enrichers/file_name.py | 4 ++++ pyproject.toml | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lrx_cli/enrichers/__init__.py b/lrx_cli/enrichers/__init__.py index 9be0a80..562533f 100644 --- a/lrx_cli/enrichers/__init__.py +++ b/lrx_cli/enrichers/__init__.py @@ -26,6 +26,12 @@ def enrich_track(track: TrackMeta) -> TrackMeta: """ for enricher in _ENRICHERS: try: + # Skip if all provided fields are already filled + if all( + getattr(track, field, None) is not None for field in enricher.provides + ): + continue + result = enricher.enrich(track) except Exception as e: logger.warning(f"Enricher {enricher.name} failed: {e}") diff --git a/lrx_cli/enrichers/audio_tag.py b/lrx_cli/enrichers/audio_tag.py index 4e9f604..47be16f 100644 --- a/lrx_cli/enrichers/audio_tag.py +++ b/lrx_cli/enrichers/audio_tag.py @@ -20,6 +20,10 @@ class AudioTagEnricher(BaseEnricher): def name(self) -> str: return "audio-tag" + @property + def provides(self) -> set[str]: + return {"title", "artist", "album", "length"} + def enrich(self, track: TrackMeta) -> Optional[dict]: if not track.is_local or not track.url: return None diff --git a/lrx_cli/enrichers/base.py b/lrx_cli/enrichers/base.py index f0a09da..a4813e5 100644 --- a/lrx_cli/enrichers/base.py +++ b/lrx_cli/enrichers/base.py @@ -22,6 +22,10 @@ class BaseEnricher(ABC): @abstractmethod def name(self) -> str: ... + @property + @abstractmethod + def provides(self) -> set[str]: ... + @abstractmethod def enrich(self, track: TrackMeta) -> Optional[dict]: """Return a dict of {field_name: value} for fields this enricher can fill. diff --git a/lrx_cli/enrichers/file_name.py b/lrx_cli/enrichers/file_name.py index ee863b2..11f8442 100644 --- a/lrx_cli/enrichers/file_name.py +++ b/lrx_cli/enrichers/file_name.py @@ -33,6 +33,10 @@ class FileNameEnricher(BaseEnricher): def name(self) -> str: return "file-name" + @property + def provides(self) -> set[str]: + return {"artist", "title", "album"} + def enrich(self, track: TrackMeta) -> Optional[dict]: if not track.is_local or not track.url: return None diff --git a/pyproject.toml b/pyproject.toml index 8e1de1e..b906f60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "lrx-cli" -version = "0.3.4" +version = "0.3.5" description = "Fetch line-synced lyrics for your music player." readme = "README.md" requires-python = ">=3.13"