zero plugin zeroes disctotal if single disc#6306
zero plugin zeroes disctotal if single disc#6306fredrik wants to merge 1 commit intobeetbox:masterfrom
zero plugin zeroes disctotal if single disc#6306Conversation
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6306 +/- ##
==========================================
- Coverage 68.97% 68.97% -0.01%
==========================================
Files 140 140
Lines 18694 18693 -1
Branches 3060 3060
==========================================
- Hits 12894 12893 -1
Misses 5153 5153
Partials 647 647
🚀 New features to boost your workflow:
|
snejus
left a comment
There was a problem hiding this comment.
Just one comment re making this slightly simpler. And it would be good to see a note in the changelog!
beetsplug/zero.py
Outdated
| 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: | ||
| if "disc" in tags: | ||
| fields_set = True | ||
| self._log.debug("disc: {.disc} -> None", item) | ||
| tags["disc"] = None | ||
| if "disctotal" in tags: | ||
| fields_set = True | ||
| self._log.debug("disctotal: {.disctotal} -> None", item) | ||
| tags["disctotal"] = None |
There was a problem hiding this comment.
You can simplify this a little by using beets.ui.show_model_changes, see:
diff --git a/beetsplug/zero.py b/beetsplug/zero.py
index 4623a0c2d..928dda60e 100644
--- a/beetsplug/zero.py
+++ b/beetsplug/zero.py
@@ -21,7 +21,7 @@
from beets.importer import Action
from beets.plugins import BeetsPlugin
-from beets.ui import Subcommand, input_yn
+from beets.ui import Subcommand, input_yn, show_model_changes
__author__ = "baobab@heresiarch.info"
@@ -122,17 +122,9 @@ def set_fields
Also update the `item` itself if `update_database` is set in the
config.
"""
- fields_set = False
-
if self.config["omit_single_disc"].get(bool) and item.disctotal == 1:
- if "disc" in tags:
- fields_set = True
- self._log.debug("disc: {.disc} -> None", item)
- tags["disc"] = None
- if "disctotal" in tags:
- fields_set = True
- self._log.debug("disctotal: {.disctotal} -> None", item)
- tags["disctotal"] = None
+ for tag in {"disc", "disctotal"} & set(tags):
+ tags[tag] = None
if not self.fields_to_progs:
self._log.warning("no fields list to remove")
@@ -146,13 +138,12 @@ def set_fields
match = not progs
if match:
- fields_set = True
self._log.debug("{}: {} -> None", field, value)
tags[field] = None
if self.config["update_database"]:
item[field] = None
- return fields_set
+ return show_model_changes(item)
def process_item(self, item):
tags = dict(item)This also has the benefit of changes being reported using the same format and user configuration as beet write and beet update.
There was a problem hiding this comment.
That looks great, I was not aware! I'll make that change and also update the Changelog.
There was a problem hiding this comment.
I don't think show_model_changes works for me here. The plugin defaults to not updating the database and in that case we're not touching item. Please correct me if I'm wrong or if there's another way around this.
I've kept your suggestion for neater iteration and also added changelog and docs entries.
164f971 to
9579489
Compare
|
Squashed and ready to go. |
When omit_single_disc is set, disctotal is now also zeroed alongside disc. Previously, only the disc tag was zeroed.
72c86ea to
cd9f86a
Compare
Description
When
omit_single_discis set,disctotalis now also zeroed alongsidedisc. These tags work together ("Disc 2 of 3") so keeping one without the other is inconsistent.Previously, only the
disctag was zeroed. This follows from #6015 which made it into v2.5.1 and added theomit_single_discoption.I've added tests and have used this locally for some time.
To Do