mirror of
https://github.com/beetbox/beets.git
synced 2026-01-24 17:12:07 +01:00
Adds a zero_disc_if_single_disc to the zero plugin (#6015)
Adds a `omit_single_disc` boolean configuration option to the zero plugin for writing to files. Adds the logic that, if disctotal is set and there is only one disc in disctotal, that the disc is not set. This keeps tags cleaner, only using disc on multi-disc albums. The disctotal is not touched, particularly as this is not usually displayed in most clients. The field is removed only for writing the tags, but the disc number is maintained in the database to avoid breaking anything that may depend on a disc number or avoid possible loops or failed logic. A column of disc 1 makes me feel there should be a disc 2, when most albums are a single disc only.
This commit is contained in:
commit
77842b72d7
4 changed files with 63 additions and 2 deletions
|
|
@ -41,6 +41,7 @@ class ZeroPlugin(BeetsPlugin):
|
|||
"fields": [],
|
||||
"keep_fields": [],
|
||||
"update_database": False,
|
||||
"omit_single_disc": False,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -123,9 +124,14 @@ class ZeroPlugin(BeetsPlugin):
|
|||
"""
|
||||
fields_set = False
|
||||
|
||||
if "disc" in tags and self.config["omit_single_disc"].get(bool):
|
||||
if item.disctotal == 1:
|
||||
fields_set = True
|
||||
self._log.debug("disc: {.disc} -> None", item)
|
||||
tags["disc"] = None
|
||||
|
||||
if not self.fields_to_progs:
|
||||
self._log.warning("no fields, nothing to do")
|
||||
return False
|
||||
self._log.warning("no fields list to remove")
|
||||
|
||||
for field, progs in self.fields_to_progs.items():
|
||||
if field in tags:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ Unreleased
|
|||
|
||||
New features:
|
||||
|
||||
- :doc:`plugins/zero`: Add new configuration option, ``omit_single_disc``, to
|
||||
allow zeroing the disc number on write for single-disc albums. Defaults to
|
||||
False.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
For packagers:
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ to nullify and the conditions for nullifying them:
|
|||
``keep_fields``---not both!
|
||||
- To conditionally filter a field, use ``field: [regexp, regexp]`` to specify
|
||||
regular expressions.
|
||||
- Set ``omit_single_disc`` to ``True`` to omit writing the ``disc`` number for
|
||||
albums with only a single disc (``disctotal == 1``). By default, beets will
|
||||
number the disc even if the album contains only one disc in total.
|
||||
- By default this plugin only affects files' tags; the beets database is left
|
||||
unchanged. To update the tags in the database, set the ``update_database``
|
||||
option to true.
|
||||
|
|
|
|||
|
|
@ -249,6 +249,54 @@ class ZeroPluginTest(PluginTestCase):
|
|||
|
||||
assert "id" not in z.fields_to_progs
|
||||
|
||||
def test_omit_single_disc_with_tags_single(self):
|
||||
item = self.add_item_fixture(
|
||||
disctotal=1, disc=1, comments="test comment"
|
||||
)
|
||||
item.write()
|
||||
with self.configure_plugin(
|
||||
{"omit_single_disc": True, "fields": ["comments"]}
|
||||
):
|
||||
item.write()
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
assert mf.comments is None
|
||||
assert mf.disc == 0
|
||||
|
||||
def test_omit_single_disc_with_tags_multi(self):
|
||||
item = self.add_item_fixture(
|
||||
disctotal=4, disc=1, comments="test comment"
|
||||
)
|
||||
item.write()
|
||||
with self.configure_plugin(
|
||||
{"omit_single_disc": True, "fields": ["comments"]}
|
||||
):
|
||||
item.write()
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
assert mf.comments is None
|
||||
assert mf.disc == 1
|
||||
|
||||
def test_omit_single_disc_only_change_single(self):
|
||||
item = self.add_item_fixture(disctotal=1, disc=1)
|
||||
item.write()
|
||||
|
||||
with self.configure_plugin({"omit_single_disc": True}):
|
||||
item.write()
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
assert mf.disc == 0
|
||||
|
||||
def test_omit_single_disc_only_change_multi(self):
|
||||
item = self.add_item_fixture(disctotal=4, disc=1)
|
||||
item.write()
|
||||
|
||||
with self.configure_plugin({"omit_single_disc": True}):
|
||||
item.write()
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
assert mf.disc == 1
|
||||
|
||||
def test_empty_query_n_response_no_changes(self):
|
||||
item = self.add_item_fixture(
|
||||
year=2016, day=13, month=3, comments="test comment"
|
||||
|
|
|
|||
Loading…
Reference in a new issue