Scripting - how to set album artist only if tag is already empty/doesn't exist

Been banging my head against this for a good few hours now and figure it’s time to ask for help. I’m very new to Picard, but have been playing around with scripting over the past few days with some test files to get a hang of it.

I’ve been managing the albumartist tag pretty carefully in mp3tag for some time, but starting up on Picard it’s clear I’ve still missed it for several albums. Because of that I’m trying to do a script that will set albumartist=artist only if the tag is already empty and if it is not empty it should preserve the existing tag.

This is what I have so far, which I cannot get to work as intended as no albumartist is set:

$if($not(%albumartist%),$set(albumartist,%artist%),$unset(albumartist))

To make matters a bit more complicated I’ve also come up with a few compilation albums with no album artist and where I want the albumartist tag to stay empty. This is the solution for that, which works as intended (apparently it doesnt after all):

$if($eq(%compilation%,1),$unset(albumartist))

However, I’m unsure if these two scripts would conflict (assuming I could make both work), so I’ve also tried making one big if statement combining both. But obviously getting that to work is tricky when I cannot get the first script to work on its own.

Any insight in to what I’m doing wrong would be much appreciated :slight_smile:

You don’t need scripting to do this. Just set the albumartist tag to the list of preserved tags. Then it will be set with MB data only if it is not yet in the file.

With scripting in the current version you can’t check whether a tag exist in the file. The upcoming Picard 3 will however provide a scripting function to get the file data specifically.

4 Likes

Aah, thank you! I’ve been using the preserved tag list already, but didn’t realize it would still update if the tag is empty. That’s so much simpler than what I was trying to do.

1 Like

After fully removing the unnecessary script and using preserved tags instead I couldn’t get the other script working again (so it “working” was probably just a byproduct of the unnecessary script and it never really worked).

I was using this in order to make it not set an album artist if the compilation tag is set to 1 (true).

$if($eq(%compilation%,1),$unset(albumartist))

I can’t really see what’s wrong with the script, though. I tried changing %compilation% to %discnumber% to test the conditionals and it then unset albumartist for all songs with discnumber set to 1 - as expected. I can unfortunately not script by %releasetype% here as the album in question does not have the compilation releasetype in there. It has “soundtrack” instead and I have plenty other soundtracks where I do want to keep or set albumartist.

Any ideas?

Not sure. First thing to double check would be whether the compilation tag is really set for this release (check in the metadata list below).

Also an $unset just clears the loaded tag value. This will then usually mean that the value from the file is kept (unless “remove existing tags” is active). If the albumartiist tag was already in the files it might be shown as unchanged (as the existing value will be kept).

If you want to actively remove the existing tag from the files use $delete(albumartist) instead of the $unset.

1 Like

I verified that the compilation tag is set (and is set to “1”) in the metadata list. I also verified that it doesn’t already come with an albumartist tag (as in, it doesn’t show in the metadata list). My intention is to clear the loaded tag so I’m reasonably certain that $unset should be correct here (since it also worked in my tests before on other tags).

It does show as “Compilation (iTunes)” in the tag list, but when I click edit tag it just says “compilation”, so I assume that means the same thing?

Alternatively, would it be possible to simply check if the compilation tag is set and not verify whether it’s set to 1? I don’t set the compilation tag at all unless it should be set to 1 anyway.

Yes, that’s the same thing. Picard shows nice, translatable names in the view on the bottom, but the internal tag name in the editor.

Picard will set this to “1” itself for various artists albums, or not at all otherwise (see also Basic Tags — MusicBrainz Picard v3.0 documentation ). So this should also work:

$if(%compilation%,$unset(albumartist))

But doesn’t explain why your script didn’t work. Maybe the above also does not work then.

2 Likes

Tried your script, but unfortunately it gives the same result and nothing really happens.

I’ve gone through my scripts and plugins, but there isn’t anything that should conflict with the compilation tag at all, so I’m a bit stumped. It seems to only be that compilation tag that causes issues as replacing it with other tags appear to work just fine (for the few I’ve tried anyway).

I don’t think I have a lot of albums that should hit this issue, so for now I’ve “hacked” a solution by just forcing it to unset albumartist based on the specific album title. I can just add new albums to the script as I come across them. Not very flexible, but it works for now and I can always adjust if I can get something to trigger unset with the compilation tag later on.

Unrelated, but as someone new to Picard and these forums I very much appreciate how helpful you are, outsidecontext! Both in this thread and those made by other people that I’ve come across. Thank you!

2 Likes