Page 1 of 1

If a file has a {edition-(whatever)} section then copy it, otherwise add such a section if there are relevant {tags}

Posted: 19 Dec 2022, 06:03
by Franky
I'm trying to get this logic working:
1. If a file has a {edition-(whatever)} section, copy it.
2. Else, add such a section if there are relevant {tags}.
3. Do nothing.

So far, I've tried

Code: Select all

{fn.match(/ \{edition-.*\}/) ? fn.match(/ \{edition-.*\}/) : " {edition-${tags[0]}}"}
This works for the first part, but doesn't add the tags section if edition section doesn't exist.

I've tried separating them out like this:

Code: Select all

{fn.match(/ \{edition-.*\}/) ? fn.match(/ \{edition-.*\}/)}
" {edition-${tags[0]}}"}
This does work the way I want if the file doesn't have the edition section, but if it does and it's a tag thats also in {tags} the section gets duplicated.

To explain further, this is so I can add custom editions that's not in {tags} and not have FileBot delete them.

Re: Custom format - If/Then not working?

Posted: 19 Dec 2022, 13:05
by rednoah
You can't use fn.match() in conditions, because it is never false. It'll either return a match, or break the {...} expression:
viewtopic.php?t=1895

Franky wrote: 19 Dec 2022, 06:03 1. If a file has a {edition-(whatever)} section, copy it.
2. Else, add such a section if there are relevant {tags}.
3. Do nothing.
e.g.

Code: Select all

{ any{ fn.match(/ \{edition-.*\}/) }{ " {edition-${tags[0]}}" } }



:idea: Alternatively, you could just use the new {edition} binding. You'll have to upgrade to the latest beta revision though. Please read [DOCS] The movie {tags} and movie {edition} bindings for details:

Code: Select all

{ "{edition-$edition}" }

Re: If a file has a {edition-(whatever)} section then copy it, otherwise add such a section if there are relevant {tags}

Posted: 20 Dec 2022, 12:27
by Franky
Awesome, thank you!