SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

Tutorial: Rename Files, Renaming Algorithm

Index

Previous
Next

Since SongKong 12.2

Renaming files is not as simple as we might wish for, here we summarize how renaming works

Like all tasks files are processed as Logical Groups that often consist of a single folder but may also be multiple folders that seem to represent an album.

Build Rename Group from Logical Group

  • If all songs in group match to same MusicBrainz album and there no duplicate tracks put all songs in one Rename Group
  • Else if all songs match to same Discogs album and there no duplicate tracks put all songs in one Rename Group
  • Else if all songs in same folder put in one Rename Group
  • Else if in different Disc folders but same album folder put in one Rename Group
  • Else put in one Rename Group per folder.

For each Rename Group, extract folder name suffix if any (e.g foldername (2)) to preserve existing names where possible when there are clashes.

For each song within Rename Group

  • Create new name song based on rename mask
  • If on Windows or have set filepath limit check to see if filenames is too long, and if they are calculate the amount of space that need to shorten and shorten filename part as far as possible whilst respecting minimum length of filename.

For each Rename Group

  • Check for any clashes in names (i.e if have multiple duplicate songs in the rename group)
  • If any found add suffix to filename, incrementing suffix until no clash
  • If on Windows on set filepath limit check to see if any of the songs new filenames are too long, and if they are calculate the amount of space that need to shorten by to fix the longest path
  • Recover that space from parent folder so all files are kept in same folder, whilst not shortening folder below minimum size of 10 characters
  • If still unable to recover enough space check the parents parent and so on

If we have multiple Rename Groups check for clashes in folder name.
e.g if have two copies of same album they will likely resolve to same folder name if in mask folder name represents an album folder. In such case

  • Add suffix to folder name
  • Recalculate filenames from masks whilst preserving folder suffix
  • Check for any clashes in names (i.e if have multiple duplicate songs in the rename group)
  • If any found add suffix to filename, incrementing suffix until no clash

Do final check if and if unable to shorten filepaths accordingly for all songs we just set new filename back to original filename

At this point we have created new potential filenames as for all songs in logical group that are valid names and keeps songs together but we haven’t actually renamed the files yet, and at any point some external process may prevent renaming a file.

The next stage differs depending on if we doing a real rename or Preview Only rename

Real Rename
For each song:

  • Try and rename song to new filename
  • If there is a clash or other problem (e.g read only file) strip any existing suffix from new filename
  • Try and rename song to new filename
  • If there is a clash again, add suffix (1), and retry increasing suffix until able to create filename that does not already exist, unless hit max retry limit then give up
  • If rename successfully update report with details of changed filename

Preview Only
Create a map of existing name to new name
For each song:

  • Remove this song from map
  • Does new filename clash with new filename in map from another song
  • If there is a clash strip any existing suffix from new filename
  • Does new filename clash with new filename in map from another song
  • If there is a clash again, add suffix (1), and retry increasing suffix until able to create filename that does not already exist in map
  • Now add existing name to new name to map
  • Update report with details of changed filename

Previous
Next