metabrainz / picard-plugins

Picard plugins: use 1.0 branch for Picard < 2.0 (python 2/Qt4) and 2.0 branch for Picard >= 2.0 (python 3/Qt5)
https://picard.musicbrainz.org/plugins/
145 stars 95 forks source link

PICARD-2032: Set albumsort/titlesort tags #369

Closed twodoorcoupe closed 9 months ago

twodoorcoupe commented 9 months ago

This plugin attempts to fix [PICARD-2032]. For each track or album it first checks if there are any sort names already available in the aliases, otherwise it swaps the title's prefix.

Then it also partly fixes [PICARD-2779] by providing script functions:

So far, the languages available are English, Spanish, Italian, French, German, and Portuguese. For each language there's a list of articles that are used as prefixes and a list of short prepositions and conjunctions that are used in $title_lang. These I wrote myself by looking online, so they are prone to errors.

$swapprefix_lang and $delprefix_lang do the same thing as their original counterparts but take languages as inputs instead of prefixes. $title_lang returns the text in title case by keeping the small words of each language in lower case. During tagging, if the title's prefix is swapped, only the track's or album's language are considered. If none are found then all of the available ones are considered.

Checking the aliases for each track and album can be turned off in the options, as well as ignoring titles in all caps for $title_lang. It's my first time contributing so I apologize if I missed anything important.

Sophist-UK commented 9 months ago

P.S. @twodoorcoupe Giorgio - Many thanks for coding this when I don't have the time. 👍

twodoorcoupe commented 9 months ago

Thank you @Sophist-UK for taking the time to review this. I made the changes you requested and added some unit tests. Now, when a new combination of languages is used, the resulting list of prefixes or minor words is stored so as not to recalculate it every time.

Sophist-UK commented 9 months ago

@zas, can you enable workflow for @twodoorcoupe so that we can see his unit tests running?

twodoorcoupe commented 9 months ago

All the tweaks you suggested should be implemented now. Many thanks for all the tips.

twodoorcoupe commented 9 months ago

Ah that makes sense and now I remembered it was actually proposed by @Sophist-UK in [PICARD-2779] as an enhancement of $swapprefix. I moved the logic for finding the languages from _swapprefix in SortTagger to a new function find_languages that is then used by the script functions. Thank you @phw for the help.

Sophist-UK commented 9 months ago

I think this looks good to go too.

Sophist-UK commented 9 months ago

@twodoorcoupe Thank you again for all your efforts on this - including your willingness to rework it several times to satisfy the petty demands of grumpy old coders like me.