File extension in renaming files

I’m currently using this string to rename my music files in Picard:

$if(%originaldate%,$left(%originaldate%,4) )%album% ($if2(%albumartist%,%artist%))$if($not($startswith(%_format%,MPEG-1 Layer 3)), %_format%)/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) %title%

If the files are mp3, then they get “YYYY Album Title (Artist)” as their folder name but if they’re FLAC then they get “YYYY Album Title (Artist) FLAC”
That works great, but I run into problems when there are other formats, like m4a or wma. I don’t like archiving those but sometimes they’re the only version of an album that I’ve got. They should get “M4A” or “WMA” in place of FLAC. But instead they get some long thing like “Windows Media Audio” or “MPEG 4 Audio Format” That’s no good. How can I get it to just put the file extension there? (except not if it’s mp3)

Another problem is that sometimes Picard tries to give files names that are way too long. This is especially bad in classical music.

Instead of your current portion:

$if($not($startswith(%_format%,MPEG-1 Layer 3)), %_format%)


$if($eq($upper(%_extension%),MP3),, $upper(%_extension%))

I deal with this in my file naming script by saving the path and file name strings generated to temporary variables, and then trimming the length of the variables to a maximum length before assembling them to form the actual path and file name.