Skip to content

Adds a zero_disc_number_if_single_disc to the zero plugin #5909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 7 additions & 1 deletion beetsplug/zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self):
"fields": [],
"keep_fields": [],
"update_database": False,
"zero_disc_number_if_single_disc": False
}
)

Expand Down Expand Up @@ -123,8 +124,13 @@ def set_fields(self, item, tags):
"""
fields_set = False

if 'disc' in tags and self.config["zero_disc_number_if_single_disc"].get(bool):
if getattr(item, 'disctotal', None) == 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can access this attribute directly

Suggested change
if getattr(item, 'disctotal', None) == 1:
if item.disctotal == 1:

self._log.debug("{0}: {1} -> None", 'disc', item['disc'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._log.debug("{0}: {1} -> None", 'disc', item['disc'])
self._log.debug("disc: {.disc} -> None", item)

tags['disc'] = None

if not self.fields_to_progs:
self._log.warning("no fields, nothing to do")
self._log.warning("no fields list to remove")
return False

for field, progs in self.fields_to_progs.items():
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ New features:
* :doc:`plugins/mpdstats`: Add new configuration option,
``played_ratio_threshold``, to allow configuring the percentage the song must
be played for it to be counted as played instead of skipped.
* :doc:`plugins/zero`: Add new configuration option,
``zero_disc_number_if_single_disc``, to allow zeroing the disc number on
write for single-disc albums. Defaults to False.

Bug fixes:

Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/zero.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ fields to nullify and the conditions for nullifying them:
``fields`` or ``keep_fields``---not both!
* To conditionally filter a field, use ``field: [regexp, regexp]`` to specify
regular expressions.
* Set ``zero_disc_number_if_single_disc`` to True to zero the disc number
field only if the album contains a disctotal count and is a single disc
* 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
Loading