From 372b9bc60fedb2edcfbd2986a9e8a92cdeac20c0 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 9 Aug 2026 11:56:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=96=87=E4=BB=B6=E6=A0=87=E7=AD=BE=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E6=9B=B2=E7=9B=AE=E6=A0=87=E9=A2=98=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=87=8D=E5=90=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 12 ++++-------- tests/test_music_transfer.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 6c271f859..8cb09a552 100755 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -1084,12 +1084,10 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton): file_meta = deepcopy(saved_meta) file_meta.org_string = file_path.name if file_tags: - has_tag_identity = bool( - file_tags.artists - or file_tags.album - or file_tags.track_number - or file_tags.isrc - ) + # 曲目标题始终优先使用当前文件自身的标签(缺失时回退为文件名), + # 防止整包目录继续沿用订阅/下载标题(单曲名、专辑名等)导致所有文件重名。 + if file_tags.title: + file_meta.title = file_tags.title for field_name in ( "artists", "album", @@ -1104,8 +1102,6 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton): ): if getattr(file_tags, field_name, None): setattr(file_meta, field_name, deepcopy(getattr(file_tags, field_name))) - if has_tag_identity and file_tags.title: - file_meta.title = file_tags.title for field_name in ( "audio_format", "bit_depth", diff --git a/tests/test_music_transfer.py b/tests/test_music_transfer.py index c21019986..99becd04f 100644 --- a/tests/test_music_transfer.py +++ b/tests/test_music_transfer.py @@ -94,6 +94,36 @@ def test_restore_music_context_from_download_history(): assert restored_info.album == "Random Access Memories" +def test_restore_music_context_uses_file_title_over_subscription_title(tmp_path, monkeypatch): + """曲目标题应优先取当前文件自身的标签/文件名,而非沿用订阅时的单曲标题。""" + meta, info = _music_context() + history = SimpleNamespace( + note={ + "music": { + "version": 1, + "meta": meta.to_dict(), + "media": info.to_dict(), + } + } + ) + # 订阅标题被识别为单曲"Get Lucky",而实际音轨标签曲目名 不同且无身份字段 + audio_file = tmp_path / "07.幸福.flac" + audio_file.write_bytes(b"fake-flac") + + from app.helper.audio import AudioMetadataHelper + + monkeypatch.setattr( + AudioMetadataHelper, + "read", + lambda path: MetaMusic(org_string=path.name, title="流浪地图"), + ) + + restored_meta, _ = TransferChain._restore_music_download_context(history, audio_file) + + assert restored_meta is not None + assert restored_meta.title == "流浪地图" + + def test_job_manager_serializes_music_queue_models(): """整理队列应使用音乐专属 Schema 序列化任务。""" meta, info = _music_context()