Audiobook file naming from the Series and Series-Part fields ($IF statement)

Hello everyone!

I am hoping for some help with an Action to rename the audio file.

I'm working with audiobooks, which have the SERIES and SERIES-PART fields (both are TEXT) along with the normal ALBUM, ARTIST, etc fields.

I'd like to format the filename like:

<ARTIST>\<SERIES>\<SERIES-PART> - <ALBUM> (<YEAR>)\<ARTIST> - (<SERIES> - Book <SERIES-PART>) <ALBUM> (<YEAR>) - <TITLE>

This produces a folder path like:

Lois McMaster Bujold\Vorkosigan series\01 - Shards of Honor (1986)\Lois McMaster Bujold - (Vorkosigan series - Book 01) Shards of Honor (1986) - Part 01

The issue I'm having is dealing with the <SERIES-PART> field.

If <SERIES-PART> is less than 10, I'd like to have a leading 0 (zero) added, if not, then use <SERIES-PART> as is.

I've tried the following:

$if($lt($len($num(%Series-Part%,0)),10),%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2),%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))

but not matter what, the $IF evaluates as TRUE, and the first condition is always performed. So, if <SERIES-PART> is 16, the file is renamed 016 when I'd like only 16 (the FALSE condition).

To throw another wrinkle, working with <SERIES-PART> that has a decimal, ie 5.3 or 16.1. I use $NUM(%SERIES-PART%,0) to get everything before the decimal point, as my tests showed $num(16.1,0) returned 16, but no go.

How do I get the $IF to evaluate correctly so that if the <SERIES-PART> is less than 10, add a 0,

and

how to deal with <SERIES-PART> that have a decimal (again adding a 0 if <SERIES-PART> is less than 10 and keeping what is after the decimal)?

Thanks for any help!

Try $num(%series-part%,2)instead of the $if-statement.
Also check the documentation

if there is a

function. I have not found it.

$lt is a scripting function from another tagging tool: MusicBrainz Picard.

Update 14:25:
As I just learned, $lt seems also to exist in the "Mp3tag for Mac" version:

In the Windows version the same function is called $less:

Thanks for the replies!

I found $lt at https://community.mp3tag.de/t/scripting-functions/51689, but after both of you saying it isn't available I checked https://docs.mp3tag.de/scripting/ and didn't find it listed. Looking at the community post I see it was in the Mac forum, so maybe it doesn't work in Windows or was removed after that post was made.

I first tried with $num(%series-part%,x) but didn't get it working. I'll go back and try again.

Which Mp3tag version do you use?

The one for Windows (this is the correct support forum for it) or the one for Mac?

Success!

I was able to get the $IF working by using $LESS for the test condition: $if($less(%series-part%,10)

So my final action is:
$if($less(%series-part%,10),%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2)%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2),%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))

Thanks LyricsLover! I was writing this reply when you updated your message with the $LESS notation. I'm using the Windows version of MP3Tag, so $LESS is what I needed.

This works for series-part numbers in the format of X(Y).(X)(Y) ie 5, 5.3, 16, 16.1. I have a couple of audiobooks where the series-part is: 5.1-5.3 . In this case I'll have to manually make the changes as "5.1-5.3" is evaluated as bigger than 10.

Have a great day!

If this is the final code, then I think that it has th part with leading zeros twice.

$if( $less(%series-part%,10), %Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2) %Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2) ,%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))

Also, I think that the code is rather redudant in respect to parts that are the same for both cases: less than 10 and more than 9.
I think it could be:
%Artist%\%Series%\$if($less(%series-part%,10),0,)%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book $if($less(%series-part%,10),0,)%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2)

Thanks ohrenkino!

I must have copied the parts wrong when I replied. Thanks for catching the error.

Your code is certainly more optimized and overall much easier to read! It hadn't occurred to me to use $IF statements in the body of the code like you did.