I made a post about this a couple of years ago but it didn't get much traction. So I've fleshed out what I'm talking about in hopes of clarifying the idea.
We now have the ability to name our format strings in the Manage history... dialog. I'd like to be able to reference those format strings inside other format strings, treating them as building blocks for more complex naming rules.
Below is the format string I currently use, formatted and commented for clarity. As you can imagine, now that it's gotten this complex it's really hard to maintain:
G:\music\$replace(
# Members of a Series go in a top-level "(Series)/Series Name" directory
# Various-Artist compilations go in a top-level "(Various)" directory
# Everything else goes in "<first letter of artist>/<artist>" (respecting
# sort order if defined
$if(%comment series%,
'(Series)\'%comment series%,
$if($eql($left(%albumartist%,7),Various),
'(Various)',
$if(%albumartistsort%,
$left(%albumartistsort%,1)\%albumartistsort%,
$if(%albumartist%,
$left(%albumartist%,1)\%albumartist%,
$left(%artist%,1)\%artist%
)
)
)
)
'\'
# Now we're creating the subdirectory for the album itself, starting
# with the album name for Series/Various, otherwise the artist name.
$if($or(%comment_series%,$grtr($strstr(%albumartist%,Various),0)),
$if2(%comment albumtitlemain%,%album%),
$if2(%albumartist%,%artist%)
)
# Now we add the release date to the directory name
$if($not(%year%),
' -',
' ['
$iflonger($left(%releasetime%,10),
$len($left(%year%,10)),
$left(%releasetime%,10),
$left(%year%,10)
)
']'
)
# Then the album subtitle, if present, for Series/Various releases, or
# the album name otherwise
$if($or(%comment_series%,$grtr($strstr(%albumartist%,Various),0)),
$if(%subtitle%,
' '%subtitle%,
),
$if(%comment albumtitlemain%,
' '%comment albumtitlemain%$if(%subtitle%,'โ'%subtitle%,),
' '%album%
)
)
'\'
# Now we're in the directory where we're going to put the actual files
$if($eql(%_extension%,flac),
# The FLAC version of the album is named the same as the directory
# but we also add which disc to the FLAC name for multidisc sets
$if($or(%comment_series%,$grtr($strstr(%albumartist%,Various),0)),
$if2(%comment albumtitlemain%,%album%),
$if2(%albumartist%,%artist%)
)
$if($not(%year%),
' - ',
' ['
$iflonger($left(%releasetime%,10),
$len($left(%year%,10)),
$left(%releasetime%,10),
$left(%year%,10)
)
']'
)
$if($or(%comment_series%,$grtr($strstr(%albumartist%,Various),0)),
$if(%subtitle%,
' '%subtitle%,
),
$if(%comment albumtitlemain%,
' '%comment albumtitlemain%$if(%subtitle%,'โ'%subtitle%,),
' '%album%
)
)
$if($grtr(%totaldiscs%,1),
' [CD'%discnumber%' of '%totaldiscs%']',
),
# If the file is NOT a FLAC, it's assumed to be a track.
# Tracks in multidisc sets start with the disc number
$if(%discnumber%,
$num(%discnumber%,2)'.',
)
# and then the track number
$if(%track%,
$num(%track%,2)' ',
)
# and if it's a Various-Artists disc we prepend the artist name
# (the colon is replaced by the $replace() statement we're in)
$if($grtr($strstr(%albumartist%,Various),0),
%artist%': ',
)
$if2(%titlesort%,%title%)
),
# And finally we replace any Windows-illegal characters from any of
# the tags with Windows-legal (often Unicode) versions
",'''',
': ',โ,
' / ','; ',
'/','-',
':','ยท'
)
You can see how often I'm repeating blocks of formatting code for generating the release date, the directory/FLAC name, etc. I'd like to be able to store these code blocks as named blocks and pull them in as needed. (Assume the below is a set of format strings defined in the Manage history... list, the comments are the names of those strings in the list, and the syntax %[FormatStringName]% recursively pulls in the code block with that name:)
# TopLevelDirectory
$if(%comment series%,
'(Series)\'%comment series%,
$if($eql($left(%albumartist%,7),Various),
'(Various)',
$if(%albumartistsort%,
$left(%albumartistsort%,1)\%albumartistsort%,
$if(%albumartist%,
$left(%albumartist%,1)\%albumartist%,
$left(%artist%,1)\%artist%
)
)
)
)
# VariousOrSeries
$or(%comment_series%,$grtr($strstr(%albumartist%,Various),0))
# ReleaseDate
$if($not(%year%),
' -',
' ['
$iflonger($left(%releasetime%,10),
$len($left(%year%,10)),
$left(%releasetime%,10),
$left(%year%,10)
)
']'
)
# DirectoryOrFLACName
$if(%[VariousOrSeries]%,
$if2(%comment albumtitlemain%,%album%),
$if2(%albumartist%,%artist%)
)
%[ReleaseDate]%
$if(%[VariousOrSeries]%,
$if(%subtitle%,' '%subtitle%,),
$if(%comment albumtitlemain%,
' '%comment albumtitlemain%$if(%subtitle%,'โ'%subtitle%,),
' '%album%
)
)
# DiscXofY
$if($grtr(%totaldiscs%,1),' [CD'%discnumber%' of '%totaldiscs%']',)
# TrackName
$if(%discnumber%,$num(%discnumber%,2)'.',)
$if(%track%,$num(%track%,2)' ',)
$if($grtr($strstr(%albumartist%,Various),0),%artist%': ',)
$if2(%titlesort%,%title%)
# CharacterReplacements
",'''',': ',โ,' / ','; ','/','-',':','ยท'
Now the main code block becomes:
G:\music\$replace(
%[TopLevelDirectory]%
'\'
%[DirectoryOrFLACName]%
'\'
$if($eql(%_extension%,flac),
%[DirectoryOrFLACName]%%[DiscXofY]%,
%[TrackName]%
),
%[CharacterReplacements]%
)
This would make life sooooooo much easier, and seems relatively straightforward to implement, you just need to detect improper nesting that causes infinite recursion.
Would love to hear peoples' thoughts on this.