-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Lastgenre: Fix track-level handling, multi-genre keep, force behaviour, logging #4982
base: master
Are you sure you want to change the base?
Conversation
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 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 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 I think the both of you decided these options should look like that around here: #3220 (comment) |
Thanks for the extra context, @JOJ0! About the existence of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping!! Here are a couple of straightforward comments.
1e81209
to
89ae925
Compare
89ae925
to
31ce30d
Compare
I'd like to pull out this conversation #4982 (comment) 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 So from my point of view, the main problem with the current behaviour when The following idea would require a new config setting as well as a whole new branch of behaviour (Case 3): Case 1
Case 2
keep any string in present genre tag, only write last.fm genres when empty Case 3
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: #4750) Case 4
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 Which of these would now make sense to be the new default? The new @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: #4751 (comment) Here @arsaboo requests a feature that goes in direction of Case 3 above: #4750 |
So, we have two config options - Case 1: overwrite all, only fresh last.fm genres remain force: yes
keep_allowed: no Case 2: Since 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 |
Ä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 |
fb9f58d
to
c12b26b
Compare
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. |
Hi @arsaboo! I finally managed to find time to almost finish this PR. The general behaviour and docs of the new config options combinations are finished. If you want to, an "early" review would be super helpful. Since it probably also for you is a long time ago it might be interesting what you think if you read through the docs. Is it 100% clear what force/keep_allowed options do? Certainly but only if you have the time, some playing around and checking if it also really works that way would be great. Thanks a ton! |
@JOJ0 this is AWESOME 🎉🎉 The docs look reasonably clear. I will play with this. The debug logs are great to see what is going on. |
796a3bf
to
a56098f
Compare
217aa33
to
8138708
Compare
in lastgenre plugin.
generation, instead of a simple set(). This way we keep the original order of genres.
- Default to False. - During PR#4982 discussions we came to the conclusion that the following behaviour would be a good new default choice: - Keep whitelisted existing genres - Only Fetch last.fm genres for empty tags. - To get this we also have to change the default of the force option!!! - Resulting in "force: no" and "keep_allowed: yes"; see Case 4 in PR#4982 description - Options are not put to use yet, just defined and defaults set!
Keep both options' "Configuration" chapter texts as compact as possible, while linking to a new chapter that describes all 4 possible combinations in detail.
- Retrieving, filtering and deduplicating present genres of Items/Albums via separate methods. - Implement all four cases of behaviour as described in PR#4982 - Issues: - There is quite some unnecessary spliting of genres from strings into lists and the other way round happening throughout the plugin. - In the case where existing genres get "augmented" with last.fm genres, we might end up with _more_ genres than the configured limit.
- Handle genre combination logic in a well documented helper function that also include type hints. - Throughout the _get_genre function rename the result variable to new_genres to make it clearly descriptive. - Rewrite thze _get_genre function's docstring.
trying to get a little order in the chaos. Maybe reordering and/or moving out of the main plugin logic would be a better idea for some methods but don't put much more refactoring into this PR to keep it readable.
when not stated otherwise whitelist_only must be disabled, we assume it that way in _get_genre calls.
This was the original behaviour and broke when _combine_and_label helper was introduced.
- Refactor and simplify logic of _get_genre() - Add a config validation function. - New default force: yes, keep_existing: yes (closest to original behaviour)
and decide to use the original default whitelist instead of trying to mock it. Some of the existing tests do it that way as well.
When original genres were kept (keep_existing option), the final genre count was "off". The reason was that reducing genres to that count is handled in _resolve_genre which wasn't run. - This fixes it by ensuring a run of _resolve_genre in _combine_and_label_genres. - There is a small caveat though: New genres have been run through _resolve_genres already. When they are combined with the old ones, they run through it again. Let's take this into account for now and hope performance doesn't suffer too much.
- Return fetched genres as a list from _resolve_genres(). - Format, limit to count and join to delimited string in helper function. - Fix docstring. - Leave a couple of temporary debug messages. - Fix original genre fallback - just keep as-is.
- No idea where a missing separator (which is default) could happen...just set it explicitely. - Since we now refactored fetch_genre to returning a list we can add mock multiple fetched gernes easier.
- Add detailed debug logging to learn when and why things go wrong here. - Shorten docstring
- _resolve_genres returns a list with not yet formatted genres. - Rename and adapt test_count -> test_to_delimited_string
otherwise deduplicate() can't handle it.
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.
force
option: Don't always overwrite comma-separated multi-genres, compile a list and keep what's in the whitelist.lastgenre -A
in combination with config optionsource: track
- Tracks receive the album's genre even when this option is setEdit 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 aforce
option. This is what we came up with (copied over and slightly edited from #4982 (comment)):Two config options,
force
andkeep_allowed
, i.e. 4 possible settings:Possible setups with keep_allowed/force
Case 1
Overwrite all. Only fresh last.fm genres remain.
Case 2
Add new last.fm genres when empty. Present tags stay untouched.
Case 3
Add new last.fm genres. Keep whitelisted genres in present tags.
Case 4 (default)
Add new last.fm genres when empty. Keep whitelisted genres in present tags.
Edit 2025-01: Change option name
keep_allowed
tokeep_existing
which feels slightly more self-explanatory. Also decide on Case 3 as default
(force always was default, with keep-existing it might be even more helpful)
Possible setups with keep_existing/force
Setup 1
Overwrite all. Only fresh last.fm genres remain.
Setup 2
Add new last.fm genres when empty. Present tags stay untouched.
Setup 3 (default)
Add new last.fm genres. Combine genres in present tags with new ones
(depending on the setting, whitelisted or any).
Setup 4 (currently not supported)
Add new last.fm genres when empty. Keep whitelisted (or any) genres in present tags.
Why is it not supported?
After testing and playing around with this option combination a lot I realized two things:
Therefore I decided to leave this combination unsupported. A much better alternative if the user would like to keep existing genres ALWAYS but use
lastgenre
with entirely empty tags is just setting force off and keep_existing off. This would ensure never-ever pre-polutated tags will be touched while enjoying the help oflastrgenre
for ebntirely empty tags.To Do
_get_genre
tests (pytest.mark.parametrize)