Help with Picard tagger script

I’m not very good with this sort of thing, but I’ve cobbled this together so far for my naming script, but still need help to get the desired result I’m looking for.

Script:
%artist% - %album% $if(%date%,\($left(%date%,4)\))/$if($gt(%totaldiscs%,1),$num(%discnumber%,2).)$if(%tracknumber%,$num(%tracknumber%,2) -) %artist% - %album% - %title%

Right now, this outputs:
DiscNumLeadingZero.TrackNumLeadingZero - Artist - Album - Title … and places them in a directory named Artist - Album (YYYY)

What I want to get is (forgive my pseudo-code):
Directory per album: %artist% - %album% ([if exists]%Original Release YYYY% [if not]%Release YYYY%)
Tracks: DiscNumLeadingZero.TrackNumLeadingZero - Artist - Album - Title
Banned Characters: replace / with |

I just want to clean up the script, and get an if statement for the Original Release Year (YYYY) if it exists, and Release Year (YYYY) if not.

Any help is appreciated.

originaldate will always be available if a date is entered in the database. You should never have no orginal date and a date.

https://picard.musicbrainz.org/docs/tags/

So it sounds like you just need %originaldate% instead of %date%

That solves one problem, but I’ve been trying to get $replace to work to no avail.

Wrapping the entire thing with $replace($replace( **rest of script here** ,/,),_,) doesn’t seem to be working.

$replace($replace(%albumartist% - %album% $if(%originaldate%,\($left(%originaldate%,4)\))/$if($gt(%totaldiscs%,1),$num(%discnumber%,2).)$if(%tracknumber%,$num(%tracknumber%,2) -) %artist% - %album% - %title%,/,),_,)

I’m just trying to replace the ‘/’ and ‘_’ characters with nothing in both the directory name and the files.

I believe you got the syntax wrong, $replace takes 3 parameters. So that

should be
$replace( **rest of script here** ,/,_)

And of course, your full command should be edited accordingly.

Their call has three parameters: the last one is empty. They want to replace / with nothing and _ with nothing; your function call replaces / with _.

Ah, OK. It makes sense. I don’t see this in the Picard documentation.

That’s actually not as easy as using $replace in the naming script. The slash / is a special character that is used as a folder separator in the naming script. To prevent that a slash in any variable is treated as a folder separator it gets replaced in all variables before the scripting is actually executed. That means if you have %artist% set to AC/DC it will be converted to AC_DC before being processed by the script. If that would not happen you would end up with a folder hierarchy of AC > DC. But that also means you can’t use $replace in the renaming script to change it.

If you want to replace / with any other character, e.g. |, you will need to do this before the renaming script is applied. If you set the following script in Options > Advanced > Scripting it will replace any slash in the %artist% variable accordingly:

$set(artist,$replace(%artist%,/,|))

That will of course have the downside that it will also replace the / character in the tags. To fix that don’t change the %artist% variable itself but create a new one, e.g. %_artist%:

$set(_artist,$replace(%artist%,/,|))

The leading underscore in the variable name makes this a hidden variable, that will not be written to the tags. But you can use it in your renaming script (just use %_artist% instead of %artist%). If you do this for every variable you use in the renaming script you will have the result you wanted.

2 Likes

For anybody coming to this now (and since it’s been linked, there’s probably a few), just know that the order of parameters for $replace has changed: it would be $replace(%artist%,/,|) instead.

2 Likes

No, the order hasn’t changed, my post just had it wrong from the start :slight_smile: I edited my post to avoid confusion.

2 Likes