Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Title Formatting: $if against list of strings (Read 323 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Title Formatting: $if against list of strings

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.

 

Re: Title Formatting: $if against list of strings

Reply #1
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.

Re: Title Formatting: $if against list of strings

Reply #2
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.