From c9b4e9b414673ec41de93e4bd70a6bfb0569b73c Mon Sep 17 00:00:00 2001 From: Constantine Evans Date: Sun, 10 Dec 2017 12:28:47 -0800 Subject: [PATCH 1/2] only use tiebreak if tiebreak includes an entry for the kind being considered, otherwise use default (eg, if only items is specified, and -a is being used, use default order of priority --- beetsplug/duplicates.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/beetsplug/duplicates.py b/beetsplug/duplicates.py index 2584e6628..6913aaef6 100644 --- a/beetsplug/duplicates.py +++ b/beetsplug/duplicates.py @@ -253,13 +253,12 @@ class DuplicatesPlugin(BeetsPlugin): "completeness" (objects with more non-null fields come first) and Albums are ordered by their track count. """ - if tiebreak: - kind = 'items' if all(isinstance(o, Item) - for o in objs) else 'albums' + kind = 'items' if all(isinstance(o, Item) for o in objs) else 'albums' + + if tiebreak and kind in tiebreak.keys(): key = lambda x: tuple(getattr(x, k) for k in tiebreak[kind]) else: - kind = Item if all(isinstance(o, Item) for o in objs) else Album - if kind is Item: + if kind is 'items': def truthy(v): # Avoid a Unicode warning by avoiding comparison # between a bytes object and the empty Unicode From dd2b44ef20fd089fb0961a77e913ed6c033b387a Mon Sep 17 00:00:00 2001 From: Constantine Evans Date: Mon, 11 Dec 2017 13:31:40 -0800 Subject: [PATCH 2/2] minor fixes and changelog entry --- beetsplug/duplicates.py | 4 ++-- docs/changelog.rst | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/beetsplug/duplicates.py b/beetsplug/duplicates.py index 6913aaef6..b316cfda6 100644 --- a/beetsplug/duplicates.py +++ b/beetsplug/duplicates.py @@ -258,14 +258,14 @@ class DuplicatesPlugin(BeetsPlugin): if tiebreak and kind in tiebreak.keys(): key = lambda x: tuple(getattr(x, k) for k in tiebreak[kind]) else: - if kind is 'items': + if kind == 'items': def truthy(v): # Avoid a Unicode warning by avoiding comparison # between a bytes object and the empty Unicode # string ''. return v is not None and \ (v != '' if isinstance(v, six.text_type) else True) - fields = kind.all_keys() + fields = Item.all_keys() key = lambda x: sum(1 for f in fields if truthy(getattr(x, f))) else: key = lambda x: len(x.items()) diff --git a/docs/changelog.rst b/docs/changelog.rst index edeaf8140..8752ff910 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -70,6 +70,8 @@ Fixes: Python 3 on Windows with non-ASCII filenames. :bug:`2671` * :doc:`/plugins/absubmit`: Fix an occasional crash on Python 3 when the AB analysis tool produced non-ASCII metadata. :bug:`2673` +* :doc:`/plugins/duplicates`: Use default tiebreak for any kind (item/album) that + does not have a tiebreak specified in the configuration. * :doc:`/plugins/duplicates`: Fix the `--key` command line option, which was ignored. * :doc:`/plugins/replaygain`: Fix album replaygain calculation with the