SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

How to create Rename masks

SongKong lets you create an edit very flexible rename masks using Javascript Expressions, via the Preferences menu.

Javascript makes things very flexible and for our purposes is quite easy, you do not have to know Javascript to use it. But because we are using standard Javaascript rather than some pseudo language only known to SongKong you can use any regular Javascript resource to help if you want to do something really complicated.

Here we give a brief overview

Each metadata field is represented by a fieldname


So to display a field just use its fieldname
i.e.
title

Values are joined using the + symbol
So to display artist and then title
i.e.
artist + title

Literal text is surrounded by apostrophe
But you probably want a space between those two values, so just add a space surrounded by apostophes
i.e.
artist + ' ' + title

Or maybe you want a hyphen with space around it
i.e.
artist + ' - ' + title

Folderpath Seperators

Rename filemask is made up of folders and then a filename, you represent the seperator between each folder and filename with the / character, because it is a literal it needs to be stored in quotes

i.e.
albumartist + '/' + album +'/' + artist + ' - ' + title

Is a mask that consists of album artist folder containing album folder and then filename comprising song artist and title.

Functions
More complex logic can make use of functions. These are defined in the User Defined Function section and can then be used by any mask

They all have the form

function functionName(parameters)
{
return result
}

e.g

function ifnotempty(value,sep){
     return value.length > 0 ? value + sep : '';
 }

The ifnotempty function is useful and used in many of the predefined rename masks. It takes a value and a separator as parameters, then it says the check the value of value and if not empty output value + sep, but if has no value output nothing.

For example here we output trackno and separator and then title but only if we have a trackno otherwise we just output title.

ifnotempty(trackno,' - ') + title

Functions within Function

A function can be called within another function, the result of the first function will become the value passed to the second function

e.g

function pad(number, length) {
   if (number == '') { return '';}
   var str = '' + number; 
   while (str.length < length) {  
      str = '0' + str;
   }
   return str;
}

ifnotempty(pad(trackno,2),' - ')`

Here the trackno is padded to two figures if it exists otherwise returns ‘’, then ifnotempty function would only output the value and separator if there was a trackno.

This should be enough information to create most rename masks.