Skip to content

Conversation

michaelkrieger
Copy link

@michaelkrieger michaelkrieger commented Sep 15, 2025

Adds a zero_disc_if_single_disc boolean 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.

NOTE: This was originally at #5909 but I managed to screw up the source/patch repo while trying to bring things up to date with master, so I just recreated the final version of it. I've also changed the parameter to remove the 'number' which I'm told won't always translate well (and technically the disc could be a letter such as 'A').

Description

This addresses concerns such as https://beets-users.narkive.com/fxh0cgmC/beets-remove-disc-field-for-single-disc-albums and accomplishes things like #5670 but in tags instead of just in the path.

To Do

  • Tests. (Very much encouraged but not strictly required.)

Summary by Sourcery

Introduce a zero_disc_if_single_disc configuration to the zero plugin, skipping the disc tag on single-disc albums when writing tags.

New Features:

  • Add zero_disc_if_single_disc boolean option to the zero plugin to omit the disc tag when only one disc is present.

Documentation:

  • Update plugin documentation and changelog to describe the zero_disc_if_single_disc option.

Summary by Sourcery

Add an option to the zero plugin that omits the disc tag when only one disc is present, keeping tags lean for single-disc albums.

New Features:

  • Introduce zero_disc_if_single_disc configuration to skip writing the disc tag on single-disc albums.

Documentation:

  • Update plugin documentation and changelog to describe the zero_disc_if_single_disc option.

Adds a zero_disc_number_if_single_disc boolean 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.
@michaelkrieger michaelkrieger requested a review from a team as a code owner September 15, 2025 22:51
Copy link
Contributor

sourcery-ai bot commented Sep 15, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduce a zero_disc_if_single_disc option in the zero plugin that omits the disc tag for single-disc albums during tag writing.

Sequence diagram for omitting disc tag on single-disc albums during tag writing

sequenceDiagram
    participant ZeroPlugin
    participant Item
    participant Tags
    ZeroPlugin->>Item: Check item.disctotal
    alt zero_disc_if_single_disc enabled and disctotal == 1
        ZeroPlugin->>Tags: Set "disc" to None (omit disc tag)
    else
        ZeroPlugin->>Tags: Leave "disc" tag unchanged
    end
Loading

Class diagram for updated Zero plugin configuration and logic

classDiagram
    class ZeroPlugin {
        +fields: list
        +keep_fields: list
        +update_database: bool
        +zero_disc_if_single_disc: bool
        +set_fields(item, tags)
    }
    ZeroPlugin : set_fields(item, tags)
    ZeroPlugin : zero_disc_if_single_disc
    ZeroPlugin : fields
    ZeroPlugin : keep_fields
    ZeroPlugin : update_database
    class Item {
        +disc: int | str
        +disctotal: int
    }
    ZeroPlugin --> Item : uses
Loading

File-Level Changes

Change Details Files
Add zero_disc_if_single_disc configuration option
  • Add zero_disc_if_single_disc key to default config with False value
beetsplug/zero.py
Skip disc tag on single-disc when option is enabled
  • Insert conditional check for disc and disctotal == 1
  • Log debug message and set tags['disc'] to None
beetsplug/zero.py
Refine warning log message when no fields to process
  • Change warning text from 'no fields, nothing to do' to 'no fields list to remove'
beetsplug/zero.py
Document the zero_disc_if_single_disc option
  • Update changelog entry to describe the new boolean option
  • Add documentation in plugin guide for zero_disc_if_single_disc
docs/changelog.rst
docs/plugins/zero.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `beetsplug/zero.py:128` </location>
<code_context>
         fields_set = False

+        if "disc" in tags and self.config["zero_disc_if_single_disc"].get(bool) and item.disctotal == 1:
+            self._log.debug("disc: {.disc} -> None", item)
+            tags["disc"] = None
+
</code_context>

<issue_to_address>
**suggestion:** The debug log message could be more descriptive.

Include the reason for zeroing the disc field in the log, such as noting it's a single-disc release and the config option is enabled, to improve clarity for future debugging.

```suggestion
            self._log.debug(
                "Zeroing disc field: single-disc release (disctotal=1) and 'zero_disc_if_single_disc' config enabled. disc: {.disc} -> None",
                item
            )
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@semohr semohr left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Overall this looks good. Im not too sure about the name for the config option tho. It seems a bit wordy to me and I don't think we need the zero in there as this is a plugin specific option.
How about something simpler like omit_single_disc?

@semohr semohr added the plugin Pull requests that are plugins related label Sep 16, 2025
Change the parameter name to omit_single_disc (vs previously zero_disc_if_single_disc)

Add return of 'fields_set' so that, if triggered by the command line `beets zero`, it will still effect the item.write.

Added tests.
@michaelkrieger
Copy link
Author

@semohr Thank you for the suggestion. It has been implemented changing the parameter name to omit_single_disc (vs previously zero_disc_if_single_disc).

Also, with this update, I have:

  • Add return of 'fields_set' so that, if triggered by the command line beets zero, it will still effect the item.write.
  • Added some tests for completeness. This tries a permutation both as the only option and along with a field-removal.

Remove tests.  Update docs.  Remove unnecessary return.
Add back tests as they were.
@michaelkrieger
Copy link
Author

Tried to implement and just got more problems. Left it as is for now (could be cleaned up once the migration of tests gets done for these plugins) unless you'd rather just remove the tests entirely.

Ideally just want to merge this important feature and move forward so it doesn't miss out on another release of Beets and aren't chasing other people's merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin Pull requests that are plugins related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants