zero plugin zeroes disctotal if single disc (#6306)

When `omit_single_disc` is set, `disctotal` is now also zeroed alongside
`disc`. These tags work together ("Disc 2 of 3") so keeping one without
the other is inconsistent.

Previously, only the `disc` tag was zeroed. This follows from #6015
which made it into v2.5.1 and added the `omit_single_disc` option.

I've added tests and have used this locally for some time.
This commit is contained in:
Šarūnas Nejus 2026-03-02 17:02:22 +00:00 committed by GitHub
commit 30d5157ba3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 10 deletions

View file

@ -123,12 +123,10 @@ class ZeroPlugin(BeetsPlugin):
config.
"""
fields_set = False
if "disc" in tags and self.config["omit_single_disc"].get(bool):
if item.disctotal == 1:
if self.config["omit_single_disc"].get(bool) and item.disctotal == 1:
for tag in {"disc", "disctotal"} & set(tags):
tags[tag] = None
fields_set = True
self._log.debug("disc: {.disc} -> None", item)
tags["disc"] = None
if not self.fields_to_progs:
self._log.warning("no fields list to remove")

View file

@ -41,6 +41,8 @@ Bug fixes
- :doc:`plugins/ftintitle`: Fix handling of multiple featured artists with
ampersand.
- :doc:`plugins/zero`: When the ``omit_single_disc`` option is set,
``disctotal`` is zeroed alongside ``disc``.
For plugin developers
~~~~~~~~~~~~~~~~~~~~~

View file

@ -31,9 +31,8 @@ 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.
- Set ``omit_single_disc`` to ``True`` to omit writing the ``disc`` number and
the ``disctotal`` number for albums with a single disc (``disctotal == 1``).
- 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.

View file

@ -256,7 +256,8 @@ class ZeroPluginTest(IOMixin, PluginTestCase):
mf = MediaFile(syspath(item.path))
assert mf.comments is None
assert mf.disc == 0
assert mf.disc is None
assert mf.disctotal is None
def test_omit_single_disc_with_tags_multi(self):
item = self.add_item_fixture(
@ -271,6 +272,7 @@ class ZeroPluginTest(IOMixin, PluginTestCase):
mf = MediaFile(syspath(item.path))
assert mf.comments is None
assert mf.disc == 1
assert mf.disctotal == 4
def test_omit_single_disc_only_change_single(self):
item = self.add_item_fixture(disctotal=1, disc=1)
@ -280,7 +282,8 @@ class ZeroPluginTest(IOMixin, PluginTestCase):
item.write()
mf = MediaFile(syspath(item.path))
assert mf.disc == 0
assert mf.disc is None
assert mf.disctotal is None
def test_omit_single_disc_only_change_multi(self):
item = self.add_item_fixture(disctotal=4, disc=1)
@ -291,6 +294,7 @@ class ZeroPluginTest(IOMixin, PluginTestCase):
mf = MediaFile(syspath(item.path))
assert mf.disc == 1
assert mf.disctotal == 4
def test_empty_query_n_response_no_changes(self):
item = self.add_item_fixture(