Implement from_scratch option

Fixes #934, and also helps with #1173.
This commit is contained in:
tummychow 2017-12-07 14:46:40 -05:00
parent d932aa4f5c
commit e848adab04
7 changed files with 40 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import:
delete: no
resume: ask
incremental: no
from_scratch: no
quiet_fallback: skip
none_rec_action: ask
timid: no

View file

@ -534,6 +534,10 @@ class ImportTask(BaseImportTask):
def apply_metadata(self):
"""Copy metadata from match info to the items.
"""
if config['import']['from_scratch']:
for item in self.match.mapping:
item.clear()
autotag.apply_metadata(self.match.info, self.match.mapping)
def duplicate_items(self, lib):

View file

@ -561,6 +561,11 @@ class Item(LibModel):
if self.mtime == 0 and 'mtime' in values:
self.mtime = values['mtime']
def clear(self):
"""Set all key/value pairs to None."""
for key in self._media_fields:
setattr(self, key, None)
def get_album(self):
"""Get the Album object that this item belongs to, if any, or
None if the item is a singleton or is not associated with a

View file

@ -1004,6 +1004,10 @@ import_cmd.parser.add_option(
u'-I', u'--noincremental', dest='incremental', action='store_false',
help=u'do not skip already-imported directories'
)
import_cmd.parser.add_option(
u'--from-scratch', dest='from_scratch', action='store_true',
help=u'erase existing metadata before applying new metadata'
)
import_cmd.parser.add_option(
u'--flat', dest='flat', action='store_true',
help=u'import an entire tree as a single album'

View file

@ -111,6 +111,12 @@ Optional command flags:
time, when no subdirectories will be skipped. So consider enabling the
``incremental`` configuration option.
* When beets applies metadata to your music, it will retain the value of any
existing tags that weren't overwritten, and import them into the database. You
may prefer to only use existing metadata for finding matches, and to erase it
completely when new metadata is applied. You can enforce this behavior with
the ``--from-scratch`` option, or the ``from_scratch`` configuration option.
* By default, beets will proceed without asking if it finds a very close
metadata match. To disable this and have the importer ask you every time,
use the ``-t`` (for *timid*) option.

View file

@ -475,6 +475,15 @@ Either ``yes`` or ``no``, controlling whether imported directories are
recorded and whether these recorded directories are skipped. This
corresponds to the ``-i`` flag to ``beet import``.
.. _from_scratch:
from_scratch
~~~~~~~~~~~~
Either ``yes`` or ``no`` (default), controlling whether existing metadata is
discarded when a match is applied. This corresponds to the ``-from_scratch``
flag to ``beet import``.
quiet_fallback
~~~~~~~~~~~~~~

View file

@ -633,6 +633,17 @@ class ImportTest(_common.TestCase, ImportHelper):
self.assert_file_in_lib(
b'Applied Artist', b'Applied Album', b'Applied Title 1.mp3')
def test_apply_from_scratch_removes_other_metadata(self):
config['import']['from_scratch'] = True
for mediafile in self.import_media:
mediafile.genre = u'Tag Genre'
mediafile.save()
self.importer.add_choice(importer.action.APPLY)
self.importer.run()
self.assertEqual(self.lib.items().get().genre, u'')
def test_apply_with_move_deletes_import(self):
config['import']['move'] = True