$noop( ######################################################################## # # # Picard File Naming Script 2022-12-03 # # 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 # # # ######################################################################## # # # For tagging and filing classical music using the Classical file # # naming scheme, a user script must be enabled that sets the # # _isClassical processing flag. This script can be a single line: # # # # $set(_isClassical,1) # # # ######################################################################## ) $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 # # _aExtension - Add separate directores under the album directory # # for each music file extension processed # # _aNoArtistSort - Do not sort the album artist name in the file # # path rather than the default of sorted # # _aSortOnFirstName - Sort / group based on album artist first name # # rather than the default last name # # # ######################################################################## ) $set(_PaddedDiscNumMinLength,1) $set(_PaddedTrackNumMinLength,2) $set(_aTitleMaxLength,65) $set(_tTitleMaxLength,65) $set(_tFilenameMaxLength,120) $set(_aTitleReleaseYear,) $set(_aTitleDisambig,) $set(_aTitleLabel,) $set(_aTitleCatalog,) $set(_aExtension,) $set(_aNoArtistSort,) $set(_aSortOnFirstName,) $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(_cSingles,[~Singles~]) $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, $noop( Disabled Replacements: $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, $noop( Disabled Replacements: $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%,%_cUnknownArtistID%)) $set(_nInitial,~ $upper($firstalphachar($if(%_aSortOnFirstName%,$delprefix(%_nPAA%),%_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($eq(%_tAlbumArtist%,%_tTrackArtist%), $set(_nFeat,$if(%_nATA%, [feat. %_nATA%],)), $set(_nFeat, [%_nFTA%]) ) $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,[$left($if2(%originaldate%,%originalyear%,%date%,0000),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 "Single" if the primary release type is 'single' AND there - - is only one disc AND there is only one track in the release. - ------------------------------------------------------------------------ ) $if($and($in(%_primaryreleasetype%,single),$lte(%_nTotalDiscs%,1),$lte(%_nTotalTracks%,1)),$set(_nAlbumType,Single)) $noop( ------------------------------------------------------------------------ - Set to "Soundtrack" if one of the secondary release types is - - 'soundtrack'. Also add the track artist to the track title. - ------------------------------------------------------------------------ ) $if($in(%_secondaryreleasetype%,soundtrack), $set(_nAlbumType,Soundtrack) $set(_nFeat, [%_nFTA%]) ) $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 the %_isClassical% variable is set. Also - - add the composer or primary track artist to the track title. - ------------------------------------------------------------------------ ) $if(%_isClassical%, $set(_nAlbumType,Classical) $set(_nFeat, [$if2(%TrackComposer%,%_nPTA%)]) ) $noop( ------------------------------------------------------------------------ - Set to "Standard" if not 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. - ------------------------------------------------------------------------ ) $noop( $if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nFAAPS%/%_nYear% %_nANT%/)) ) $if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nYear% %_nANT%/)) $if($eq(%_nAlbumType%,Soundtrack),$set(_nFilePath,%_cSoundtrack%/%_nYear% %_nANT%/)) $if($eq(%_nAlbumType%,Other),$set(_nFilePath,%_cOther%/%_nYear% %_nANT%/)) $if($eq(%_nAlbumType%,Single),$set(_nFilePath,%_nInitial%/$if(%_aNoArtistSort%,%_nPAA%,%_nPAAS%)/%_cSingles%/)) $if($eq(%_nAlbumType%,Standard),$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%), $set(_nFilePath,%_cVariousArtist%/%_nYear% %_nANT%/), $if($eq($if2(%musicbrainz_albumartistid%,%_cUnknownArtistID%),%_cUnknownArtistID%), $set(_nFilePath,%_cUnknownArtist%/%_nYear% %_nANT%/), $set(_nFilePath,%_nInitial%/$if(%_aNoArtistSort%,%_nFAA%,%_nFAAPS%)/%_nYear% %_nANT%/) ))) $if(%_aExtension%,$set(_nFilePath,%_nFilePath%/$upper(%_extension%))) $noop( ------------------------------------------------------------------------ - Set the file name. - ------------------------------------------------------------------------ ) $if($eq(%_nAlbumType%,Classical),$set(_nFileName,%_nTNum%%_nFeat% %_nTNT%)) $if($eq(%_nAlbumType%,Soundtrack),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat%)) $if($eq(%_nAlbumType%,Other),$set(_nFileName,%_nTNum% %_nTNT%)) $if($eq(%_nAlbumType%,Single),$set(_nFileName,%_nYear% %_nTNT%%_nFeat%)) $if($eq(%_nAlbumType%,Standard),$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. # # # ######################################################################## ) $noop( $set(OutputPath,%_nFilePath%) $set(OutputFileName,%_nFileName%) ) $rreplace(%_nFilePath%/%_nFileName%,[?*:\\_]+,_) $noop( ######################################################################## # # # End of script. # # # ######################################################################## )