Skip to content

Commit 679cfc9

Browse files
authored
Fix 'from_scratch': delete all tags before writing new tags to file (#5828)
Fixes #3706. ### 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.
2 parents b3c42a3 + fdfeb35 commit 679cfc9

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

beets/importer/tasks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ def imported_items(self):
680680
return [self.item]
681681

682682
def apply_metadata(self):
683+
if config["import"]["from_scratch"]:
684+
self.item.clear()
683685
autotag.apply_item_metadata(self.item, self.match.info)
684686

685687
def _emit_imported(self, lib):

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ Bug fixes:
9090
- :doc:`/plugins/ftintitle`: Fixed artist name splitting to prioritize explicit
9191
featuring tokens (feat, ft, featuring) over generic separators (&, and),
9292
preventing incorrect splits when both are present.
93+
- :doc:`reference/cli`: Fix 'from_scratch' option for singleton imports: delete
94+
all (old) metadata when new metadata is applied. :bug:`3706`
9395

9496
For plugin developers:
9597

test/test_importer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ def test_apply_candidate_adds_track(self):
258258
assert self.lib.items().get().title == "Applied Track 1"
259259
assert (self.lib_path / "singletons" / "Applied Track 1.mp3").exists()
260260

261+
def test_apply_from_scratch_removes_other_metadata(self):
262+
config["import"]["from_scratch"] = True
263+
264+
for mediafile in self.import_media:
265+
mediafile.comments = "Tag Comment"
266+
mediafile.save()
267+
268+
self.importer.add_choice(importer.Action.APPLY)
269+
self.importer.run()
270+
assert self.lib.items().get().comments == ""
271+
261272
def test_skip_does_not_add_track(self):
262273
self.importer.add_choice(importer.Action.SKIP)
263274
self.importer.run()

0 commit comments

Comments
 (0)