diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 9870f157f..ba657cedb 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -462,7 +462,7 @@ def tag_item(item, search_artist=None, search_title=None, candidates = {} # First, try matching by MusicBrainz ID. - trackids = search_ids or filter(None, [item.mb_trackid]) + trackids = search_ids or [t for t in [item.mb_trackid] if t] if trackids: for trackid in trackids: log.debug(u'Searching for track ID: {0}', trackid) diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 4c12c3df0..fa77a82dc 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -23,6 +23,7 @@ import: group_albums: no pretend: false search_ids: [] + duplicate_action: ask clutter: ["Thumbs.DB", ".DS_Store"] ignore: [".*", "*~", "System Volume Information", "lost+found"] diff --git a/beets/importer.py b/beets/importer.py index 4209a4831..072c2ad5b 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -331,7 +331,7 @@ class ImportSession(object): been imported in a previous session. """ if self.is_resuming(toppath) \ - and all(map(lambda p: progress_element(toppath, p), paths)): + and all([progress_element(toppath, p) for p in paths]): return True if self.config['incremental'] \ and tuple(paths) in self.history_dirs: @@ -1327,7 +1327,29 @@ def resolve_duplicates(session, task): log.debug(u'found duplicates: {}'.format( [o.id for o in found_duplicates] )) - session.resolve_duplicate(task, found_duplicates) + + # Get the default action to follow from config. + duplicate_action = config['import']['duplicate_action'].as_choice({ + u'skip': u's', + u'keep': u'k', + u'remove': u'r', + u'ask': u'a', + }) + log.debug(u'default action for duplicates: {0}', duplicate_action) + + if duplicate_action == u's': + # Skip new. + task.set_choice(action.SKIP) + elif duplicate_action == u'k': + # Keep both. Do nothing; leave the choice intact. + pass + elif duplicate_action == u'r': + # Remove old. + task.should_remove_duplicates = True + else: + # No default action set; ask the session. + session.resolve_duplicate(task, found_duplicates) + session.log_choice(task, True) diff --git a/beetsplug/info.py b/beetsplug/info.py index 29bff7a29..d29d9b45f 100644 --- a/beetsplug/info.py +++ b/beetsplug/info.py @@ -230,7 +230,7 @@ def make_key_filter(include): def filter_(data): filtered = dict() for key, value in data.items(): - if any(map(lambda m: m.match(key), matchers)): + if any([m.match(key) for m in matchers]): filtered[key] = value return filtered diff --git a/docs/changelog.rst b/docs/changelog.rst index 64b582450..b350381af 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,8 @@ New features: * A new ``--force`` option for :ref:`remove-cmd` allows removal of items without prompting beforehand. :bug:`2042` +* A new importer configuration :ref:`duplicate_action` controls how + duplicate albums or tracks treated in import task. :bug:`185` Some fixes for Windows: diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 4ca54652a..0892aaa30 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -550,6 +550,17 @@ with the ``-a`` flag to the :ref:`import-cmd` command.) Default: ``yes``. +.. _duplicate_action: + +duplicate_action +~~~~~~~~~~~~~~~~ + +Either ``skip``, ``keep``, ``remove``, or ``ask``. Controls how duplicates +are treated in import task. "skip" means that new item(album or track) will be +skiped; "keep" means keep both old and new items; "remove" means remove old +item; "ask" means the user should be prompted for the action each time. +The default is ``ask``. + .. _musicbrainz-config: