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.
This commit is contained in:
rdy2go 2025-06-21 00:01:01 +02:00
parent 8fd20b9b67
commit f51559e16f
3 changed files with 16 additions and 0 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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()