Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions beetsplug/zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ def set_fields(self, item, tags):
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")
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 2 additions & 3 deletions docs/plugins/zero.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions test/plugins/test_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def test_omit_single_disc_with_tags_single(self):

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(
Expand All @@ -271,6 +272,7 @@ def test_omit_single_disc_with_tags_multi(self):
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)
Expand All @@ -280,7 +282,8 @@ def test_omit_single_disc_only_change_single(self):
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)
Expand All @@ -291,6 +294,7 @@ def test_omit_single_disc_only_change_multi(self):

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(
Expand Down
Loading