Code: Select all
{fn=~/2160p/?'Movies 4K':'Movies'} {vc=~/HEVC|265|AV1/?(vc=='AV1'?'(AV1)':'(x265)'):'(x264)'}/{
norm = {
it.colon(' - ').tr('*?|', ' !-')
.asciiQuotes()
.replaceAll(/\b(?i)[IVX]+\b/, { it.upper() })
.replaceAll(/\b[0-9](?i:st|nd|rd|th)\b/, { it.lower() })
.replaceAll(/(Collection) of the (.+)/, /$2 $1/)
.replaceAll(/(Saga) Collection/, /$1/)
.replaceAll(/^(?i)(The|A|An|Der|Die|Das) (.+)/, /$2, $1/)
};
path = allOf { norm(collection) } { norm(n) }.join('/');
path[0].replaceAll(/\W|\d/, '#') + '/' + path}
{norm(n) != norm(primaryTitle) ? ' (' + primaryTitle + ')' : null
}{ fn =~ /3D|3-D/ ? ' 3D' : null} ({y}) {[aco.match(/ATMOS/) ? 'Atmos' : null]}
{tags*.toUpperCase()} {["$group"]}/
{ allOf {n.asciiQuotes().removeAll(/[,!]/)}{fn =~ /3D|3-D/ ? '3D' : null} {".$y"}{edition}{tags*.toUpperCase()}{'Part'+pi}{".$vf"}{".$HD"}
{ fn.match(/(?-i:ATVP|AMZN|DCU|DSNP|DSNY|Disney[+]|DisneyPlus|HBO|HULU|NF|SUBBED|Encore.Edition|Colorized|B&W|HQ)/) }
{if (bitdepth >= 10) 'HDR10'}{(hdr == 'Dolby Vision' || hdr == 'Dovi') ? '_DV' : ''}
{ HD == 'UHD' ? '4K' : '' }{".$vs"}
{vc =~ /HEVC|265|AV1/ ? (vc =~ /AV1/ ? 'AV1' : 'x265') : 'x264'}
{"$ac"}{aco.match(/ATMOS/)}{af == 8 ? 'DD+7.1CH' : af == 7 ? '6.1CH': af == 6 ? 'DD.5.1CH': af == 3 ? '2.1CH': af == 2 ? '2.0CH': (af as int) + 'CH'}.join('.').space('.')
}{'-'+group}
First I want to thank @rednoah for all the patience and Chat GPT for corrections.
Let's break down each section of the code and its purpose:
J:\{fn=~/2160p/?'Movies 4K':'Movies'}: This sets the initial file path to either "Movies" or "Movies 4K", depending on whether the file has a resolution of 2160p (4K) or not.
{vc=~/HEVC|265|AV1/?(vc=='AV1'?'(AV1)':'(x265)'):'(x264)'}: This assigns the video codec of the file to either "(AV1)", "(x265)", or "(x264)", depending on whether the codec matches "AV1", "265", or "HEVC". If the codec doesn't match any of those, it defaults to "(x264)".
{ norm = {...} }: This defines a function named "norm" that normalizes the movie title by replacing certain characters and formatting the title in a consistent way. The function is used later in the script to format both the collection and movie titles.
{ path = allOf { norm(collection) } { norm(n) }.join('/') }: This creates the file path for the movie by joining together the normalized collection and movie titles with forward slashes.
{ norm(n) != norm(primaryTitle) ? ' (' + primaryTitle + ')' : null }: If the normalized movie title does not match the normalized primary title, this section appends the primary title in parentheses to the file name. If the titles match, this section returns null.
{ fn =~ /3D|3-D/ ? ' 3D' : null }: If the file name includes "3D" or "3-D", this section appends " 3D" to the file name. If not, it returns null.
({y}): This appends the year of release to the file name in parentheses.
{[aco.match(/ATMOS/) ? 'Atmos' : null]}: If the audio codec contains "ATMOS", this section appends "Atmos" to the file name. If not, it returns null.
{tags*.toUpperCase()}: This adds any tags included in the file name in uppercase letters.
{["$group"]}: This appends the group releasing the file in square brackets.
{ allOf {...} }: This defines a new function that formats several attributes of the file name.
{n.asciiQuotes().removeAll(/[,!]/)}: This removes commas and exclamation points from the movie title and replaces any double quotes with single quotes.
{fn =~ /3D|3-D/ ? '3D' : null}: If the file name includes "3D" or "3-D", this section appends "3D" to the file name. If not, it returns null.
{".$y"}: This appends the year of release to the file name preceded by a period.
{edition}: This appends the edition of the movie, such as "Director's Cut" or "Extended Edition".
{tags*.toUpperCase()}: This adds any tags included in the file name in uppercase letters.
{'Part'+pi}: This appends the part number of a multi-part movie, such as "Part 1" or "Part 2".
{".$vf"}: This appends the video format of the movie, such as "1080p" or "2160p".
{".$HD"}: This appends the resolution
{tags*.toUpperCase()}
This section converts all the elements in the "tags" array to uppercase letters. The "tags" array is a property of the media file that contains various tags or labels that describe the file, such as the genre, language, or content rating.
{["$group"]}
This section adds the value of the "$group" variable to the end of the path. The "$group" variable is a user-defined variable that can be set to any value before running the script. It is useful for grouping related files together.
/
This section adds a forward slash character to the end of the path, separating it from the filename.
{ allOf {n.asciiQuotes().removeAll(/[,!]/)}
This section creates a new string by applying several transformations to the "n" variable. First, it replaces any curly or straight quotes with ASCII quotes. Then it removes any commas or exclamation marks from the string.
{fn =~ /3D|3-D/ ? '3D' : null}
This section adds the string "3D" to the filename if the "fn" variable contains the substring "3D" or "3-D". Otherwise, it returns null.
{".$y"}
This section adds a period character followed by the value of the "y" variable to the filename. The "y" variable is a property of the media file that contains the release year.
{edition}
This section adds the value of the "edition" variable to the filename. The "edition" variable is a user-defined variable that can be set to any value before running the script. It is useful for distinguishing different versions of the same file.
{tags*.toUpperCase()}
This section converts all the elements in the "tags" array to uppercase letters and adds them to the filename.
{'Part'+pi}
This section adds the string "Part" followed by the value of the "pi" variable to the filename. The "pi" variable is a user-defined variable that can be set to any value before running the script. It is useful for identifying which part of a multi-part file this particular file belongs to.
{".$vf"}
This section adds a period character followed by the value of the "vf" variable to the filename. The "vf" variable is a property of the media file that contains the video format.
{".$HD"}
This section adds a period character followed by the value of the "HD" variable to the filename. The "HD" variable is a property of the media file that contains the video resolution.
{ fn.match(/(?-i:ATVP|AMZN|DCU|DSNP|DSNY|Disney[+]|DisneyPlus|HBO|HULU|NF|SUBBED|Encore.Edition|Colorized|B&W|HQ)/) }
This section adds various labels to the filename based on the value of the "fn" variable. These labels indicate the source of the file, whether it has been colorized or is in black and white, whether it is a high-quality version, and other relevant information.
{if (bitdepth >= 10) 'HDR10'}
This section adds the string "HDR10" to the filename if the "bitdepth" variable is greater than or equal to 10. The "bitdepth" variable is a property of the media file that contains the bit depth of the video.
{(hdr == 'Dolby Vision' || hdr == 'Dovi') ? '_DV' : ''}
This section adds the string "_DV" to the filename if the "hdr" variable is equal to "Dolby Vision" or "Dovi". The "hdr"
{ HD == 'UHD' ? '4K' : '' }: This section checks if the variable HD is equal to 'UHD' (which stands for ultra high definition) and if it is, it returns '4K'. Otherwise, it returns an empty string.
{".$vs"}: This section simply returns the variable vs with a period before it.
{vc =~ /HEVC|265|AV1/ ? (vc =~ /AV1/ ? 'AV1' : 'x265') : 'x264'}: This section checks if the variable vc matches any of the regular expressions /HEVC|265|AV1/. If it does, it checks if vc matches the regular expression /AV1/ and if it does, it returns 'AV1'. Otherwise, it returns 'x265'. If vc doesn't match any of the regular expressions, it returns 'x264'.
{"$ac"}: This section simply returns the variable ac.
{aco.match(/ATMOS/)}: This section checks if the variable aco matches the regular expression /ATMOS/ and returns a boolean value.
{af == 8 ? 'DD+7.1CH' : af == 7 ? '6.1CH': af == 6 ? 'DD.5.1CH': af == 3 ? '2.1CH': af == 2 ? '2.0CH': (af as int) + 'CH'}: This section checks the value of the variable af and returns a string based on its value. If af is 8, it returns 'DD+7.1CH'. If af is 7, it returns '6.1CH'. If af is 6, it returns 'DD.5.1CH'. If af is 3, it returns '2.1CH'. If af is 2, it returns '2.0CH'. If af is any other integer, it returns the integer value followed by 'CH'.
.join('.').space('.'): This section joins all the string values returned from the previous sections with periods and then replaces spaces with periods.
Hopefully this will help all you newbies out there and maybe you might want to use the code as it is. I have self taught myself how to write this and am pretty happy with the outcome. As usual I am never really done with it I always tinker onward!