Yeah that’s it. I’m posting my mods to your script if someone wanna try.
$noop(
########################################################################
# #
# Picard File Naming Script 2022-10-14 #
# Bob Swift [rdswift] #
# #
# License: GPLv3.0 #
# #
########################################################################
# #
# This script relies on the following inputs provided by the #
# "Additional Artists Variables" plugin: #
# #
# Album Variables #
# #
# _artists_album_primary_std - The primary / first album artist #
# listed [standardized] #
# _artists_album_primary_sort - The primary / first album #
# artist listed [sort name] #
# _artists_album_all_std - All album artists listed #
# [standardized], separated with strings provided from #
# the release entry #
# _artists_album_all_sort - All album artists listed #
# [sort names], separated with strings provided from #
# the release entry #
# _artists_album_all_sort_primary - The primary / first album #
# artist listed [sort name] followed by all additional #
# album artists [standardized], separated with strings #
# provided from the release entry #
# #
# Track Variables #
# #
# _artists_track_primary_cred - The primary / first track artist #
# listed [as credited] #
# _artists_track_additional_cred - All track artists listed [as #
# credited] except for the primary / first artist, #
# separated with strings provided from the track entry #
# _artists_track_all_cred - All track artists listed #
# [as credited], separated with strings provided from #
# the track entry #
# #
########################################################################
)
$noop(
########################################################################
# #
# User Settings: #
# #
# _PaddedDiscNumMinLength - Minimum length to pad disc numbers #
# _PaddedTrackNumMinLength - Minimum length to pad track numbers #
# _aTitleMaxLength - Maximum length of album title in file name #
# _tTitleMaxLength - Maximum length of track title in file name #
# _tFilenameMaxLength - Overall maximum length of track file name #
# #
# #
# Processing Flags [set to '1' to include or '' to omit]: #
# #
# _aTitleReleaseYear - Add the release year to the title #
# _aTitleDisambig - Add the disambiguation to the title #
# _aTitleLabel - Add the label information to the title #
# _aTitleCatalog - Add the catalogue number to the title #
# #
########################################################################
)
$set(_PaddedDiscNumMinLength,1)
$set(_PaddedTrackNumMinLength,2)
$set(_aTitleMaxLength,200)
$set(_tTitleMaxLength,200)
$set(_tFilenameMaxLength,259)
$set(_aTitleReleaseYear,)
$set(_aTitleDisambig,)
$set(_aTitleLabel,)
$set(_aTitleCatalog,)
$noop(
########################################################################
# #
# Constants #
# #
# _cUnknownArtistID - MBID of "Unknown Artist" #
# _cVariousArtistID - MBID of "Various Artists" #
# _cUnknownArtist - Text to use for "Unknown Artist" #
# _cVariousArtist - Text to use for "Various Artists" #
# _cUnknownAlbum - Text to use for unknown album title #
# _cNoTitle - Text to use for unknown track title #
# _cClassical - Text to use for path to classical albums #
# _cSoundtrack - Text to use for path to soundtrack albums #
# _cSingles - Text to use as album title for singles by an artist #
# _cOther - Text to use for path to other albums #
# #
########################################################################
)
$set(_cUnknownArtistID,125ec42a-7229-4250-afc5-e057484327fe)
$set(_cVariousArtistID,89ad4ac3-39f7-470e-963a-56509c546377)
$set(_cUnknownArtist,[Unknown Artist])
$set(_cVariousArtist,[Various Artists])
$set(_cUnknownAlbum,[Unknown Album])
$set(_cNoTitle,[Unknown Title])
$set(_cClassical,[Classical])
$set(_cSoundtrack,[Soundtracks])
$set(_cOther,[Other])
$noop(
########################################################################
# #
# RegEx Constants #
# #
########################################################################
)
$set(_reCaseInsensitive,\(?i\))
$noop(
########################################################################
# #
# Variables used for processing, set to defaults if "Additional #
# Artists Variables" plugin not loaded or metadata is missing: #
# #
# _nFAA - All album artists [standard] #
# _nPAA - Primary album artist [standard] #
# _nFAAS - All album artists [sort] #
# _nPAAS - Primary album artist [sort] #
# _nFAAPS - All album artists [primary artist sort] #
# _nPTA - Primary track artist [credited] #
# _nATA - Additional track artists [credited] #
# _nFTA - All track artists [credited] #
# _nAN - Album title #
# _nANT - Album title [with additional information added later] #
# _nTN - Track title #
# _nTNT - Track title [with additional information added later] #
# #
########################################################################
)
$set(_nFAA,$if2(%_artists_album_all_std%,%albumartist%,%_cUnknownArtist%))
$set(_nPAA,$if2(%_artists_album_primary_std%,%albumartist%,%_cUnknownArtist%))
$set(_nFAAS,$if2(%_artists_album_all_sort%,%albumartistsort%,%_cUnknownArtist%))
$set(_nPAAS,$if2(%_artists_album_primary_sort%,%albumartistsort%,%_cUnknownArtist%))
$set(_nFAAPS,$if2(%_artists_album_all_sort_primary%,%albumartistsort%,%_cUnknownArtist%))
$set(_nPTA,$if2(%_artists_track_primary_cred%,%artist%,%_cUnknownArtist%))
$set(_nATA,%_artists_track_additional_cred%)
$set(_nFTA,$if2(%_artists_track_all_cred%,%artist%,%_cUnknownArtist%))
$set(_nAN,$if2(%album%,%_cUnknownAlbum%))
$set(_nANT,$if2(%album%,%_cUnknownAlbum%))
$set(_nTN,$if2(%title%,%_cNoTitle%))
$set(_nTNT,$if2(%title%,%_cNoTitle%))
$noop(
########################################################################
# #
# Replace special characters in the album and track artists used in #
# the output file path and name. #
# #
# Note that some of these replacements may revert back to an #
# underscore because of processing for Windows compatability. #
# #
########################################################################
)
$foreach(_nFAA; _nFAAS; _nPAA; _nPAAS; _nFAAPS; _nPTA; _nATA; _nFTA,
$set(%_loop_value%,$rreplace($get(%_loop_value%),[_],•))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[*],-))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[/],\u2571))
$set(%_loop_value%,$rreplace($get(%_loop_value%),:, \u2236))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[?],!))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[`´‘’ʻ""“”],'))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[.]3,…))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[.]2_,…)))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[._]*\$,))
$noop(
########################################################################
# #
# Replace special characters in the album and track title used in #
# the output file path and name. #
# #
# Note that some of these replacements may revert back to an #
# underscore because of processing for Windows compatability. #
# #
########################################################################
)
$foreach(_nAN; _nANT; _nTN; _nTNT,
$set(%_loop_value%,$rreplace($get(%_loop_value%),[_],•))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[*],-))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[:], \u2236))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[?],!))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[`´‘’ʻ""“”],'))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[.]3,…))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[.]2_,…)))
$set(%_loop_value%,$rreplace($get(%_loop_value%),[._]*/\$],))
$noop(
########################################################################
# #
# Initialize Working Variables #
# #
########################################################################
)
$set(_nMedia,%media%)
$set(_nTotalDiscs,$if2(%totaldiscs%,1))
$set(_nDiscNum,$if2(%discnumber%,1))
$set(_nTotalTracks,$if2(%totaltracks%,1))
$set(_nTrackNum,$if2(%tracknumber%,1))
$set(_nAlbumArtistID,$if2(%musicbrainz_albumartistid%,%_kUnKnownArtistID%))
$set(_nInitial,~ $upper($firstalphachar(%_nFAAPS%,#)) ~/)
$noop(
------------------------------------------------------------------------
- If standardized primary album artist is different from credited -
- primary track artist [other than prefix] show in track file name. -
- Otherwise, show any additional credited track artists in track -
- file name. -
------------------------------------------------------------------------
)
$set(_tAlbumArtist,$lower($delprefix(%_nPAA%)))
$set(_tTrackArtist,$lower($delprefix(%_nPTA%)))
$if($and($eq(%_tAlbumArtist%,%_tTrackArtist%),$not($eq(%_nAlbumType%,Standalone))),
$set(_nFeat,$if(%_nATA%, feat. %_nATA%,)),
)
$noop(
------------------------------------------------------------------------
- Calculate the maximum lengths for disc and track numbers and set -
- the desired padding lengths. -
------------------------------------------------------------------------
)
$set(_TotalDiscNumberLength,$len($if2(%totaldiscs%,1)))
$set(_TotalTrackNumberLength,$len($if2(%totaltracks%,1)))
$set(_DiscPadLength,$if($gt(%_TotalDiscNumberLength%,%_PaddedDiscNumMinLength%),%_TotalDiscNumberLength%,%_PaddedDiscNumMinLength%))
$set(_TrackPadLength,$if($gt(%_TotalTrackNumberLength%,%_PaddedTrackNumMinLength%),%_TotalTrackNumberLength%,%_PaddedTrackNumMinLength%))
$noop(
------------------------------------------------------------------------
- Automatically pad disc and track numbers to the length of the -
- total number of discs and tracks. -
------------------------------------------------------------------------
)
$set(_PaddedDiscNum,$num($if2(%discnumber%,1),%_DiscPadLength%))
$set(_PaddedTrackNum,$num($if2(%tracknumber%,1),%_TrackPadLength%))
$noop(
------------------------------------------------------------------------
- Set the year for the release -
------------------------------------------------------------------------
)
$set(_nYear,
$if($gt($left($if2(%originaldate%,%originalyear%,%date%),4),1400),
$left($if2(%originaldate%,%originalyear%,%date%),4).))
$noop(
------------------------------------------------------------------------
- Add the disc number to the track number if there is more than one -
- disc in the album. -
------------------------------------------------------------------------
)
$set(_nTNum,$if($gt(%_nTotalDiscs%,1),%_PaddedDiscNum%-,)%_PaddedTrackNum%)
$noop(
------------------------------------------------------------------------
- Add disambiguation, release year, label and catalog number to -
- the album title information as available and enabled in the -
- "User Settings" section. Use the first value there is more than -
- one specified in the metadata. -
------------------------------------------------------------------------
)
$set(_nDisambig,$if($and(%_releasecomment%,%_aTitleDisambig%), \(%_releasecomment%\),))
$set(_nTitleExtra,)
$if(%_aTitleLabel%,$if(%label%,
$setmulti(_temp,%label%)
$set(_nTitleExtra,$getmulti(%_temp%,0))
)
)
$if(%_aTitleCatalog%,$if(%catalognumber%,
$setmulti(_temp,%catalognumber%)
$set(_nTitleExtra,$trim(%_nTitleExtra% $getmulti(%_temp%,0)))
)
)
$if(%_aTitleReleaseYear%,$if(%date%,
$set(_temp,$left(%date%,4))
$if($ne([%_temp%],%_nYear%),
$if(%_nTitleExtra%,$set(_nTitleExtra,%_nTitleExtra%\,))
$set(_nTitleExtra,$trim(%_nTitleExtra% %_temp%))
)
)
)
$if(%_nTitleExtra%,$set(_nTitleExtra, [%_nTitleExtra%]))
$set(_nANT,%_nANT%%_nDisambig%%_nTitleExtra%)
$noop(
------------------------------------------------------------------------
- Trim the album and track names used to create directories and -
- tracks if they are longer than the maximum lengths set in the -
- "User Settings" section. -
------------------------------------------------------------------------
)
$if($gt($len(%_nANT%),%_aTitleMaxLength%),$set(_nANT,$left(%_nANT%,$sub(%_aTitleMaxLength%,3))...))
$if($gt($len(%_nTNT%),%_tTitleMaxLength%),$set(_nTNT,$left(%_nTNT%,$sub(%_tTitleMaxLength%,3))...))
$noop(
########################################################################
# #
# Set Album Type [Single, Soundtrack, Classical, Other or Standard] #
# #
########################################################################
)
$noop(
------------------------------------------------------------------------
- Set to "Soundtrack" if one of the secondary release types is -
- 'soundtrack'. Also add the track artist to the track title. -
------------------------------------------------------------------------
)
$if($or($in(%_secondaryreleasetype%,soundtrack),$in(%genre%,Soundtrack)),
$set(_nAlbumType,Soundtrack)
)
$noop(
------------------------------------------------------------------------
- Set to "Other" if one of the secondary release types is 'other'. -
- Also add the track artist to the track title. -
------------------------------------------------------------------------
)
$if($in(%releasetype%,other),
$set(_nAlbumType,Other)
$set(_nFeat,%_nFTA%)
)
$noop(
------------------------------------------------------------------------
- Set to "Classical" if one of the genres is 'Classical' and the -
- album type is not already set. Also add the composer or primary -
- track artist to the track title. -
------------------------------------------------------------------------
)
$if($and($in(%genre%,Classical),$not(%_nAlbumType%)),
$set(_nAlbumType,Classical))
$noop(
------------------------------------------------------------------------
- Set to "Standalone" if only one song. -
------------------------------------------------------------------------
)
$if($and($eq($matchedtracks(),1),$not($in(%_secondaryreleasetype%,soundtrack)),$not($in(%genre%,Soundtrack))),
$set(_nAlbumType,Standalone),
$set(_nFeat,$if(%_nATA%,feat. %_nATA%,)))
$noop(
------------------------------------------------------------------------
- Set to "No Album" if no album. -
------------------------------------------------------------------------
)
$if($eq(%_nAN%,%_cUnknownAlbum%),
$set(_nAlbumType,Unknown Album))
$noop(
------------------------------------------------------------------------
- Set to "Standard" if processing type is not already set. -
------------------------------------------------------------------------
)
$set(_nAlbumType,$if2(%_nAlbumType%,Standard))
$noop(
##################################################################################
# #
# Set the file path and name in accordance with the specified processing type. #
# #
# Process as Classical #
# Format: /[Classical]/Album Artist/[year] Album/Disc-Track [Composer] Title #
# #
# Process as Other #
# Format: /[Other]/[year] Album/Disc-Track Title [Artist] #
# #
# Process as Soundtrack #
# Format: /[Soundtrack]/[year] Album/Disc-Track Title [Artist] #
# #
# Process as Single #
# Formats: /~ A ~/Album Artist/[~Singles~]/[year] Title [feat.] #
# #
# Process as Standard #
# Formats: /~ A ~/Album Artist/[year] Album/Disc-Track Title [feat.] #
# /~ # ~/Album Artist/[year] Album/Disc-Track Title [feat.] #
# /[Various Artists]/[year] Album/Disc-Track Title [Artist] #
# /[Unknown Artists]/[year] Album/Disc-Track Title [Artist] #
# #
##################################################################################
)
$noop(
------------------------------------------------------------------------
- Set the file path. -
------------------------------------------------------------------------
)
$if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nFAAS%/%_nYear% %_nANT%/))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFilePath,%_cSoundtrack%/%_nANT% [%_nPAA%]/))
$if($eq(%_nAlbumType%,Other),$set(_nFilePath,%_cOther%/%_nYear%. %_nANT%/))
$if($eq(%_nAlbumType%,Standalone),
$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
$set(_nFilePath,%_nPTA%/),
$set(_nFilePath,%_nPAA%/)))
$if($eq(%_nAlbumType%,Unknown Album),
$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
$set(_nFilePath,%_nPTA%/),
$set(_nFilePath,%_nPAA%/)))
$if($eq(%_nAlbumType%,Standard),
$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
$set(_nFilePath,%_cVariousArtist%/%_nANT%/),
$if($eq($if2(%musicbrainz_albumartistid%,%_cUnknownArtistID%),%_cUnknownArtistID%),
$set(_nFilePath,%_cUnknownArtist%/%_nANT%/))
$set(_nFilePath,%_nPAA%/%_nYear% %_nANT%/)))
$noop(
------------------------------------------------------------------------
- Set the file name. -
------------------------------------------------------------------------
)
$if($eq(%_nAlbumType%,Classical),$set(_nFileName,%_nTNum%. %_nTNT%))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFileName,%_nTNum%. %_nTNT% %_nFeat%))
$if($eq(%_nAlbumType%,Other),$set(_nFileName,%_nTNum%. %_nTNT%))
$if($eq(%_nAlbumType%,Standalone),
$set(_nFileName,%_nTNT%%_nFeat% $if($or($in(%_nANT%,EP),$in(%_nANT%, \(single\))),,[%_nANT%])))
$if($eq(%_nAlbumType%,Unknown Album),$set(_nFileName,%_nTNT% %_nATA%))
$if($eq(%_nAlbumType%,Standard),$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
$set(_nFileName,%_nTNum%. %_nTNT% [%_nFTA%]),
$set(_nFileName,%_nTNum%. %_nTNT% %_nFeat%)))
$noop(
------------------------------------------------------------------------
- Trim the file name if it is longer than the maximum length set in -
- the "User Settings" section. -
------------------------------------------------------------------------
)
$if($gt($len(%_nFileName%),%_tFilenameMaxLength%),$set(_nFileName,$left(%_nFileName%,$sub(%_tFilenameMaxLength%,3))...))
$noop(
########################################################################
# #
# Output the path and file name to use. #
# #
########################################################################
)
$set(OutputPath,%_nFilePath%)
$set(OutputFileName,%_nFileName%)
$rreplace(%_nFilePath%/%_nFileName%,[?*:\\_]+,_)
$noop(
########################################################################
# #
# End of script. #
# #
########################################################################
)
Added more character replacements.
Added naming categories for Unknown Albums and Standalone files (only one track per album) :
- Skip album folder creation for those, instead parse album name to filename in brackets (unless EP/Single)
- Remove track number, use primary track artist (esp useful if you have a song you could only match through Various Artists compilation, but you have only one song from this comp = it’ll use track artist instead).
Reworked categories naming :
- Date is “2001.” instead of “[2001]”
- If no date then nothing shows instead of [0000].
- No initials or sortname (except on classic where i do use sortname).
- Extended maximum lengths.
Maybe other stuff.
Now i’m gonna work on making it a genre library, not sure how i’ll go at it. Probably try to define a genre list in order that fits me, for example check for classic, then rock, then electronic etc.