Capitalize first letter of each word

I’ve been banging my head against the wall on trying to handle disambiguation in a more standard way. But my current issue is that $rreplace does not seem to handle using a function such as $upper. Here is a stripped down version of what I’m trying to do:

$set(_firstLetter,\\b\(\\w\))
$set(_upperLetter,$upper(\\1))
$set(album,%album% \($rreplace(%_releasecomment%,%_firstLetter%,%_upperLetter%)\))

No matter how many times I’ve tried to tweak this, it never returns the uppercase value of the first letter. If I replace %_upperLetter% with something like TEST, it will return TESTeluxe TESTdition. So my regex is at least capturing the right stuff.

Double-checking the Picard scripting functions list, $rreplace() is of course “replace by searching for a regular expression”. I looked for a $sentencecase() or $caps2() function, but I don’t see them.

I see two things that puzzle me in your second statement, $set(_upperLetter,$upper(\\1)).

First, when is the $upper() call executed? Just looking at it, it seems it should be executed when the second statement runs. This means that %_upperLetter% will always have the value \1, not $upper(\1).

Second, I assume that you want the \1 value passed to $rreplace() to be replaced by whatever matches the regular expression \w. Does $rreplace() promise to perform that kind of match group replacement? The documentation is very skimpy, but it doesn’t promise this that I can see.

So, if my observations are valid, maybe the conclusion is: this is the sort of text manipulation which is too hard for Picard’s scripting language. You might have to write a Picard plugin instead. That gives you access to the full power of the Python scripting language.

I hope this is helpful. Good luck!
—Jim DeLaHunt

1 Like

Interesting point. I think I tried it in the $set album statement directly, too. I’ll try that again, but had a funny feeling it might lead to me writing a plugin…

Thanks for the pointers.

@thomnottom Just for the records: There is already a plugin called “Title Case” as starting point:
https://picard.musicbrainz.org/plugins/
This plugin does what you are looking for, but only for words in the tags “title”, “album” and “artist”.

Hi. Plugins “Title Case”, “Smart Title Case”, this “Enhanced Title Case” and this script command didn’t work for me:

$set(title,$title(%title%))
$set(album,$title(%album%))
$set(title,$replace(%title%,A|An|And|As|At|But|By|De|E|En|For|From|Ka|Kara|Ga|If|In|It|Ma|Made|Mo|Mid|Na|Ne|Ni|No|Nor|O|Of|On|Or|Per|Qua|Re|The|To|Up|Wa|Ya|Yo|Via|Vs.,a|an|and|as|at|but|by|de|e|en|for|from|ka|Kara|ga|if|in|it|ma|made|mo|mid|na|ne|ni|no|nor|o|of|on|or|per|qua|re|the|to|up|wa|ya|yo|via|vs.))
$set(album,$replace(%album%,A|An|And|As|At|But|By|De|E|En|For|From|Ka|Kara|Ga|If|In|It|Ma|Made|Mo|Mid|Na|Ne|Ni|No|Nor|O|Of|On|Or|Per|Qua|Re|The|To|Up|Wa|Ya|Yo|Via|Vs.,a|an|and|as|at|but|by|de|e|en|for|from|ka|Kara|ga|if|in|it|ma|made|mo|mid|na|ne|ni|no|nor|o|of|on|or|per|qua|re|the|to|up|wa|ya|yo|via|vs.))

All letters in “title” and “album” fields are always capitalized (if it was so originally). What could be the problem?

Adding to my previous message. This concerns Asian music, mainly Japanese, where English words in Title and Album fields are often written in capital letters. I would like to normalize the capitalization for myself, but for some reason i cannot do it in Picard, i can’t make it work. The fields Title and Album are not added to the “Preserve Tags” list, but plugins and scripts do not do anything with capitalization.

Hello, @truumann :

Thank you for your contributions to MusicBrainz. Sorry I am so late in replying to your post. I just now noticed this topic.

First, it looks you have a new question, rather than a reply to the previous messages of this topic, so I suggest that it is better to start a new topic with your question, rather than tack it on to an old topic.

If you want, you could click the little flag icon under your Aug '23 message, and report your message and its replies as off-topic. Ask for an administrator to move them to their own topic.

Second, take a close look at the letters in the Japanese and Asian text. Are those proportionally-spaced or halfwidth characters? Or are they full-width? Full width letters are the same with as Chinese characters, and all letters have the same width. Full-width letters have different character codes than proportionally-spaced or halfwidth letters, so the usual letter-case-changing functions probably will pass them over.