diff --git a/beets/importer.py b/beets/importer.py index f8d4794c4..82f60da4b 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -275,7 +275,8 @@ class ImportConfig(object): 'quiet_fallback', 'copy', 'write', 'art', 'delete', 'choose_match_func', 'should_resume_func', 'threaded', 'autot', 'singletons', 'timid', 'choose_item_func', - 'query', 'incremental', 'ignore'] + 'query', 'incremental', 'ignore', + 'resolve_duplicate_func'] def __init__(self, **kwargs): for slot in self._fields: setattr(self, slot, kwargs[slot]) @@ -577,8 +578,7 @@ def user_query(config): # Check for duplicates if we have a match (or ASIS). if _duplicate_check(lib, task, recent): tag_log(config.logfile, 'duplicate', task.path) - log.warn("This album is already in the library!") - task.set_choice(action.SKIP) + config.resolve_duplicate_func(task, config) def show_progress(config): """This stage replaces the initial_lookup and user_query stages @@ -777,8 +777,7 @@ def item_query(config): # Duplicate check. if _item_duplicate_check(lib, task, recent): tag_log(config.logfile, 'duplicate', task.item.path) - log.warn("This item is already in the library!") - task.set_choice(action.SKIP) + config.resolve_duplicate_func(task, config) def item_progress(config): """Skips the lookup and query stages in a non-autotagged singleton diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 769966fab..9f77b5826 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -564,6 +564,14 @@ def choose_item(task, config): assert not isinstance(choice, importer.action) return choice +def resolve_duplicate(task, config): + """Decide what to do when a new album or item seems similar to one + that's already in the library. + """ + log.warn("This %s is already in the library!" % + ("album" if task.is_album else "item")) + task.set_choice(importer.action.SKIP) + # The import command. def import_files(lib, paths, copy, write, autot, logpath, art, threaded, @@ -636,6 +644,7 @@ def import_files(lib, paths, copy, write, autot, logpath, art, threaded, query = query, incremental = incremental, ignore = ignore, + resolve_duplicate_func = resolve_duplicate, ) finally: diff --git a/test/_common.py b/test/_common.py index aaccccb2f..d632df041 100644 --- a/test/_common.py +++ b/test/_common.py @@ -95,6 +95,7 @@ def iconfig(lib, **kwargs): query = None, incremental = False, ignore = [], + resolve_duplicate_func = lambda x, y: None, ) for k, v in kwargs.items(): setattr(config, k, v) diff --git a/test/test_importer.py b/test/test_importer.py index c04a12296..d4c41d0cc 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -105,6 +105,7 @@ class NonAutotaggedImportTest(unittest.TestCase): query = None, incremental = False, ignore = [], + resolve_duplicate_func = None, ) return paths