Author Topic: File naming ending on complete a word?  (Read 2466 times)

Mr. Trev

  • Sr. Member
  • ****
  • Posts: 321
Not sure if I'm asking too much here…

I have my file naming template set to truncate folder/files names so I don't end up with absurdly long file paths (even with Win10 I've had paths long enough to cause issues)

Is it possible to have a naming template that'll shorten names, but end on a complete word before the cutoff? Ideally, I'd want to end with an ellipse too.

For instance, the Chumbawamba album "The Boy Bands Have Won, and All the Copyists and the Tribute Bands and the TV Talent Show Producers Have Won, If We Allow Our Culture to Be Shaped by Mimicry, Whether From Lack of Ideas or From Exaggerated Respect. You Should Never Try to Freeze Culture. What You Can Do Is Recycle That Culture. Take Your Older Brother's Hand-Me-Down Jacket and Re-Style It, Re-Fashion It to the Point Where It Becomes Your Own. But Don't Just Regurgitate Creative History, or Hold Art and Music and Literature as Fixed, Untouchable and Kept Under Glass. The People Who Try to 'Guard' Any Particular Form of Music Are, Like the Copyists and Manufactured Bands, Doing It the Worst Disservice, Because the Only Thing That You Can Do to Music That Will Damage It Is Not Change It, Not Make It Your Own. Because Then It Dies, Then It's Over, Then It's Done, and the Boy Bands Have Won"

I would keep the full album name in my MB library, but the folder would be "The Boy Bands Have Won…" as opposed to just being abruptly cutoff after the 50 character (or whatever) limit - actually, I'm not even sure if the ellipse is a valid character for file naming, but I'd use it if possible

BTW: this is a great album

The Incredible Boom Boom

  • Hero Member
  • *****
  • Posts: 723
For instance, the Chumbawamba album "The Boy Bands Have Won, and All the Copyists and the Tribute Bands and the TV Talent Show Producers Have Won, If We Allow Our Culture to Be Shaped by Mimicry, Whether From Lack of Ideas or From Exaggerated Respect. You Should Never Try to Freeze Culture. What You Can Do Is Recycle That Culture. Take Your Older Brother's Hand-Me-Down Jacket and Re-Style It, Re-Fashion It to the Point Where It Becomes Your Own. But Don't Just Regurgitate Creative History, or Hold Art and Music and Literature as Fixed, Untouchable and Kept Under Glass. The People Who Try to 'Guard' Any Particular Form of Music Are, Like the Copyists and Manufactured Bands, Doing It the Worst Disservice, Because the Only Thing That You Can Do to Music That Will Damage It Is Not Change It, Not Make It Your Own. Because Then It Dies, Then It's Over, Then It's Done, and the Boy Bands Have Won"

Lmao

Quote
I would keep the full album name in my MB library, but the folder would be "The Boy Bands Have Won…" as opposed to just being abruptly cutoff after the 50 character (or whatever) limit - actually, I'm not even sure if the ellipse is a valid character for file naming, but I'd use it if possible

You'll need the Additional Tagging & Tools plugin to access some of the functions below.
This should get you started. You'll have to wrap the $Left(Album,#) in a regular expression that matches everything up to the last space of the input phrase.

Code
$If($Pad($Len(<Album>),4)>0050,$Left(<Album>,50)"...",<Album>)
Last Edit: November 10, 2021, 04:38:14 PM by The Incredible Boom Boom

hiccup

  • Hero Member
  • *****
  • Posts: 5571
You'll need the Additional Tagging & Tools plugin to access some of the functions below.
This should get you started. You'll have to wrap the $Left(Album,#) in a regular expression that matches everything up to the last space of the input phrase.
Code
$If($Pad($Len(<Album>),4)>0050,$Left(<Album>,50)"...",<Album>)
Just curious, (being a frequently frustrated regex amateur): what is it in this regex that defines the last space?

edit:
b.t.w. the ellipse … is a valid Windows file- and folder name character, so it would be appropriate here and will save two character positions.
Last Edit: November 10, 2021, 05:42:54 PM by hiccup

psychoadept

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10483
That $If looks incomplete. And what's the purpose of padding the number?
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

The Incredible Boom Boom

  • Hero Member
  • *****
  • Posts: 723
Just curious, (being a frequently frustrated regex amateur): what is it in this regex that defines the last space?

Code
$If($Pad($Len(<Album>),4)>0050,$RxReplace($Left(<Album>,50),"\s(?=[^\s]*$)[\s\S]*?$","..."),<Album>)
For the purpose of answering @hiccup's question, here's a hacky expression that should work for you, @Mr. Trev. (You can change "50" to whatever number you wish and use either the three periods or the ellipse provided by him.)

Expression formulated here, @hiccup
It's a little hard to understand, but divide it into three parts.

Code
\s
The space before the last space. This is where the engine knows to start matching. Once it hits a space, it'll check the below expression to see if it also matches.
Code
(?=[^\s]*$)
?= is the lookahead operator, so (starting from the above space) the engine will search for every character not a space [^\s] to the end of the phrase *$. If it hits the end of the phrase, it's a match, but if it hits another space, it'll reset matching starting from this newly discovered space.
Code
[\s\S]*?$
This expression is a generic "match all characters" until the end of the phrase.

That $If looks incomplete. And what's the purpose of padding the number?

How so? MusicBee doesn't handle place value, so padding ensures both numerical expressions are evaluated appropriately.
I think something like 133>50 would return F, because 5 is greater than 1, for example. 133>050 evaluates properly.
Last Edit: November 10, 2021, 11:53:35 PM by The Incredible Boom Boom

Mr. Trev

  • Sr. Member
  • ****
  • Posts: 321
Just curious, (being a frequently frustrated regex amateur): what is it in this regex that defines the last space?

Code
$If($Pad($Len(<Album>),4)>0050,$RxReplace($Left(<Album>,50),"\s(?=[^\s]*$)[\s\S]*?$","..."),<Album>)
For the purpose of answering @hiccup's question, here's a hacky expression that should work for you, @Mr. Trev. (You can change "50" to whatever number you wish and use either the three periods or the ellipse provided by him.)

Expression formulated here, @hiccup
It's a little hard to understand, but divide it into three parts.

Code
\s
The space before the last space. This is where the engine knows to start matching. Once it hits a space, it'll check the below expression to see if it also matches.
Code
(?=[^\s]*$)
?= is the lookahead operator, so (starting from the above space) the engine will search for every character not a space [^\s] to the end of the phrase *$. If it hits the end of the phrase, it's a match, but if it hits another space, it'll reset matching starting from this newly discovered space.
Code
[\s\S]*?$
This expression is a generic "match all characters" until the end of the phrase.

That $If looks incomplete. And what's the purpose of padding the number?

How so? MusicBee doesn't handle place value, so padding ensures both numerical expressions are evaluated appropriately.
I think something like 133>50 would return F, because 5 is greater than 1, for example. 133>050 evaluates properly.

Hey, thanks for both the expression and how it works. My feeble mind doesn't handle RegEx well, so I probably would've never figured it out (and I've tried learning this stuff. I guess my brain just don't work that way)

psychoadept

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10483
How so? MusicBee doesn't handle place value, so padding ensures both numerical expressions are evaluated appropriately.
I think something like 133>50 would return F, because 5 is greater than 1, for example. 133>050 evaluates properly.

Ah, I think I was just parsing it wrong. I guess I'd have to test to be sure about $Len but I figured it would handle numerical expressions since that's what it has to return. I've always just used $Left(<Tag>,50) and it doesn't have any effect if the tag is less than 50. But in this case you probably need it to determine if it's truncating anything before you decide if the RegEx needs to be applied.
Last Edit: November 11, 2021, 06:31:51 PM by psychoadept
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

hiccup

  • Hero Member
  • *****
  • Posts: 5571
Expression formulated here, @hiccup
It's a little hard to understand, but divide it into three parts.
Very nice, thanks!

@Mr. Trev:
If you replace the colon in the formulas with this:
Code
[∶ :]
the formulas should work both on titles containing colon or ratio characters.