This is based on a subset of my naming script, but I think it will do most of what you want. I believe that all of the elements are there, but they may be in a slightly different order so you might have to move the various bits around. It processes soundtracks, singles, various artists compilations and “normal” albums differently, and saves them to a slightly different structure as:
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]
Note that one of the elements relies on a plugin that I wrote which is not (yet) in Picard’s list of standard plugins. It is called Additional Artists Variables and is available for download from my GitHub repository. There is also a User Guide available, which includes some examples of how the plugin could be used.
Here’s the script. Note that I haven’t tested this, so it might need some tweaking to do exactly what you’re after:
$noop(
#######################################################################
#
# Picard File Naming Script for krishk 2019-02-14
# Prepared by: rdswift
#
# License: GPLv3.0
#
#######################################################################
#
# This script relies on inputs provided by the "Additional Artists
# Variables" plugin. This plugin is freely available for use under
# GPL-2.0 or later, and the latest version can be downloaded from the
# author's repository at:
#
# https://github.com/rdswift/picard-plugins/raw/2.0_RDS_Plugins/plugins/additional_artists_variables/additional_artists_variables.zip
#
#######################################################################
)
$noop(
#######################################################################
#
# Constants
#
#######################################################################
)
$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(_cSingles,[~Singles~])
$set(_aTitleMaxLength,65)
$set(_tTitleMaxLength,65)
$set(_tFilenameMaxLength,120)
$noop(
#######################################################################
#
# Defaults if "Additional Artists Variables" plugin not loaded or metadata is missing
#
#######################################################################
)
$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(
-----------------------------------------------------------------------
- Trim the album and track names used to create directories and tracks
- if they are longer than the maximum lengths set in the "Constants"
- 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(
#######################################################################
#
# 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($eq(%_tAlbumArtist%,%_tTrackArtist%),
$set(_nFeat,$if(%_nATA%, [feat. %_nATA%],)),
$set(_nFeat, [%_nFTA%])
)
$set(_nYear,[$left($if2(%originaldate%,%originalyear%,%date%,0000),4)])
$set(_nTNum,$if($gt(%_nTotalDiscs%,1),$num(%_nDiscNum%,2)-,)$num(%_nTrackNum%,2))
$noop(
#######################################################################
#
# Set Album Type [Single, Soundtrack or Standard]
#
# 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]
#
#######################################################################
)
$set(_t1,1=)
$set(_t1,%_t1%$if($lte(%_nTotalDiscs%,1),Y,N))
$set(_t1,%_t1%$if($lte(%_nTotalTracks%,1),Y,N))
$set(_t1,%_t1%$if($in(%_primaryreleasetype%,single),Y,N))
$if($eq(%_t1%,1=YYY),$set(_nAlbumType,Single))
$set(_t2,2=)
$set(_t2,%_t2%$if($eq(%_nAlbumArtistID%,%_cVariousArtistID%),Y,N))
$set(_t2,%_t2%$if($in(%_secondaryreleasetype%,soundtrack),Y,N))
$if($eq(%_t2%,2=YY),$set(_nAlbumType,Soundtrack))
$set(_nAlbumType,$if2(%_nAlbumType%,Standard))
$noop(
#######################################################################
#
# Set File Path
#
#######################################################################
)
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFilePath,%_cSoundtrack%/%_nYear% %_nANT%/))
$if($eq(%_nAlbumType%,Single),$set(_nFilePath,%_nInitial%/%_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%/%_nFAAPS%/%_nYear% %_nANT%/)
)))
$noop(
#######################################################################
#
# Set File Name
#
#######################################################################
)
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat%))
$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 "Constants" section.
-----------------------------------------------------------------------
)
$if($gt($len(%_nFileName%),%_tFilenameMaxLength%),$set(_nFileName,$left(%_nFileName%,$sub(%_tFilenameMaxLength%,3))...))
$noop(
#######################################################################
#
# Output the path and file name to use.
#
#######################################################################
)
%_nFilePath%/%_nFileName%
$noop(
#######################################################################
#
# End of script.
#
#######################################################################
)
I hope this helps.
EDIT: Before anybody tells me that the code could be tightened up and shortened by combining things like the album type testing, I already know that. I tried to write this as generically as possible so that it could be (relatively) easily modified to suit a particular desired output. That’s also why I tried to create each of the naming “elements” first, and then just assemble them in the desired order at the end. Hopefully the various comments throughout will help anyone wanting to use this as a starting point for their own file naming script.
EDIT: I just realized that this might be more appropriate in the Repository for neat file name string patterns and tagger script snippets thread. @Freso, if you agree, can you please move it? Thanks.