Help with Picard tagger script

Tags: #<Tag:0x00007fcb4d1ecb50> #<Tag:0x00007fcb4d1eca10>


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.

%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.

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:


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%:


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.

Help replacing special or forbidden characters
Couple of questions about file naming

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.


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