Let us explain this mask
ifnotempty2(albumartist,artist,'/')
+ ifnotempty(album,'/')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
+ title
The forward slashes (/) indicate a folder separator, we use forward slash in the mask regardless of if running on MacOS Linux (that use forward slash in filesystem) or Windows (that use backslash). If using Windows when the mask is actually used SongKong will automatically convert the forward slash to a backslash.
Javascript Syntax
The plus sign (+) just means add this to the output
Anything in quotes (’’) is a literal, this just means output the value in the quotes literally as it is
albumartist, artist, discno, trackno and title are mask fields, they take their value from the equivalent metadata field in the file being processed, they are all listed in the Mask Fields dropdown.
If for a particular song a field has multiple values then they are returned to the rename mask semi-colon then space separated. For example if the Album Artists field (note the plural) contains
- Johnny Cash
- June Carter
the value returned to the rename mask would be:
Johnny Cash; June Carter
whereas the Album Artist field usually contains all albums artists as one value so this might return
Johnny Cash, June Carter
A word and then starting ( and closing brackets ) indicate a function. In this example ifnotempty2, ifnotempty, ifmultidisc and pad are functions.
Rename mask Line by Line
ifnotempty(album, '/')
Now in this rename mask we want the songs to be stored in folder structure albumartist/album and we could just naively write the rename mask as
albumartist + '/' album
However this then assumes the songs have a value for albumartist and album, but if they do not we have a problem. So instead for album we use the ifnotempty function, this write the 1st argument (album) and then the second argument (’/’) but only if 1st argument exists.
ifnotempty2(albumartist,artist,'/')
For album artist we take one step further using ifnotempty2, this function this write the 1st argument (albumartist) and then the third argument (’/’) if 1st argument exists. If 1st argument doesnt exist but second argument (artist) does it writes 2nd and then 3rd argument. If neither 1st or 2nd argument exists it writes nothing.
There are no more forward slashes so the rest of the filename mask applies to the filename
+ title
Simply add the title of the song to the output if exists
+ ifnotempty(pad(trackno,2),' - ')
This contains a function within a function, so we have to work inside out. So firstly the pad function is applied to the trackno metadata field. This ensures we output a value of at least two digits even if trackno is less then 10, i.e 2 is output as 02. Then as long as we have a value for trackno we use ifnotempty function to output the padded trackno and then ’ - ’ to separate from the title
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
This contains a function within a function within a function ! - so again we have to work inside out
So firstly the pad function is applied to the discno metadata field. Then as long as we have a value for discno we use ifnotempty function to output the padded discnono and then ’ - ’ . Then this passed to ifmultidisc function to check if we have more than one disc and only if we have more than one disc is it output.
So all the parts together output a subfolder and filename for each file based on their metadata. Then we automatically add the filename suffix (e.g .mp3, .wav) to the end of the file.