Hello. I have trouble with $if(x,y,z)
Often the artist is indicated in the title of the track, you need to transfer it to the artist tag. It can be done this way. Example:
Andy Moor - Trespass (feat. Sue McLaren) (Masoud Chill Out Mix)
Action format value:
Field: ARTIST
Format string: $if($regexp(%title%,'.*?\((feat..*?)\).*?','$1')
But how to set the condition that the action is performed only if there are brackets with the performer in title. If you apply this action in the case when there are no brackets with the artist in the title, then the title is copied to the artist's name. How to make sure that if there are no brackets with the performer in the track title, the action is not performed?
Test for the presence of the brackets first:
$ifgreater($strstr(%title%,'('),0,....
I'm just curious:
How should Mp3tag distinguish between the performer names "Sue Mclaren" and "Masoud"?
Are you sure that the performer name that you want to be transfered from TITLE to ARTIST exists always and only in the first pair of brackets following the word feat. ?
BTW: Your above regular expression $if($regexp... doesn't work for me with your example. It does not extract anything from the TITLE field to the ARTIST field. It would also overwrite whatever currently exists in ARTIST.
Something like
$ifgreater($strstr(%title%,'('),0,$regexp(%title%,'.*?\((feat..*?)\).*?','$1'),WhatElse)
could basically work and check for the position of an opening bracket.
If such a position is greater then 0 (= opening bracket exists in TITLE) then the regular expression would be executed. If the position is 0 (= opening bracket does not exist in TITLE), then WhatElse would be used.
Thank you. I found the solution to copie performer from TITLE to ARTIST:
Action 1: Format value:
Field: ARTIST
Format string: %artist% $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1')
It works in cases:
Trespass (feat. Sue McLaren) (Masoud Chill Out Mix)
Trespass feat. Sue McLaren
Trespass (Masoud Chill Out Mix) (feat. Sue McLaren)
Trespass (Masoud Chill Out Mix) feat. Sue McLaren
The next two actions delete preformer from TITLE and shall be arranged one after the other strictly in this order
Action 2: Replace with regular expressions:
Field: TITLE
Regular explression: \(*feat. .*?\)* \(
Replace matches with: (
Action 3: Replace with regular expressions:
Field: TITLE
Regular explression: \(*feat. .*?\)*$
Replace matches with:
Probably, ACTION 2 and ACTION 3 can be combined into one common ACTION using |, but the problem is that in ACTION 2 there is a replacement for (, and in ACTION 3 a replacement for nothing
Finaly, the problem present in cases where the performer is not specified in TITLE, in such cases TITLE is completely copied to ARTIST ![]()
You can do this by using the regex twice in your action. First to check if the match is not equal to the field that you match on (brackets are present) and then to perform the actual replacement that you wish to perform if they are not equal. If they are equal, the current content of the field is retained. This works because the regex returns the field it is matched against in the case that no match was found by default.
It's quite wordy and I really wish there was a simple way to say: Abort the action/change nothing if the regex does not match.
I have described the problem and the workaround I'm using in this thread.
Here's my latest example of this workaround:
Action type: Format value
Field:
MUSICBRAINZ_ALBUMTYPE
Format string:
$if($neql($regexp(%ALBUM%,.* \'['EP\']'.*,EP,0),%ALBUM%),$regexp(%ALBUM%,.* \'['EP\']'.*,EP,0),$meta_sep(MUSICBRAINZ_ALBUMTYPE,\\))
This action checks if ALBUM contains [EP] and sets the MUSICBRAINZ_ALBUMTYPE to EP if it does. If ALBUM does not contain [EP], the release type is set to its current value(s).
Why are there 3 commas here?:
$regexp(%ALBUM%,.* \'['EP\']'.*,EP,0)
I thought the formula should have this scheme:
$regexp(%...%,'...','...')
What does 0 mean?
I am confused
TITLE: Blue Way feat. Anna (Aerotek Remix)
ARTIST:Amir Farhoodi
Format value:
Field:ARTIST
Format string:$if($eql($regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%title%),%artist% $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%artist%)
Why$eql($regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%title%) returns false (not true) and nothing happens, %artist% copies to %artist%?
But $neql($regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%title%) returns true and %artist% $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1') copies to %artist%?
I think mistake is somewhere here: $eql($regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%title%)
I don't fully understand how to specify equality of the first value $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1') with the second value %title%
As you can see here:
$regexp(x,e,r,c)replaces the pattern specified by the regular expression e in the string x by r. The optional fourth parameter c enables ignore case (1) or disables the ignore case setting (0). Please note that you have to escape comma and other special characters in e.
The 0 simply means that the match is case sensitive (wich it already is by default, but it also doesn't hurt to explicitly state it).
So far I had not checked your regex and I'm not sure that I understand what you want to achieve.
In this example:
With your regex:
Amir Farhoodi would get replaced by feat. Anna. Wouldn't it make more sense to append feat. Anna to get Amir Farhoodi feat. Anna as the result?
You should also note that you have to escape . if you want to match a literal dot like this \..
$if($neql($regexp(%TITLE%,'^.*?\(?(feat.*?)\)?(?:\s\(.*?)?$',$1,0),%TITLE%),$regexp(%TITLE%,'^.*?\(?(feat.*?)\)?(?:\s\(.*?)?$',%ARTIST% $1,0),$meta_sep(ARTIST,\\))
After changing up your regex a bit and fixing the syntax, this one does append feat. Anna to the artist for your given example.
Do note that it will append the artist again, should you re-run the action on its own.
After running it twice you'd have Amir Farhoodi feat. Anna feat. Anna.
Yes, this job does first action:
ARTIST
%artist% $regexp(%title%,'.*?\(?(feat\.?.*?)\)?(\s\(.*?)?$|$','$1')
This action works on its own when performed separately (no convention or other), it copies feat. Anna from TITLE to ARTIST
Then one of two actions (depending on whether feat. Anna is located in front of the bracket or at the end of the TITLE) remove feat. Anna from TITLE
The goal is that the first action is performed only if the performer is in TITLE with:
$if($eql($regexp(%title%,'.*?\(?(feat.*?)\)?(\s\(.*?)?$|$','$1'),%title%),%artist% $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%artist%)
But it does not work yet, because $eql does not return TRUE, I don't know why
And finally, then you need to work on combining 2 and 3 actions into one action, I think this can be done with the something like that: $if($eql(1,2,$if($eql(1,2,%artist%))
Found the mistake:
$if($eql($regexp(%title%,'.*?\(?(feat.*?)\)?(\s\(.*?)?$|$','$1'),%title%),%artist% $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%artist%)
Must be:
$if($eql($regexp(%title%,'.*?\(?(feat.*?)\)?(\s\(.*?)?$|$','$1')=%title%),%artist% $regexp(%title%,'.*?\(?(feat..*?)\)?(\s\(.*?)?$|$','$1'),%artist%)
But now it copies full TITLE to ARTIST if there is no **feat **in TITLE
It's a pity really that you never reacted to @LyricsLover's and my suggestion.
You can test a format string (including regular expressions) with the preview in Convert>Tag-Tag.
That preview may also help to develop the full expression step by step.
Thank you, I will test. I apologize for deviating from the topic
