From 1f356d66a694ba5fe68d7b38ab59fc16e6233d5a Mon Sep 17 00:00:00 2001 From: David Logie Date: Fri, 25 Jan 2019 14:06:30 +0000 Subject: [PATCH] First attempt at fixing #3132. Add a new `no_clobber` config option that contains a list of "miscellaneous" metadata fields not to be overwritten by empty values. I'm not entirely happy with the `no_clobber` name. Suggestions welcome. --- beets/autotag/__init__.py | 9 +++++++-- beets/config_default.yaml | 13 +++++++++++++ docs/changelog.rst | 3 +++ docs/reference/config.rst | 25 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 90d294c61..6783929cd 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -154,9 +154,14 @@ def apply_metadata(album_info, mapping): 'albumdisambig', 'releasegroupdisambig', 'data_source',): + # Don't overwrite fields with empty values unless the + # field is explicitly allowed to be overwritten + clobber = field not in config['no_clobber'].get() value = getattr(album_info, field) - if value is not None: - item[field] = value + if value is None and not clobber: + continue + item[field] = value + if track_info.disctitle is not None: item.disctitle = track_info.disctitle diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 26babde55..0e6e01efa 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -30,6 +30,19 @@ import: bell: no set_fields: {} +no_clobber: + - albumtype + - label + - asin + - catalognum + - script + - language + - country + - albumstatus + - albumdisambig + - releasegroupdisambig + - data_source + clutter: ["Thumbs.DB", ".DS_Store"] ignore: [".*", "*~", "System Volume Information", "lost+found"] ignore_hidden: yes diff --git a/docs/changelog.rst b/docs/changelog.rst index b896604c2..746a3f5be 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -63,6 +63,9 @@ New features: provider: you can match tracks and albums using the Spotify database. Thanks to :user:`rhlahuja`. :bug:`3123` +* A new ``no_clobber`` configuration option allows setting a list of + fields not to be overwritten by empty values upon re-importing items. + :bug:`3132` Changes: diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 57cb6c295..44f7dd576 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -303,6 +303,31 @@ The defaults look like this:: See :ref:`aunique` for more details. + +.. _no_clobber: + +no_clobber +~~~~~~~~~~ + +A list of fields that should not be overwritten by empty values when +re-importing items. + +The default is:: + + no_clobber: + - albumtype + - label + - asin + - catalognum + - script + - language + - country + - albumstatus + - albumdisambig + - releasegroupdisambig + - data_source + + .. _terminal_encoding: terminal_encoding