-
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: New config option keep_existing
#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
- 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.
otherwise deduplicate() can't handle it.
- Adapt tests to _resolve_genres returning a list with not yet formatted genres. - Rename and adapt test_count -> test_to_delimited_string. Note that the new function does not apply whitelist, prefer anything. It just cuts to count and formats!
You are absolutely right, this is the reason. We should note this and handle it in a future PR. Maybe note it in a new issue with a possible solution idea already: We have a multi-artist field in beets already:
Exactly, only because of the artist "Pritam", genres could be found. |
@arsaboo I think final testing is in order. If I haven't forgotten anything (except a changelog) I think this is finally done. Some testing with all the different possible (and impossible) configuration combination lastgenre offers would be great. (whitelist of/on, canonical off/on, prefer_specifc, count, and so on). If you find the time, it would be super-helpful!!!! :-) @snejus thanks to the Note that I left a lot of debug logging in place for now, to make final testing easier Those lines will be removed before merge but if we find something particularly useful we could keep it in the final version. |
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. |
It is working fine for the most part. Here's one that is not working fine. With lastgenre:
auto: no
source: album
count: 5
separator: '\?'
# whitelist: ~/.config/beets/genres/genres.txt
# all_genres: ~/.config/beets/genres/all_genres.txt
# canonical: ~/.config/beets/genres/genres-trees.yaml
force: yes
keep_existing: no I am not sure why it still checks against the whitelist. $ beet -v lastgenre album:"Rocky Aur Rani Kii Prem Kahaani"
user configuration: /home/arsaboo/.config/beets/config.yaml
data directory: /home/arsaboo/.config/beets
Sending event: pluginload
library database: /home/arsaboo/.config/beets/musiclibrary.blb
library directory: /data/music
Sending event: library_opened
Parsed query: AndQuery([SubstringQuery('album', 'Rocky Aur Rani Kii Prem Kahaani', fast=True)])
Parsed sort: NullSort()
lastgenre: Genre 'Filmi' allowed. FOUND in whitelist.
lastgenre: Genre 'World Music' allowed. FOUND in whitelist.
lastgenre: Genre 'Desi' allowed. FOUND in whitelist.
lastgenre: _last_lookup receives: album, get_album, ('Pritam', 'Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)')
lastgenre: _tags_for result is: []
lastgenre: fetch_genre returns (whitelist checked): []
lastgenre: _last_lookup returns: []
lastgenre: _last_lookup receives: artist, get_artist, ('Pritam',)
lastgenre: _tags_for result is: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: fetch_genre returns (whitelist checked): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _last_lookup returns: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _combine got type new_genres: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres received: ['filmi', 'world music', 'desi', 'bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india']
lastgenre: Genre 'filmi' allowed. FOUND in whitelist.
lastgenre: Genre 'world music' allowed. FOUND in whitelist.
lastgenre: Genre 'desi' allowed. FOUND in whitelist.
lastgenre: _resolve_genres (canonicalized and whitelist filtered): ['filmi', 'world music', 'desi']
lastgenre: Reducing ['filmi', 'world music', 'desi'] to configured count 5
lastgenre: Reduced and formatted tags to Filmi, World Music, Desi
lastgenre: genre for album "Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)" (keep + artist): Filmi, World Music, Desi |
Have a look at the defaults: https://github.com/beetbox/beets/pull/4982/files#diff-f85204832b1e3e76cf854983f1f1773be9f7857d94656cbb3a0f2a0ae6431140L99 and note that an empty string "" still will enable the built-in whitelist (same as True/on). To really disable it set Also note that the This all is expected behaviour (even unittested) and existed before this PR! |
hmm...even with lastgenre:
auto: no
source: album
count: 5
separator: ','
whitelist: False
# whitelist: ~/.config/beets/genres/genres.txt
# all_genres: ~/.config/beets/genres/all_genres.txt
# canonical: ~/.config/beets/genres/genres-trees.yaml
force: yes
keep_existing: no lastgenre: Genre 'Filmi' allowed. FOUND in whitelist.
lastgenre: Genre 'World Music' allowed. FOUND in whitelist.
lastgenre: Genre 'Desi' allowed. FOUND in whitelist.
lastgenre: _last_lookup receives: album, get_album, ('Pritam', 'Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)')
lastgenre: _tags_for result is: []
lastgenre: fetch_genre returns (whitelist checked): []
lastgenre: _last_lookup returns: []
lastgenre: _last_lookup receives: artist, get_artist, ('Pritam',)
lastgenre: _tags_for result is: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: fetch_genre returns (whitelist checked): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _last_lookup returns: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _combine got type new_genres: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres received: ['filmi', 'world music', 'desi', 'bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india']
lastgenre: Genre 'filmi' allowed. FOUND in whitelist.
lastgenre: Genre 'world music' allowed. FOUND in whitelist.
lastgenre: Genre 'desi' allowed. FOUND in whitelist.
lastgenre: _resolve_genres (canonicalized and whitelist filtered): ['filmi', 'world music', 'desi']
lastgenre: Reducing ['filmi', 'world music', 'desi'] to configured count 5
lastgenre: Reduced and formatted tags to Filmi, World Music, Desi
lastgenre: genre for album "Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)" (keep + artist): Filmi, World Music, Desi |
Interesting. I added a debug message in 2025a56 Could you try the same again? |
Ok...it is working 🎉🎉 Too embarrassed to admit that I had lastgenre: The whitelist config setting is 'False'
lastgenre: The self.whitelist property after file parsing is 'set()'
Sending event: pluginload
library database: /home/arsaboo/.config/beets/musiclibrary.blb
library directory: /data/music
Sending event: library_opened
Parsed query: AndQuery([SubstringQuery('album', 'Rocky Aur Rani Kii Prem Kahaani', fast=True)])
Parsed sort: NullSort()
lastgenre: _last_lookup receives: album, get_album, ('Pritam', 'Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)')
lastgenre: _tags_for result is: []
lastgenre: fetch_genre returns (whitelist checked): []
lastgenre: _last_lookup returns: []
lastgenre: _last_lookup receives: artist, get_artist, ('Pritam',)
lastgenre: _tags_for result is: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: fetch_genre returns (whitelist checked): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _last_lookup returns: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _combine got type new_genres: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres received: ['filmi', 'world music', 'desi', 'bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india']
lastgenre: Genre 'filmi' allowed. Whitelist OFF.
lastgenre: Genre 'world music' allowed. Whitelist OFF.
lastgenre: Genre 'desi' allowed. Whitelist OFF.
lastgenre: Genre 'bollywood' allowed. Whitelist OFF.
lastgenre: Genre 'hindi' allowed. Whitelist OFF.
lastgenre: Genre 'indian' allowed. Whitelist OFF.
lastgenre: Genre 'pritam' allowed. Whitelist OFF.
lastgenre: Genre 'soundtrack' allowed. Whitelist OFF.
lastgenre: Genre 'world' allowed. Whitelist OFF.
lastgenre: Genre 'india' allowed. Whitelist OFF.
lastgenre: _resolve_genres (canonicalized and whitelist filtered): ['filmi', 'world music', 'desi', 'bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india']
lastgenre: Reducing ['filmi', 'world music', 'desi', 'bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india'] to configured count 5
lastgenre: Reduced and formatted tags to Filmi, World Music, Desi, Bollywood, Hindi
lastgenre: genre for album "Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)" (keep + artist): Filmi, World Music, Desi, Bollywood, Hindi I tried various combinations of In terms of debug logs, we should at least log:
Would love to see this merged ASAP so that we can work on improving the search. |
Thanks! Very helpful and no problem :-) You tried the prefer_specific option too? I agree with logging 1 2is actually already logged in the current version and will improve in #5582 |
I am unsure if this album is a good test for lastgenre:
auto: no
source: album
count: 5
separator: ','
whitelist: no
# whitelist: ~/.config/beets/genres/genres.txt
# all_genres: ~/.config/beets/genres/all_genres.txt
# canonical: ~/.config/beets/genres/genres-trees.yaml
force: yes
keep_existing: no
prefer_specific: True lastgenre: _last_lookup receives: album, get_album, ('Pritam', 'Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)')
lastgenre: _tags_for result is: []
lastgenre: fetch_genre returns (whitelist checked): []
lastgenre: _last_lookup returns: []
lastgenre: _last_lookup receives: artist, get_artist, ('Pritam',)
lastgenre: _tags_for result is: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: fetch_genre returns (whitelist checked): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _last_lookup returns: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _combine got type new_genres: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres received: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres (canonicalized and whitelist filtered): []
lastgenre: Reducing [] to configured count 5
lastgenre: Reduced and formatted tags to
lastgenre: genre for album "Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)" (artist): lastgenre:
auto: no
source: album
count: 5
separator: ','
whitelist: no
# whitelist: ~/.config/beets/genres/genres.txt
# all_genres: ~/.config/beets/genres/all_genres.txt
# canonical: ~/.config/beets/genres/genres-trees.yaml
force: yes
keep_existing: no
prefer_specific: False lastgenre: _last_lookup receives: album, get_album, ('Pritam', 'Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)')
lastgenre: _tags_for result is: []
lastgenre: fetch_genre returns (whitelist checked): []
lastgenre: _last_lookup returns: []
lastgenre: _last_lookup receives: artist, get_artist, ('Pritam',)
lastgenre: _tags_for result is: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: fetch_genre returns (whitelist checked): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _last_lookup returns: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _combine got type new_genres: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres received: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: Genre 'bollywood' allowed. Whitelist OFF.
lastgenre: Genre 'hindi' allowed. Whitelist OFF.
lastgenre: Genre 'indian' allowed. Whitelist OFF.
lastgenre: Genre 'pritam' allowed. Whitelist OFF.
lastgenre: Genre 'soundtrack' allowed. Whitelist OFF.
lastgenre: Genre 'world' allowed. Whitelist OFF.
lastgenre: Genre 'india' allowed. Whitelist OFF.
lastgenre: Genre 'world music' allowed. Whitelist OFF.
lastgenre: Genre 'desi' allowed. Whitelist OFF.
lastgenre: _resolve_genres (canonicalized and whitelist filtered): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: Reducing ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi'] to configured count 5
lastgenre: Reduced and formatted tags to Bollywood,Hindi,Indian,Pritam,Soundtrack
lastgenre: genre for album "Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)" (artist): Bollywood,Hindi,Indian,Pritam,Soundtrack I am not sure if this album is a good test for prefer specific. |
It is a difficult one yes, but that makes it an even more interesting one to see how the plugin handles it.
First a sidenote that my debug messages are not 100% accurate anymore. For example _ Anyway, what I see here is that even that we found genres:
they are kicked out in the next step:
You have the whitelist off. One would assume this shouldn't happen....... but you also have which relies on the canonicalization tree and enables it (even though you have set Now I assume that this "kick out" happens because the I'm not 100% sure yet if this can be expected but from what I checked, the default genres-tree.txt does not have any of them. (Not even bollywood, soundtrack or world music - which I find odd and think generally should be there in our default -> maybe expand that in the future with some intenational basics?) Anyway, what now would be superinteresting. What happens if you put in place a genres-tree.txt where you have a tree with (at least some) of these genres? Thanks so far, very helpful!!! |
Some debug messages to better understand what |
with lastgenre:
auto: no
source: album
count: 5
separator: ','
whitelist: no
# whitelist: ~/.config/beets/genres/genres.txt
# all_genres: ~/.config/beets/genres/all_genres.txt
canonical: ~/.config/beets/genres/genres-trees.yaml
force: yes
keep_existing: no
prefer_specific: True Parsed query: AndQuery([SubstringQuery('album', 'Rocky Aur Rani Kii Prem Kahaani', fast=True)])
Parsed sort: NullSort()
lastgenre: _last_lookup receives: album, get_album, ('Pritam', 'Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)')
lastgenre: _tags_for result is: []
lastgenre: fetch_genre returns (whitelist checked): []
lastgenre: _last_lookup returns: []
lastgenre: _last_lookup receives: artist, get_artist, ('Pritam',)
lastgenre: _tags_for result is: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: fetch_genre returns (whitelist checked): ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _last_lookup returns: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _combine got type new_genres: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _resolve_genres received: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi']
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _get_depth returns depth:None
lastgenre: _sort_by_depth sorted depth_tag_paris: []
lastgenre: _resolve_genres (canonicalized and whitelist filtered): []
lastgenre: Reducing [] to configured count 5
lastgenre: Reduced and formatted tags to
lastgenre: genre for album "Rocky Aur Rani Kii Prem Kahaani (Original Motion Picture Soundtrack)" (artist): Let me know if you want me to test anything else. |
Doesnt seem to have changed anything compared to your run without a canoncial file. How is the genres we try to handle structured in the file? maybe post a snippet how you put these in your genres-tree.txt: ['bollywood', 'hindi', 'indian', 'pritam', 'soundtrack', 'world', 'india', 'world music', 'desi'] what you also could try: does this work on master branch with your particular config? |
Here's part of the file: - filmi
- feature film soundtrack
- indian playback
- bollywood
- indian film music composer
- indian film music composers
- soundtrack
- film music
- bolly
- bollywood disco
- bollywood film
- bollywood funk
- bollywood hindi
- bollywood indian
- bollywood legend
- bollywood movies
- bollywood music
- bollywood songs
- bollywood sound
- bollywood soundtrack
- bollywood soundtracks
- stage & screen
- soundtrack
- modern bollywood
- desi |
In any case, it doesn't look like you changed anything related to |
Description (moved)
Initially this PR included the following fixes which moved to a separate PR:
FixMoved to PR lastgenre: Fix track-level handling and streamline logging #5582lastgenre -A
in combination with config optionsource: track
- Tracks receive the album's genre even when this option is setAdjust log-level and message when lastgenre handles tracks to look similar to when handling albums.Moved to PR lastgenre: Fix track-level handling and streamline logging #5582Description
force
option. Previously disabling the option still led to manipulation of existing tags:,
), thus it failed and erased genres.This didn't feel like a typical behaviour of a
force
option, which this PR tries to improve as follows...String-separated multi-genres are now compiled into a list and depending on the
whitelist
option are kept and enriched with freshly fetched last.fm genres.A lot of refactoring was done, some absolutely required, some as a preparation for future work on the plugin.
Details & Docs
Back in 2023-09 we decided on an additional option named
keep_allowed
, details on what we came up with: #4982 (comment)):My final conclusion is to change that option name to
keep_existing
, which feels slightly more self-explanatory. Also decide on Setup 3 (see below) as the default because:keep-existing
enabled it might be a pretty common use-case.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
whitelist
setting, allowed or any).To Do
_get_genre
tests usingpytest.mark.parametrize
and add new test-cases.