From 1f4e8e5e3b0a4d5fab47d1d3bc08abc5caf9aea3 Mon Sep 17 00:00:00 2001 From: elmerohueso Date: Fri, 1 May 2026 19:36:36 -0600 Subject: [PATCH] get hifi tags during download, without needing to go through the enrichment pipeline --- core/hifi_client.py | 9 +++++++++ core/metadata/source.py | 18 ++++++++++++++++++ core/soulseek_client.py | 1 + 3 files changed, 28 insertions(+) diff --git a/core/hifi_client.py b/core/hifi_client.py index 3c9dbf2a..c1209716 100644 --- a/core/hifi_client.py +++ b/core/hifi_client.py @@ -559,6 +559,15 @@ class HiFiClient: title=track.get('title'), album=track.get('album'), track_number=track.get('track_number'), + _source_metadata={ + 'source': 'hifi', + 'track_id': track.get('id'), + 'artist_id': track.get('artist_id'), + 'album_id': track.get('album_id'), + 'isrc': track.get('isrc'), + 'bpm': track.get('bpm'), + 'copyright': track.get('copyright'), + }, ) async def download(self, username: str, filename: str, file_size: int = 0) -> Optional[str]: diff --git a/core/metadata/source.py b/core/metadata/source.py index f0772755..a679995e 100644 --- a/core/metadata/source.py +++ b/core/metadata/source.py @@ -1045,6 +1045,24 @@ def embed_source_ids(audio_file, metadata: dict, context: dict = None, runtime=N if not isinstance(source_order, list) or not source_order: source_order = DEFAULT_SOURCE_ORDER + # If this download came from HiFi, use cached metadata from the download + # pipeline instead of re-searching the HiFi API. + original_search = get_import_original_search(context) + cached_meta = original_search.get("_source_metadata") or {} + if cached_meta.get("source") == "hifi": + if _tag_enabled(cfg, "hifi.embed_tags"): + if cfg.get("hifi.tags.track_id", True) and cached_meta.get("track_id"): + pp["id_tags"]["HIFI_TRACK_ID"] = str(cached_meta["track_id"]) + if cfg.get("hifi.tags.artist_id", True) and cached_meta.get("artist_id"): + pp["id_tags"]["HIFI_ARTIST_ID"] = str(cached_meta["artist_id"]) + if cfg.get("hifi.tags.isrc", True) and cached_meta.get("isrc"): + pp["hifi_isrc"] = cached_meta["isrc"] + if cfg.get("hifi.tags.bpm", True) and cached_meta.get("bpm"): + pp["hifi_bpm"] = cached_meta["bpm"] + if cfg.get("hifi.tags.copyright", True) and cached_meta.get("copyright"): + pp["hifi_copyright"] = cached_meta["copyright"] + source_order = [s for s in source_order if s != "hifi"] + db = get_database() for source_name in source_order: diff --git a/core/soulseek_client.py b/core/soulseek_client.py index 3110c305..e69c9439 100644 --- a/core/soulseek_client.py +++ b/core/soulseek_client.py @@ -79,6 +79,7 @@ class TrackResult(SearchResult): title: Optional[str] = None album: Optional[str] = None track_number: Optional[int] = None + _source_metadata: Optional[Dict[str, Any]] = None def __post_init__(self): self.result_type = "track"