Help understanding Picard naming script system for noob

Hi guys, i’m new to MusicBrainz Picard and i’m trying to understand how the naming script is working and the only things i found on internet was pretty advanced stuff.

First thing first, just to understand the default value in the program :

$if2(%albumartist%,%artist%)/$if($ne(%albumartist%,),%album%/)$if($gt(%totaldiscs%,1),%discnumber%-,)$if($ne(%albumartist%,),$num(%tracknumber%,2) ,)$if(%_multiartist%,%artist% - ,)%title%

I found this :

$if2(a1,a2,a3,...)

Returns first non empty argument.

$if(if,then,else)

If if is not empty, it returns then, otherwise it returns else.

$ne(x,y)

Returns true, if x not equals y.

$gt(x,y)

Returns true, if x is greater than y.

$num(num,len)

Returns num formatted to len digits.

But i still don’t really understand what does it do.

In the end i want to move all my music into a new folder called Music and all my music sorted like that :

Music\Artist\Year - Album\TrackNumber - Title

That does’t cover the case of multi artists albums or original sound track wich i would like sorted like that :

Music\OST - MoovieName\TrackNumber - Title

Can i have only one script to do all this or do i have to write one scrit for the artist’s mucis and one for the OST?

Well that last question is not my priority.

Thank you for your help.

1 Like

You actually got pretty far with looking up and understanding the individual function. Let’s just disassemble the default script then :slight_smile:

The first part is:

$if2(%albumartist%,%artist%)/

As you said before $if2(a1,a2) will give you the first non-empty value. So in this case you will get %albumartist% if set, otherwise %artist%. %albumartist% is the artist set for the entire album, %artist% is the artist for the individual track. So this $if2 ensures the album artist is used if available so you don’t scatter e.g. a compilation across multiple folders. The slash at the end just marks a folder separator. So this little part will give us a folder name like:

The Rolling Stones/

Next

$if($ne(%albumartist%,),%album%/)

The $if(if,then,else) will give us then, in this case the album name followed by a slash (the then is omitted here). The $ne here will be true, if %albumartist is true. Easy rule: If an album artist is set, create an album name folder. I think this handles the case of standalone recordings (those without an album). Usually the album artist is set. The result combined with the previous part is this:

The Rolling Stones/Beggars Banquet/
$if($gt(%totaldiscs%,1),%discnumber%-,)

This compares the total number of discs in the collection with one. If there is more than one disc, it will output the discnumber followed by a slash, e.g. 1- or 2-. If there is only one disc on the album it will do nothing (the empty ,)). We have only one disc, so let’s move on.

$if($ne(%albumartist%,),$num(%tracknumber%,2) ,)

Similar to what we hade before this will only output something, if the album artist is not empty. In this case it will print the track number. With $num(value,2) the number will be formatted to have always 2 decimals, filled up with leading zeros. So we get something like 03 or 10:

The Rolling Stones/Beggars Banquet/01 
$if(%_multiartist%,%artist% - ,)

If this is an album with multiple artists it will output the artist name followed by a hyphen, e.g. "The Rolling stones - ". If it is only a single artist album this will be omitted.

%title%

And finally output the title. Picard will also add the proper file extension at the end, so the final result might be:

The Rolling Stones/Beggars Banquet/01 Sympathy for the Devil.mp3

A multi artist album with multiple discs could look something like this:

Various Artists/Century Media: Covering 20 Years of Extremes/2-04 The Agonist - Monochromatic Stains.mp3

So this is actually pretty close to what you want. To add the year maybe just edit the part $if($ne(%albumartist%,),%album%/) and use $left(%date%,4) - %album% instead of %album%. $left will give you just the first 4 characters of %date%, which is the year. If you want the original release year of that album (instead of the specific edition you have) use %originaldate%.

3 Likes

Wow!

Thank you very much for your answer, you’re helping me a lot!
Just breaking the default script in parts helped me understand it better.

I’m not really sure to understand how the $if works though. In the first iteration in the script there is only two variables (is it the correct word?) with one comma and you said the then is omitted, is that not the else which is omitted?

$if($ne(%albumartist%,),%album%/)

If that’s so why in all the other 3 iterations there is also only two variables but 2 commas.

$if($gt(%totaldiscs%,1),%discnumber%-,)
$if($ne(%albumartist%,),$num(%tracknumber%,2) ,)
$if(%_multiartist%,%artist% - ,)

Which seems to indicate that the then is empty.
Well i’m a little confused here.

Reading your explenation for the "multiartist if", maybe helped me to understand. In $if (the function), if if (the variable) is true, so the function write then and if if (variable) is false, the function write else. Sorry if i’m not clear, we’re talking something i don’t really understand and english is not my native tong.
If what i just said is correct then why in the first iteration the then is omitted?

For the disc number, how can we make a folder named Disc %discnumber%? Like that ?

$if($gt(%totaldiscs%,1),"Disc "%discnumber%-,)

For the track number, what happens if there is more than 99 songs in the album?

And about the date how can i write the month and the year if there is more than one album of the artist in one year and only the year if there is only one album in the year?

Thank you again for your help and sorry for my approximations.

One last thing, how do you highlight the script lines here on the forum?

See this post :slight_smile: :

Oh, some tough questions. I’ll do my best :slight_smile:

Yep, I meant the else.

Your description is correct. To be honest I am currently not sure whether there is a difference between $if(a,b) and $if(a,b,) (without and with the last comma). Until yesterday I thought the last comma is mandatory :slight_smile:

Nearly, but not exactly. Rather like this (note the leading slash, so it will actually be a folder and not part of the filename):

$if($gt(%totaldiscs%,1),"Disc "%discnumber%/,)

Again not sure, but I think it will just start using three digits, so it will be 01, 02, …, 10, 11, …, 99, 100, 101. If this is a common case for you you could of course use $num(%tracknumber%,3) to always use 3 digits. Or even do some clever scripting, maybe $num(%tracknumber%,$len(%totaltracks%)) (never tested that one).

I fear that is not possible. In scripting you can use only the metadata available for the track and the album. You can’t see how many other albums you have. But you could always use the year and month (if the month is available) with $left(%date%,7).

1 Like

Great, thank you! ^^
It seems i can’t get the taggerscript work in a quote, is that normal?

Ok perfect.

Of course ><
Thank you for that! ^^

Maybe i can find a way for the numbers to have at least two digits and more if there is more than 99 songs in the album?

I was assuming the month was in the metadata for the album. But i’m not even sure we can have the month in the metadatas?

It is a bug. :wink: