SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

Examples of advanced scripts

Hi Paul,
Thank you for the great software! I purchased pro versions of SongKong and Jaikoz to improve my music library.
I’m trying to learn scripting and would like to see examples from other users. For example, my current task is to make a script for a large batch of individual albums. The script would look at the artist/album artist metadata, create an artist directory if it doesn’t exist, and then move the entire album directory into it. It would not change anything else. The original album directory name would stay the same.

Where do I start?

So your want to use the Rename Files task, for a couple of fies can you give their current file path please.

Here are two examples:
X:\Sort\SK Test\ [1966] Revolver (1966 Parlophone PCS 7009 Original UK Tube Cut Stereo Pressing) [24-96]

X:\Sort\SK Test\Absolute Elsewhere - In Search of Ancient Gods (1976) [FLAC] {~2003, Tachika Records WBRK CD56192}

Hi, so in SongKong and Jaikoz we split the filepath into three parts

  • Base Folder
  • Sub Folder
  • Filename

In your first example the Base Folder is X:\Sort\SK Test, the Sub Folder is [1966] Revolver (1966 Parlophone PCS 7009 Original UK Tube Cut Stereo Pressing) [24-96], you dont show filename but lets assume it would be something like 01 - Taxman.wav

The Rename Files task can use a filename mask to replace the values of SubFolder and Filename, you can also configure to Rename filename part Only to only replace the Filename, but we dont currently have the option to Rename Subfolder Only which is what you ideally want.

image

Your request is an unusual one because usually new filepaths are constructed purely from metadata within the file, this ensures they are consistently named. But in your case you would like keep the album and filename component of the existing filepath but insert a folder based on albumartist/artist, and I can see why because you have alot of information encoded in the album part of the filename.

I had a go at creating filename mask in Preferences:Filename Masks that could be used by Filename Renamer as follows

function filepathFilenameComponent()
{
	var file = filename.substring(filename.lastIndexOf('/') + 1);
	return file;
}

function filepathAlbumComponent()
{
	var subFolderPath = filename.substring(0, filename.lastIndexOf('/'));
        var albumComponent = subFolderPath.substring(subFolderPath.lastIndexOf('/') + 1);
	return albumComponent;
}

ifnotempty2(albumartist, artist,'/') + filepathAlbumComponent() + "/" + filepathFilenameComponent();

Note we use ‘/’ to specify a folder seperator on both Windows and Unix so that masks work on either system, but on Windows the ‘/’ is converted to ‘\’ behind the scenes.

Unfortunately there is an issue, when metadata fields are extracted from the file we clean the value, this means that occurrences of / and \ are replaced with ’ - '. This makes sense for metadata values because if metadata contains slash (e.g AC/DC) we dont want use of that value to split into two folders, but when parsing filename we need to know where the separators are.

So this rename mask does not work, it runs if you replace filename.lastIndexOf(’/’) with filename.lastIndexOf(’ - ')

function filepathFilenameComponent()
{
	var file = filename.substring(filename.lastIndexOf(' - ') + 1);
	return file;
}

function filepathAlbumComponent()
{
	var subFolderPath = filename.substring(0, filename.lastIndexOf(' - '));
        var albumComponent = subFolderPath.substring(subFolderPath.lastIndexOf(' - ') + 1);
	return albumComponent;
}

ifnotempty2(albumartist, artist,'/') + filepathAlbumComponent() + "/" + filepathFilenameComponent();

but the trouble with this method is if the filepath already contains ’ - ’ such as if the filename was 01 - Taxman.wav this gets picked up instead and you end up with splitting the album

image

So I have raised a bug to fix this https://jthink.atlassian.net/browse/SONGKONG-2648 for next release, should be within a few weeks.

The alternative is to use a standard rename mask constructed from songs metadata , you can also use metadata from matching MusicBrainz/Discogs release if the songs have been matched to these. This should be able to generate something similar to your existing album component if not exactly the same.

e.g basic example to give some idea (doesnt check for empty values ectera)

ifnotempty2(albumartist,artist,'/')
+ ifnotempty(mb_release 
+ '(' 
   + mb_release_year + ' ' 
   + mb_comment 
+ ')' 
+ '[' 
+ audioformat + ' ' 
+ audiobitrate
+ ']' 
+ '{'
+ mb_catno
+ '}'
,'/')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
+ title

Thank you—this explanation is very helpful. I’ll watch for the next release. In the meantime, I’m trying to use ChatGTP to build scripts with mixed success, but it is helpful for learning.