Only write x if y does not contain

I want to make %comment:% write to end of the filename but only if it does not contain a certain word(s)

$if(%comment:%,($left(%comment:%,64)))

Is what I have now

I tried to do something like

$if($ne($startswith(%comment:%, visit http)))

but it still saved the %comment:% tag and from from what I read I couldn’t figure out how to get a tags value to paste into $startswith

I want it to exclude “visit http” which is the start of %comment:% bandcamp downloads come with.

Potentially two things:

  1. Does the comment tag really include a colon at the end of the tag name?

  2. Get rid of the space in front of " visit http" in your test.

Assuming the trailing colon is correct, you might try something like:

$if(%comment:%,$if($startswith(%comment:%,visit http),,$left(%comment:%,64)))

Note that this is just off the top of my head and hasn’t been tested, so it may need a bit of tweaking (e.g.: case sensitive). Please let us know if this helps address your issue, and if not, what it seems to be doing (or not doing) wrong.

By looking at your code I managed to trial and error my way to

$if($ne($startswith(%comment:%,Visit http),1),($left(%comment:%,64)))

which works

putting %comment:% at the start of $if(

$if(%comment:%,$ne etc.

just returns 1 which was led me astray a few times.

In regards to %comment:% yes musicbrainz interprets the %comment% tag as %comment:% for some reason and it only works if it’s fetched as that.

I guess I should have included a bit of an explanation of what I initially proposed. That may have made your trial and error work a little less painful. Maybe it will help the next person reading this thread, so here goes:

  • The first $if statement checks for the existence of a %comment:% tag.

  • If the first $if is true, the second $if is processed, checking if the contents of the %comment:% tag begins with “visit http”, as specified in the true (then) clause of the first $if statement.

  • If the second $if is true, nothing happens because the true (then) clause is empty in the second $if statement.

  • If the second $if is false, then the first 64 characters of the %comment:% tag are output, as specified in the false (else) clause in the second $if statement.

  • If the first $if is false (i.e.: no %comment:% tag exists or it is empty) then nothing is output because no false (else) clause for the first $if statement has been specified.

In any event, it’s good to hear that you ended up with something that works for you. That’s the main thing. Thanks for letting us know.

2 Likes

Your script helped enough.

With what I had gotten to work didn’t actually fully work, if it had no comment tag at all it would just write () so I combined what you wrote with what I had gotten to work

$if(%comment:%,$if($ne($startswith(%comment:%,Visit http),1),($left(%comment:%,64))))

and now it works like it should

1 Like

Excellent. Thanks for the update.