HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: John Doe on 2021-10-07 18:10:54

Title: Title Formatting: $if against list of strings
Post by: John Doe on 2021-10-07 18:10:54
I have no idea how to use Search for this particular question:

Is it possible to use the $if statement with an array or a text file with strings?

What I want to achieve:
Code: [Select]
IF 'WORD' is in 'list-of-exclusions.txt' -> do nothing -> ELSE convert to $Caps.
or the more confusing version
Code: [Select]
IF 'WORD' is one of 'STRING1,STRING2,STRING3,STRING4...' -> do nothing -> ELSE convert to $Caps.

Specific sample:
Tags are:
Artist: BilliE Eilish
Album: Happier Than EVER
Title: NDA
List 'exclude-from-Caps.txt' has 'NDA','BilliE'

Code: [Select]
$IF 'WORD' is in 'list-of-exclusions.txt' -> do nothing -> ELSE convert to $Caps

would change the tags to:
Artist: BilliE Eilish
Album: Happier Than Ever
Title: NDA

How do you achieve that?

Thanks.
Title: Re: Title Formatting: $if against list of strings
Post by: j7n on 2021-10-07 22:29:25
I don't think you can read in a text file directly into a function. The most practical solution for this case would be to capitalize all words, and then decapitalize your exclusions with a long $replace() function. You may also need to insert a placeholder character between words and punctiation marks to make sure your function operates on whole words. If you want to capitalize a word down, then use a different word boundary character, which is not inserted after major punctuation which signals a new sentence. $replace(input,|¦|Billie|¦|,|¦|BilliE|¦|,|¦|The|¦|,|¦|the|¦|). Use Masstagger to make your function more readable by breaking out the replace onto a separate line.

I use this workflow for capitalizing titles, but my exclusions are conventional conjuctions and prepositions, not strange "artistic" capitalization.

You could find a word in a string using $ifgreater($strstr($get(input),BilliE),0,$dosomething(),). But that doesn't help with capitalization because you can't process individual words. It will pass or reject the entire string.
Title: Re: Title Formatting: $if against list of strings
Post by: Dryst on 2021-10-20 19:32:50
If fb2k scripting supported regex matching, this would be trivial to do.  I saw no mention of regex support at all.  Perhaps this would be a useful feature request for future consideration.