Move Creating Disc Subfolders

This action serves as an example for those of you who wish to create Disc subfolders for multi-disc albums. The intent is to relocate tracks to something approximating /basepath/Artist/Album if there is only one disc in an album. Muti-disc albums are to be organized as /basepath/Artist/Album/Disc ##. Non audio files are always moved to the Album folder.

The Artist path component will be the Album Artist field, or if empty the Artist field or if still empty, Unknown Album Artist. The Album path component will be (Year) Album. The filenames will be ##. Title where ## is the track number.

The action works in all execution modes and may contain any number of albums. It is assumed that within each album the Year, Album Artist (or Artist) metadata is consistent.

You must edit the action to set the correct destination path. Look for ********** READ THIS!!!!!! in the action.

----- Start of action 'Move Creating Disc Subfolders'

'

Assume the selected files may be in any number of albums.

The files are to be relocated to one of the two possible destinations:

/Base Path/Album Artist/(Year) Album/08. Title

or

/Base Path/Album Artist/(Year) Album/Disc 03/08. Title

Non audio files are always moved to the 'album' folder.

'

********** READ THIS!!!!!!

The next statement sets the base path to receive the 'Artist' folders when moving. This must be edited.

Set named variable 'Base Path' to "/basepath"

'

We're going to be assuming a unique album is defined by all of the metadata used to construct paths:

Album Artist (or Artist), Album and Year.

Trim the fields to avoid issues with leading or trailing spaces.

Trim Artist and 2 other fields (SP) [Leading] [Trailing]

'

Initialize 'Need Disc Folder List' to be empty.

Also initialize Variable 5 and 6 of every track to potential placeholders.

Set named variable 'Need Disc Folder List' to ""

'

Calculate Variables for each track as follows:

Variable 3 contains a track's initial folder

Variable 7 contains the effective Artist field which will be: Album Artist or Artist or Unknown Album Artist

Variable 8 contains the effective Album folder which will be: Album (Year) or Unknown Album (Year)

Variable 9 contains the 'key' used in the 'Need Disc Folder List' named variable to imply that a Disc sub-folder is required. Upon return, if a track's Variable 9 field is an item in 'Need Disc Folder List', it needs a Disc subfolder

The empty values are being filled as we want the contents of Variable 9 to represent the 'final' values.

'

The following two variables are 'fallback' values, used only if a required field is empty.

Set Variable 5 to "Unknown Album"

Set Variable 6 to "Unknown Album Artist"

'

Calculate the effective 'Artist' list and place it in Variable 7.

Use Album Artist

if empty use Artist

if empty use Variable 6 which contains Unknown Album Artist

Copy the Album Artist field to Variable 7

Copy the Artist field to Variable 7 only if empty

Copy the Variable 6 field to Variable 7 only if empty

'

Calculate the effective Album folder

Use Album

If empty use Variable 5 which contains Unknown Album Folder

The year field is read as an integer and padded to 4 characters in case it was missing.

Variable 8 will contain Album (Year)

Copy the Album field to Variable 8

Copy the Variable 5 field to Variable 8 only if empty

Copy the Year field to Variable 0

Make Variable 0 numeric padding to 4 digits

Set Variable 8 to "(\v0) \v8"

'

Calculate the key used to determine if an album needs a Disc subfolder.

Set Variable 9 to "\v7\,\v8"

'

Set Variable 3 to a track's current folder. This will be the source for the eventual Move Non Audio statement

Set Variable 3 to "\!Path to Folder!"

'

After Get Per Album Disc Information is called, the Need Disc Folder List will reference an album if it needs the Disc subfolders.

Run inline action 'Get Per Album Disc Information' grouped

'

Move the tracks one at a time

Run inline action 'Move the Tracks' grouped

'

Move the non audio files all at once. For each track the source folder is Variable 3 and the destination folder is Variable 4

Move all non audio files from Variable 3 to Variable 4 (delete original and parent folder if empty)

'

----- end of main action

Start Get Per Album Disc Information -

If a track's Disc field is > 1 create an entry in the Need Disc Folder List named variable

The action sets 4 variables:

Variable 3 contains a track's initial folder

Variable 7 contains the effective Artist field which will be: Album Artist or Artist or Unknown Album Artist

Variable 8 contains the effective Album folder which will be: Album (Year) or Unknown Album (Year)

Variable 9 contains the 'key' used in the 'Need Disc Folder List' named variable to imply that a Disc sub-folder is required. Upon return, if a track's Variable 9 field is an item in 'Need Disc Folder List', it needs a Disc subfolder

'

If the disc number is greater than 1, add the key to the list

Test if the numeric value of the Disc field > "1" (Set result)

if true

Add "\v9" to the end of the list in named variable 'Need Disc Folder List' delimiter "⏎", if not in list (case insensitive)

endif

'

----- end of Get Per Album Disc Information

Start Move the Tracks -

Move a single Track

'

See if we need a Disc subfolder. We do this by checking the list we created.

Test if the list in named variable 'Need Disc Folder List' delimiter "⏎" has an item equalling case insensitive "\v9"

if false

'

There was no entry for this 'album' so we do not need a Disc subfolder. Save any changes to the files

Save all files if modified

'

Move the files to the pre-calculated folders

Move to \<Base Path>/Variable 7/Variable 8/<TrackPad2. Title>

'

Variable 4 is where we want the non audio files moved. Save the track's new full path. The Move Non Audio statement is smart enough to remove the filename.