From a73ad99dd80378e48dc9219e8ba18cc82918b218 Mon Sep 17 00:00:00 2001 From: Dixon Xavier Date: Sun, 19 Jun 2016 12:53:37 +0530 Subject: [PATCH 1/5] Add new importer configuration to deal with duplicate items --- beets/config_default.yaml | 1 + beets/importer.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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..25daefe4e 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -1327,7 +1327,24 @@ 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'].get() + log.debug(u'default action for duplicates: {0}', duplicate_action) + + if duplicate_action == 'skip': + # Skip new. + task.set_choice(action.SKIP) + elif duplicate_action == 'keep': + # Keep both. Do nothing; leave the choice intact. + pass + elif duplicate_action == 'remove': + # 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) From fbcc8dbf1ec4e6354e5b75214126da924f8edc0c Mon Sep 17 00:00:00 2001 From: Dixon Xavier Date: Sun, 19 Jun 2016 12:54:27 +0530 Subject: [PATCH 2/5] Update changelog and documentation --- docs/changelog.rst | 2 ++ docs/reference/config.rst | 11 +++++++++++ 2 files changed, 13 insertions(+) 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..11310ac0c 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: From 80ca527f76d75aa549b3e2f6654fec65de1fdd3f Mon Sep 17 00:00:00 2001 From: Dixon Xavier Date: Sun, 19 Jun 2016 13:20:54 +0530 Subject: [PATCH 3/5] Fix typo in documentation --- docs/reference/config.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 11310ac0c..0892aaa30 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -550,7 +550,7 @@ with the ``-a`` flag to the :ref:`import-cmd` command.) Default: ``yes``. -.. _duplicate_action +.. _duplicate_action: duplicate_action ~~~~~~~~~~~~~~~~ From 366a6d7fb29708e7380a500ceff4af1b79af997d Mon Sep 17 00:00:00 2001 From: Dixon Xavier Date: Mon, 20 Jun 2016 00:35:47 +0530 Subject: [PATCH 4/5] add validation for configuration --- beets/importer.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index 25daefe4e..120a3ddb8 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -1329,16 +1329,21 @@ def resolve_duplicates(session, task): )) # Get the default action to follow from config. - duplicate_action = config['import']['duplicate_action'].get() + 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 == 'skip': + if duplicate_action == u's': # Skip new. task.set_choice(action.SKIP) - elif duplicate_action == 'keep': + elif duplicate_action == u'k': # Keep both. Do nothing; leave the choice intact. pass - elif duplicate_action == 'remove': + elif duplicate_action == u'r': # Remove old. task.should_remove_duplicates = True else: From 4d75d4c06326f8e3a83bf75f5fb8c51f34b40b34 Mon Sep 17 00:00:00 2001 From: Dixon Xavier Date: Mon, 20 Jun 2016 00:52:09 +0530 Subject: [PATCH 5/5] Fix lint error --- beets/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/importer.py b/beets/importer.py index 120a3ddb8..60aeb2f2b 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -1333,7 +1333,7 @@ def resolve_duplicates(session, task): u'skip': u's', u'keep': u'k', u'remove': u'r', - u'ask' : u'a', + u'ask': u'a', }) log.debug(u'default action for duplicates: {0}', duplicate_action)