From f51559e16fef413f34b1e591c88512ef224c9cc1 Mon Sep 17 00:00:00 2001 From: rdy2go <47011689+rdy2go@users.noreply.github.com> Date: Sat, 21 Jun 2025 00:01:01 +0200 Subject: [PATCH] Fix 'from_scratch': delete all tags before writing new tags to file ## Github Issues Fixes #3706 Related #5165 ## Issue Comment tags are written to file even if option 'from_scratch' is used. The same tags are not written to the file if imported together with other files as album. Therefore 'from_scratch' is not working as described in the documentation. ## Solution 1. Add test: Adapt the function from the 'regular' import class and insert it in the class for the singleton import test. 2. Fix bug : Add check for 'from_scratch' option. If used, clear metadata before applying 'new' metadata with autotag. 3. No documentation change needed. Option now works as described in the documentation. 4. Add changelog. --- beets/importer/tasks.py | 2 ++ docs/changelog.rst | 3 +++ test/test_importer.py | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/beets/importer/tasks.py b/beets/importer/tasks.py index 75f04cf5a..4aa1f8a62 100644 --- a/beets/importer/tasks.py +++ b/beets/importer/tasks.py @@ -690,6 +690,8 @@ class SingletonImportTask(ImportTask): return [self.item] def apply_metadata(self): + if config["import"]["from_scratch"]: + self.item.clear() autotag.apply_item_metadata(self.item, self.match.info) def _emit_imported(self, lib): diff --git a/docs/changelog.rst b/docs/changelog.rst index 88b82e4da..bf830bade 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -39,6 +39,9 @@ Bug fixes: :bug:`5797` * :doc:`plugins/musicbrainz`: Fix the MusicBrainz search not taking into account the album/recording aliases +* :doc:`reference/cli`: Fix 'from_scratch' option for singleton imports: delete + all (old) metadata when new metadata is applied. + :bug:`3706` For packagers: diff --git a/test/test_importer.py b/test/test_importer.py index 9bb0e8a63..2fa5b32d3 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -315,6 +315,17 @@ class ImportSingletonTest(AutotagImportTestCase): self.importer.run() self.assert_file_in_lib(b"singletons", b"Applied Track 1.mp3") + def test_apply_from_scratch_removes_other_metadata(self): + config["import"]["from_scratch"] = True + + for mediafile in self.import_media: + mediafile.comments = "Tag Comment" + mediafile.save() + + self.importer.add_choice(importer.Action.APPLY) + self.importer.run() + assert self.lib.items().get().comments == "" + def test_skip_does_not_add_first_track(self): self.importer.add_choice(importer.Action.SKIP) self.importer.run()