Home User Forums SongKong Music Tagger Jaikoz Music Tagger Albunack Music Service

Thursday 14 January 2016

An even easier way to shorten audio filenames with Functions

In the previous post I showed you how you can reduce the length of the filename so less than the maximum allowed. This can be a particular problem for classical music and be useful for better compatibility with other applications.

But one problem with this approach is you have to check the length of the field first and then only substring it if its too long, because if it is not long enough substring() would give an error. This can make more complex rename masks a little unwieldy.

This code checks the album field length is greater than 100 and if it then substrings it otherwise it just outputs the value as is.

(album.length>100 ? album.substring(0,100):album)

1. So lets make this simpler by creating a function, open up your rename mask for editing and then select the Add button at the bottom of window,

2. Now create the following function as shown in the window, then select OK.

function substring(value,length){
     return value.length > length ? value.substring(0, length)  : value;

 3. Now we can use this new function in any rename mask, we simply put substring() around any value we want to limit the length of, and no longer need to check the length first.

i.e. here we use substring on albumartist, artist, title and year fields.

ifnotempty(substring(albumartist,50),' - ')
+ ifnotempty(substring(album,50),' ')
+ '(' + substring(year,4) +')/'
+ ifnotempty(pad(trackno,2),' - ')
+ ifnotempty(substring(artist,50),' - ')
+ substring(title, 50)

4. You can also use substring to simply truncate the total replaceable path by wrapping substring() around whatever you want to truncate.

i.e convert this mask:

ifnotempty2(albumartist,artist,' - ')
+ ifnotempty(album,' - ')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
+ title

to be no longer than 200 characters with:

(ifnotempty2(albumartist,artist,' - ')
+ ifnotempty(album,' - ')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
+ title),200)

No comments:

Jthink blog Jthink Facebook page google_plus Jthink YouTube channel Email Paul at Jthink Subscribe to Weekly Newsletter