Thread runtime through metadata enrichment

- Pass the live runtime bundle into the shared metadata facade so worker-backed source enrichment can actually run.
- Forward runtime from the import pipeline and web-server wrapper into embed_source_ids.
- Add a regression test that verifies the runtime object reaches the source-ID embedding path.
pull/378/head
Antti Kettunen 1 month ago
parent 8319c6679f
commit 9656dbd46a
No known key found for this signature in database
GPG Key ID: C6B2A3D250359BD7

@ -364,7 +364,7 @@ def post_process_matched_download(context_key, context, file_path, runtime):
f"[Metadata Input] Playlist mode - artist: '{artist_context.get('name', 'MISSING')}' "
f"(id: {artist_context.get('id', 'MISSING')})"
)
enhance_file_metadata(file_path, context, artist_context, None)
enhance_file_metadata(file_path, context, artist_context, None, runtime=runtime)
except Exception as meta_err:
import traceback
pp_logger.info(f"[inner] Metadata enhancement FAILED for {context_key}: {meta_err}\n{traceback.format_exc()}")
@ -529,7 +529,7 @@ def post_process_matched_download(context_key, context, file_path, runtime):
)
else:
logger.info("[Metadata Input] album_info: None (single track)")
enhance_file_metadata(file_path, context, artist_context, album_info)
enhance_file_metadata(file_path, context, artist_context, album_info, runtime=runtime)
except Exception as meta_err:
import traceback
pp_logger.info(f"[inner] Metadata enhancement FAILED for {context_key}: {meta_err}\n{traceback.format_exc()}")

@ -25,7 +25,7 @@ __all__ = [
]
def enhance_file_metadata(file_path: str, context: dict, artist: dict, album_info: dict) -> bool:
def enhance_file_metadata(file_path: str, context: dict, artist: dict, album_info: dict, runtime=None) -> bool:
cfg = get_config_manager()
logger_ = get_logger()
if cfg.get("metadata_enhancement.enabled", True) is False:
@ -126,7 +126,7 @@ def enhance_file_metadata(file_path: str, context: dict, artist: dict, album_inf
if metadata.get("disc_number"):
audio_file["disk"] = [(metadata["disc_number"], 0)]
embed_source_ids(audio_file, metadata, context)
embed_source_ids(audio_file, metadata, context, runtime=runtime)
if album_info is not None and metadata.get("musicbrainz_release_id"):
album_info["musicbrainz_release_id"] = metadata["musicbrainz_release_id"]

File diff suppressed because it is too large Load Diff

@ -208,6 +208,60 @@ def test_embed_source_ids_uses_current_source_ids_and_legacy_fallback(monkeypatc
assert "ITUNES_ALBUM_ID" in legacy_descs
def test_enhance_file_metadata_forwards_runtime_to_source_embedding(monkeypatch):
audio = _FakeAudio()
symbols = _fake_symbols(audio)
seen = {}
runtime = types.SimpleNamespace(marker="runtime")
monkeypatch.setattr(me, "get_config_manager", lambda: _Config(
{
"metadata_enhancement.enabled": True,
"metadata_enhancement.embed_album_art": False,
"metadata_enhancement.tags.write_multi_artist": False,
}
))
monkeypatch.setattr(me, "get_mutagen_symbols", lambda: symbols)
monkeypatch.setattr(me, "strip_all_non_audio_tags", lambda file_path: {"apev2_stripped": False, "apev2_tag_count": 0})
monkeypatch.setattr(
me,
"extract_source_metadata",
lambda context, artist, album_info: {
"source": "deezer",
"source_track_id": "dz-track",
"source_artist_id": "dz-artist",
"source_album_id": "dz-album",
"title": "Song One",
"artist": "Artist One",
"album_artist": "Artist One",
"album": "Album One",
"track_number": 3,
"total_tracks": 12,
"disc_number": 2,
"date": "2024",
"genre": "Rock",
},
)
monkeypatch.setattr(
me,
"embed_source_ids",
lambda audio_file, metadata, context, runtime=None: seen.setdefault("runtime", runtime),
)
monkeypatch.setattr(me, "embed_album_art_metadata", lambda *args, **kwargs: None)
monkeypatch.setattr(me, "verify_metadata_written", lambda file_path: True)
result = me.enhance_file_metadata(
"song.flac",
{"_audio_quality": ""},
{"name": "Artist One"},
{},
runtime=runtime,
)
assert result is True
assert seen["runtime"] is runtime
def test_enhance_file_metadata_writes_tags_and_propagates_release_id(monkeypatch):
audio = _FakeAudio()
symbols = _fake_symbols(audio)

@ -19678,8 +19678,14 @@ import urllib.request
def _wipe_source_tags(file_path: str) -> bool:
return metadata_enrichment.wipe_source_tags(file_path)
def _enhance_file_metadata(file_path: str, context: dict, artist: dict, album_info: dict) -> bool:
return metadata_enrichment.enhance_file_metadata(file_path, context, artist, album_info)
def _enhance_file_metadata(file_path: str, context: dict, artist: dict, album_info: dict, runtime=None) -> bool:
return metadata_enrichment.enhance_file_metadata(
file_path,
context,
artist,
album_info,
runtime=runtime or _build_import_pipeline_runtime(),
)
def _download_cover_art(album_info: dict, target_dir: str, context: dict = None):
@ -19781,6 +19787,15 @@ def _build_import_pipeline_runtime():
on_download_completed=_on_download_completed,
web_scan_manager=web_scan_manager,
repair_worker=repair_worker,
mb_worker=mb_worker,
deezer_worker=deezer_worker,
audiodb_worker=audiodb_worker,
tidal_client=tidal_client,
qobuz_enrichment_worker=qobuz_enrichment_worker,
lastfm_worker=lastfm_worker,
genius_worker=genius_worker,
spotify_enrichment_worker=spotify_enrichment_worker,
itunes_enrichment_worker=itunes_enrichment_worker,
)
@ -19897,18 +19912,28 @@ def _build_import_pipeline_runtime():
on_download_completed=_on_download_completed,
web_scan_manager=web_scan_manager,
repair_worker=repair_worker,
mb_worker=mb_worker,
deezer_worker=deezer_worker,
audiodb_worker=audiodb_worker,
tidal_client=tidal_client,
qobuz_enrichment_worker=qobuz_enrichment_worker,
lastfm_worker=lastfm_worker,
genius_worker=genius_worker,
spotify_enrichment_worker=spotify_enrichment_worker,
itunes_enrichment_worker=itunes_enrichment_worker,
)
def _wipe_source_tags(file_path: str) -> bool:
return metadata_enrichment.wipe_source_tags(file_path)
def _enhance_file_metadata(file_path: str, context: dict, artist: dict, album_info: dict) -> bool:
def _enhance_file_metadata(file_path: str, context: dict, artist: dict, album_info: dict, runtime=None) -> bool:
return metadata_enrichment.enhance_file_metadata(
file_path,
context,
artist,
album_info,
runtime=runtime or _build_import_pipeline_runtime(),
)

Loading…
Cancel
Save