Classical album split into four folders because of duplicate filenames even though mask quite simple
Forgot was using Compilation album mask that was set to include
+ ifnotempty(artist,' - ')
+ ifnotempty(album,' - ')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
so was very long, so that is why we get duplicate filenames, but can we be any cleverer about this to protect user from themselves.
If on Windows the FileNameFormatter.formatFromMask() doesnt currenlty know the length of basefolder/moved folder so we can consider this as part of the 259 total limit during formatFromMask() so we can shorten the parts as required. We need to do earlier because once we have created the mask we don't know the component that make up the filename (i.e is it artist - track -title or artist album -title etc)
Might be nice to apply more logic,. i.e if we know filename mask consists of artist-album-trackno-title we know album will be same for all tracks but trackno will be different so we must ensure we keep trackno but possibly drop albumartist.
Also we cant replace the scriptvar with an amended one before parse the mask, i.e replace filename occurence of album with shortalbum and the map this to a shorted value for the songs album. We cant do this because we cant just do search and replace for album in mask as that would also pick up albumartist, albums ectera.
For duplicate albums we currently do something where we map album to %ALBUMPLACEHOLDER% and then search and replace the result of evaluation allowing us to add albumcount for first case, but the trouble is that if any logic is applied to album in the original mask then that logic is applied to the value %ALBUMPLACEHOLDER% rather than the actual value of album in the song (e.g The Joshua Tree) and therefore not a great solution.
If we had named scriptvars %album% instead of album then find and replace on mask would have been safe to do, but making this change now would be difficult.
Maybe we could just to search and replace on the result of the new filename since we do know the name of the album ectera.but we dont have any reliable way of knowing if we have album in the filename really.
Wonder if should go ahead with replacement of nashorn (because removed in Java 15) first in case the new engine provides another option.
For now logic will be if need to shorten folder name then use the placeholder logic for album and artist. In the future may need to surround scriptvar with %'s e.g %album% so we can find and replace mask before parsing.