Extract and Expand Artist and Title

This action illustrates how to extract information from file system names and how to do character manipulation.

----- Start of action 'Extract and Expand Artist, Album and Title'

'

An action to extract missing artist, album and title names from file system path components.

If the Artist field is empty the name of the folder containing the track's folder will be used as the Artist field. If the Album field is empty, the name of the folder containing the track will be used as the Album Name. If the Title field is empty the track's filename will be used as the Title field. It is assumed that both the folder and file names may be missing spaces but have capital letters for each new word. For example a track's path may be:

.../TheRollingStones/FortyLicks/Jumpin'JackFlash

The desired result is to have an Artist field of "The Rolling Stones", an Album field of "Forty Licks" and a Title field of "Jumpin' Jack Flash". Assuming the associated fields are empty.

When there are contiguous capital letters, spaces are not to be inserted between them, so that "DJ" will not become "D J". The only exception to this rule is if the first capital letter in a sequence is "A" or "I" there will be a space inserted after it. So, "AHardDay'sNight" will become "A Hard Day's Night".

Note that existing spaces are kept intact and are not discarded.

'

Trim the Title, Artist and Album fields to ensure they do not have leading or trailing spaces. We also convert sequences of multiple spaces to a single space.

Run the 'Single File' action to process each track individually.

Trim Title and 2 other fields (SP) [Leading] [Trailing] [->SP]

Run inline action 'Single File' grouped

'

Perform capitalization on the three fields in order to make them consistant. You can remove this statement if it doesn't interest you.

Case Title Case in Title and 2 other fields with names, exceptions and replacements

Start Single File -

Process a single track

'

See if the Artist field is empty.

Test if the Artist field is empty (Set result)

if true

'

If we're here, the Artist field was empty. Put the name of the parent folder into variable 1. Then run the Expand action to get the new value returned in Result. Copy Result to the Artist field.

Get Property Parent Folder Name -> Variable 1

Run inline action 'Expand' grouped

Set the Artist field to "\<Result>"

endif

'

See if the Album field is empty.

Test if the Album field is empty (Set result)

if true

'

If we're here, the Album field was empty. Put the name of the track's folder into variable 1. Then run the Expand action to get the new value returned in Result. Copy Result to the Album field.

Get Property Folder Name -> Variable 1

Run inline action 'Expand' grouped

Set the Album field to "\<Result>"

endif

'

See if the Title field is empty.

Test if the Title field is empty (Set result)

if true

'

If we're here, the Title field was empty. Put the name of the file into variable 1. Then run the Expand action to get the new value returned in Result. Copy Result to the Title field.

Get Property File Name (without extension) -> Variable 1

Run inline action 'Expand' grouped

Set the Title field to "\<Result>"

endif

Start Expand -

This action takes a string in Variable 1 and expands its contents. The result is stored in Variable 8

'

Initialize some variables used later.

Set named variable Result to empty.

Set named variable 'Last Character Was UC Alpha' to 0.

Named variable 'Prefix' is either empty or contains a space, depending on the state of the algorithm

The named variable 'Upper Case Alpha Characters' contains the list of all upper case alphabetic characters used by the expansion. If your language has other characters you want to 'trigger' on, add them to the value.

The named variable 'Exceptions' contains the lits of 'starting' alphabetic characters which allow space insertion if they are first and are immediately followed by another upper case character.

Set named variable 'Result' to ""

Set named variable 'Last Character Was UC Alpha' to "No"

Set named variable 'Prefix' to " "

Set named variable 'Upper Case Alpha Characters' to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Set named variable 'Exceptions' to "AI"

'

Call the Process action to do the expansion. The action is called for every character in Variable 1. The individual characters will be in Variable 3.

Trim leading and trailing spaces form the Result.

Repeat With Variable 3 for every character in field Variable 1 Run inline action 'Process' grouped

Trim named variable 'Result' (SP) [Leading] [Trailing] [->SP]

Start Process -

Process the character in Variable 3

'

Test if the character in Variable 3 is an upper case alphabetic character