Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement from_scratch option #2755

Merged
merged 1 commit into from
Dec 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beets/config_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import:
delete: no
resume: ask
incremental: no
from_scratch: no
quiet_fallback: skip
none_rec_action: ask
timid: no
Expand Down
4 changes: 4 additions & 0 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ def imported_items(self):
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):
Expand Down
5 changes: 5 additions & 0 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ def update(self, values):
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
Expand Down
4 changes: 4 additions & 0 deletions beets/ui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,10 @@ def import_func(lib, opts, args):
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'
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny typo: missing one dash in the option name.

flag to ``beet import``.

quiet_fallback
~~~~~~~~~~~~~~

Expand Down
11 changes: 11 additions & 0 deletions test/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,17 @@ def test_apply_candidate_adds_album_path(self):
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

Expand Down