beets
beets copied to clipboard
Lastgenre: Fix track-level handling, multi-genre keep, force behaviour, logging
Description
Edit 2023-09: The original idea of this PR was:
Several fixes I had in the queue for months. Some of it required fixes in the library code which are through by now.
- [X] Fix the
force
option: Don't always overwrite comma-separated multi-genres, compile a list and keep what's in the whitelist. - [X] Fix
lastgenre -A
in combination with config optionsource: track
- Tracks receive the album's genre even when this option is set- When an album-level genre is set already, single tracks should don't fall back to receiving the album's genre.
- [x] Adjust log-level and message when lastgenre handles tracks to look similar to when handling albums.
Edit 2023-09: Additional option keep_allowed
During review and discussions it turned out that besides the existing force
option a second option would be required to really achieve a typical (expected) behaviour of a force
option. This is what we came up with (copied over and slightly edited from https://github.com/beetbox/beets/pull/4982#issuecomment-1816696749):
Two config options, force
and keep_allowed
, i.e. 4 possible settings:
Case 1
Overwrite all. Only fresh last.fm genres remain.
force: yes
keep_allowed: no
Case 2
Add new last.fm genres when empty. Present tags stay untouched.
force: no
keep_allowed: no
Case 3
Add new last.fm genres. Keep whitelisted genres in present tags.
force: yes
keep_allowed: yes
Case 4 (default)
Add new last.fm genres when empty. Keep whitelisted genres in present tags.
force: no
keep_allowed: yes
To Do
- [x] Documentation of new option and new default force behaviour.
- [ ] Documentation: Clarify that -a is implicit
- [ ] Changelog.
- [ ] Fix existing tests.
- [x] Implement Case 1
- [x] Implement Case 2
- [x] Implement Case 3
- [x] Implement Case 4
I'd request a review from you @sampsyo since I think you initially created it. Also @rain0r would be good since 5 years ago they added the -A
option. Hi @rain0r , you wanna take a look? :-)
In short: I think I fixed the plugin to now really reflect what's documented. Any nitpicking in my code or functionality-wise is appreciated.
One question already. Here we do not state that a -a/--album
option exists: https://beets.readthedocs.io/en/latest/plugins/lastgenre.html#running-manually
When I started out with using this plugin I was confused a verry long time about this option. As far as I understand it now: It doesn't do anything since it is default. So why keep it? Or is having a -a
option that is the default anyway a common thing in beets? I know we have a lot of -a
commands which streamlines usablity, and that is a very good thing! Usuall they change behaviour to not do something with items but with albums. I'm just not sure about this one....do we have such a pattern anywhere else? So, just leave it? Should I add some words to the docs?
I think the both of you decided these options should look like that around here: https://github.com/beetbox/beets/pull/3220#issuecomment-485265032
Thanks for the extra context, @JOJ0!
About the existence of -a
(the default mode) specifically: it's not too uncommon… for example, the beet import
command has several flags that are opposites of each other, one of which is the default. Of course, it's important in that case because the default mode can be set in the config, so the user needs a way to override the default in either direction. That's not the case here, so maybe it at least makes sense to add "(default)" to the -a
option's help string, or to remove it altogether?
I'd like to pull out this conversation https://github.com/beetbox/beets/pull/4982#discussion_r1382269775 into a new thread, to make it more obvious for others as well. I think it could be a broader discussion of where this plugin should go. Basically we were talking about the current force: no
behaviour being weird as well as the new behaviour I am initially proposing with this PR. I gave all this some thought and came up with this idea. Let's discuss it:
So from my point of view, the main problem with the current behaviour when force
is disabled, is that it's not really what a user would typically expect. So what could we do to make force: no
more predictable?
The following idea would require a new config setting as well as a whole new branch of behaviour (Case 3):
Case 1
force: yes
overwrite all, only fresh last.fm genres remain
Case 2
force: no
keep any string in present genre tag, only write last.fm genres when empty
Case 3
force: yes
keep_allowed: yes
keep present genres when whitelisted and add new last.fm genres (this is a new branch of behaviour and needs to be coded, I think there is open feature requests for it. Update: Something was feature-requested, but it might not be exactly as I'm proposing here: https://github.com/beetbox/beets/issues/4750)
Case 4
force: no
keep_allowed: yes
cleanup only - keep present genres when whitelisted but don't add new last.fm genres; Only when genre is empty, add last.fm genres.
That last combination is weird though....but it's what I proposed for force:no
before!
Which of these would now make sense to be the new default? The new force: no
(Case 2) would be the least invasive IMO...
@sampsyo brainstorming request 🧐
Some more context / cross-linking:
The initial reason why I got my hands dirty with this plugin was when I realised that comma separated multi-genres where not recognized: https://github.com/beetbox/beets/pull/4751#issuecomment-1531342394
Here @arsaboo requests a feature that goes in direction of Case 3 above: https://github.com/beetbox/beets/issues/4750
So, we have two config options - force
and keep_allowed
, i.e., 4 options in all. Given that, keep_allowed
is no
in cases 1 and 2. Thus, here's a slightly modified behavior in the 4 cases above:
Case 1: overwrite all, only fresh last.fm genres remain
force: yes
keep_allowed: no
Case 2: Since keep_allowed
is no
, we only write last.fm genres when empty. There may be incorrect genres in pre-existing tags even after this, as this option is not touching pre-existing tags
force: no
keep_allowed: no
Case 3: keep present genres when whitelisted and add new last.fm genres
force: yes
keep_allowed: yes
Case 4: keep any string in the present genre tag; only write last.fm genres when empty. This will not touch pre-existing genre tags.
force: no
keep_allowed: yes
Thus, Case 4 seems like the best default choice. It does not affect existing genre tags and updates the empty ones. Case 3, on the other hand, is the most useful one (at least for me).
This brainstorming honestly sounds great, y'all. It is indeed really weird that the force: no
mode can still update old genres; keeping all nonempty genres seems like it should at least be an option. I feel less specific about what the default should be, but I like your idea about decoupling the two aspects of the behavior (when to override existing, nonempty data and what to do to old data) into two different options.
Ähem I might be slow or too tired already. Which of those 4 cases are now different from my proposal @arsaboo ? Sorry I must have missed it! Help! :-)
Not different....just a little more explicit about the force
and keep_allowed
config options. I think we have an agreement about the options.