Conditional formatting with featured artists to add to title and filename

Hello there, my head is spinning after spending hours trying to make this work.

I filter to locate tracks I want to edit:

"$meta_sep(Artist,\\)" HAS \\

If album artist name UB40 differs from the artist name (for example UB40\Chrissie Hynde), add "(feat. Chrissie Hynde) to the title and filename. If this is done, subsequently remove Chrissie Hynde from the artist list.

Additionally, I want to add further conditional rules (I know I have mentioned these somewhere else but I am completely lost) for one or more ADDITIONAL ARTISTS. TITLE (feat. ADDITIONAL ARTIST 1, ADDITIONAL ARTIST 2 & ADDITIONAL ARTIST 3). For less than three, it would be TITLE (feat. ADDITIONAL ARTIST 1 & ADDITIONAL ARTIST 2). FILENAME would be the same except including TRACK at the start with padding (01) for example.

1=$if($neql(%artist%,%albumartist%),' (feat. %feat_artist%)','')

1=$if($neql(%artist%,%albumartist%),%title%[ (%feat_artist%)],%title%)




This might be along the right lines:

Guess value

Here is a thread about a chain of equal separators where the first should become one and the last a different one:

You only have to adapt it to your separator.

As always, thank you! I think I found the post about it.

$regexp($meta_sep(artist,', '),'(.*), (.*)',$1 & $2)
"A:\Music\UB40\03 Breakfast In Bed.mp3" ->
"A:\Music\UB40\UB40 & Chrissie Hynde.mp3"

So I can see it's picking up the right data, it just doesn't know how to manipulate it.

You refer to

$regexp($replace(%artist%, and ,', '),'(.*), (.*)','$1 and $2')
"A:\Music\UB40\03 Breakfast In Bed.mp3" ->

So I'm not sure how I move forward with this.

At the moment it's clearly picking up UB40, I want regex to ignore the first name in the artist list if it matches the name in album artist and work through anything thereafter to include in %feat_artist%.

ChatGPT suggested:

$if($eql(%artist%,%albumartist%),%title%,$if($eql($meta(artist,0),%albumartist%),%title% (feat. $meta_sep(artist,' & ')),$num(%track%,1) %title% (feat. $meta_sep(artist,' & '))))

2=$if($eql(%albumartist%,%artist%),%artist%,%artist% (feat. %albumartist%))

1=$if($eql(%artist%,%albumartist%),%title%,$if($eql($meta(artist,0),%albumartist%),%title% (feat. $meta_sep(artist,' & ')),$num(%track%,1) %title% (feat. $meta_sep(artist,' & '))))

1=$if($eql($meta(artist,0),%albumartist%),$num(%track%,1) %title%,%num(%track%,1) %title% (feat. $meta_sep(artist,', '))$if($gt($meta_num(artist),1),&, $if($gt($meta_num(artist),2),',',)) $meta_sep(artist,' & '))

It's still grabbing UB40 and ignoring Chrissie Hynde in testing though.

My prompt:

  1. The code should be used in Mp3tag to modify tags and filenames for music files.
  2. The code should check for differences between the "Artist" and "Album Artist" fields in the music files.
  3. If the "Artist" differs from the "Album Artist," the code should add "(feat. [all artists except album artist])" to the title field.
  4. If there are multiple artists in the "Artist" field, the code should handle them properly.
  5. The filename should include the track number at the beginning with 1-digit padding for track numbers 1-9.
  6. The filename should not include a hyphen.
  7. The code should use proper punctuation when there are featured artists (e.g., "feat. [artist1] & [artist2]" or "feat. [artist1], [artist2] & [artist3]").

And? Does it work? Or would support by natural intelligence bring you closer?

A good way is always: first get the data right in the tags, then create a filename from the tag data.

I would always use a filter for that. Much safer than an action that runs clandestine in the background.

How does this check deal with spelling errors? If you refer to a list of artists in the field ARTIST: how are they separated from each other?

see 3. How will you deal with groups that already have a list of artists in the name? Like Emerson, Lake & Palmer? Earth, WInd & Fire? Dave Dee, Dozy, Beaky, Mick & Tich


But... what instead? Or should it be deleted? Try: $replace(%_filename%,-,)

As 3. is still unclear, it is hard to say what to do. In general
$regexp($replace(%field%,/,','),'(.*), (.*)',$1 & $2)
to deal with the punctuation. whether a "feat" is necessary is a different case.

I do not say anything about the order of the manipulations. It could well be that steps from the end should be carried out much earlier

1 Like

Thanks for your reply.

Clearly your natural intelligence is far superior to that of AI in this instance!

If there are already artists listed with commands and &, those should retain their formatting and once & is declared, it knows the subsequent artist in the list is the last one and can then add a comma.

I think the key thing here is keeping the data in %feat_artist% before doing anything with it. Presumably if anything goes wrong, if the data is held here then it could be reversed using an action that finds matches in the filename and title and could put the names in the original format into the artist field.

Not sure what you mean about spelling mistakes.

What filter would you use?

Yep, hyphens should be deleted.

The prompt I listed is how it produced the code above the prompt, I could have made that clearer. The outcome was listed above the prompt too.

When I look at the artist list, it's divided by \\ in mp3tag. Windows shows it as:

Is it divided by ; or a space? From the other thread I know \ isn't actually something within the file and is added by mp3tag. But then adding your suggested code worked as a filter:

"$meta_sep(Artist,\\)" HAS \\

So it's not clear to me what divides the artists names up.

Then you can use the scripting function $meta_sep(fieldname,', ') to get all the artists separated by a comma or even better by a semicolon.
Then you apply the action to replace the separators and set the ampersand.

The check for ALBUMARTST and ARTIST being the same or being used for further treatment so that the string from ALBUMARTIST is compared with a substring of ARTIST to see whether they are the same only works if the spelling is the same. But if you have e.g. ABBA and Abba or Beatles and Baetles, then the comparison will not yield a match.
The result in the end would be that those files would not be treated in the way they should.

1 Like

There is "nothing" dividing the multiple ARTIST tag contents.
That dividing character you see as \\ is only to represent a visible divider between the different ARTIST contents.

Technically, there are 3 ARTIST tags in this example track:

If you would manually add \\Artist Four in the Tag Panel in the field Artist, it would end with a fourth ARTIST tag like this:

1 Like

Thanks for your reply. SO to clarify, are you saying the first action should be

Replace with regex
$meta_sep(%artist%,', ')

Then what?

Thank you for explaining about the spelling check. I am going to assume the spelling is consistent, so any regex will pick up only the correct variations. I understand there could be times it doesn't behave as needed (if there are differences in case or spelling) and that's okay.

I had come to realise \\ wasn't a real divider after seeing ohrenko's post in another thread.

I hae not said anything about that being the first action nor did I say anything about an action of the type "replace with regex".
What I said:

which is a format string and can only be applied in actions/functions that allow a format string.
If you are sure that you deal with multi-value fields, then you can leave out the $replace-part and use $meta_sep(artist,', ') as string for the regular expression-function. The regular expression then replaces the last comma with an ampersand

1 Like

Thanks for your reply, so I should make it?

$regexp($meta_sep(artist,', '),'(.*), (.*)',$1 & $2)

I don't know what I am supposed to do next, I'm not feeling particularly clever right now.

You can test the regular expression with Convert>Tag-Tag.
So check if that does what you intended to do.

1 Like

It does add & and commas correctly when there are two or more artists respectively. Still need to stop it from picking up the ALBUM ARTIST when compiling the list and insert (feat. ) before any featured artists.



wasn't the original idea to use FEAT_ARTIST as intermediate field?
So how do you fill that field?
Once you have data in that field, you can apply the punctuation regular expression to that field and set the string constants as well:
Format value for FEAT_ARTIST
Format string: (feat. $regexp($meta_sep(feat_artist,', '),'(.*), (.*)',$1 & $2))
this assumes that the check for identical ALBUMARTIST and first ARTIST has happend in the shape of a filter.
It furthermore assumes that there is only 1 artist in ARTIST and the rest in FEAT_ARTIST

1 Like

w00t! Like this?


It works in this example when there are two other artists. It doesn't work when it's only one featuring artist though.


I think I may have accidentally had another action selected when I did that as it's not producing that effect now.

It now converts the artist list only (not touching the title).




If I remove the "artist" action, this is what the %feat_artist% action does on its own within extended tags:


I don't think so.
I wonder why you read only fractions of what I write:

and you offer an action group that does not do anything like it.
That makes the whole thing absolutely longwinded.

I am missing the action that moves everything but the first ARTIST to FEAT_ARTIST.
In many cases an action of the type "Guess value" is a good idea.
Source: $regexp($meta_sep(artist,', '),'(.*?), (.*)',$1==$2)
Target string: %artist%==%feat_artist%

The non-reading part also applies to your observation:

I assumed that you still filter for more than 1 ARTIST field:

... but if you change the preconditions constantly, then this will never be successful.

1 Like

Thank you, it's not so much a lack of reading as not understanding in the same way that you do. I didn't remove the filter at any point.

Is there a way to combine the two format lines so it works on TITLE and FILENAME in one line instead or not, because I want to omit the TRACK NUMBER on titles but not _FILENAMEs?

If you want to address 2 (or more) fields, you need 2 (or more) actions.

1 Like