So after the rabbit hole of scripting, I ended up thinking up a bunch more rules:
- Separate [A Capella] parent folder for acapella (like college groups or The Sing Off), identified by a tag that I set with a separate script run manually
- [Soundtrack] parent folder for soundtracks
- [Various Artists] parent folder for compilations
- Use sort order artist name for the folder (“Beatles, The”, or “Joel, Billy”)
- Remove featured artists from folder name (“Bob feat. Joe” → “Bob”)
- Put the release year before the album title so they sort in chronological order (soundtracks or compilations put the year last so they sort by name)
- Flag singles/EPs with an indicator after the year
- Omit album folder and track number if only one album track is present
- When the artist doesn’t match the album artist, add the artist to the track name
- Add [YYYY Remaster] showing the year for remastered tracks (see note at bottom of this post)
- Add [live] for live recordings
- Replace special characters Windows doesn’t like, or which cause confusion, such as curly quotes, question marks, colons (and use two single quotes instead of a double quote)
Result is something like this:
> [Various Artists] > Album [Year] > 01 TrackName.mp3
> Artist > [Year] Album > 01 TrackName.mp3
> Artist > [Year-Single] Album > 01 TrackName [ArtistName] [live].mp3
> Artist > StandaloneTrack.mp3
I ended up setting a bunch of variables up front to reduce the complexity of the actual naming part. Here’s the full script I ended up with:
$noop(Renaming script... some special rules
- If Grouping=acapella, use folder [A Capella] -- can use 'Tag as acapella' tagger script but ** DON'T LEAVE IT ON **
- If release type contains 'soundtrack', use folder [Soundtrack]
- If album artist is 'Various Artists', use folder [Various Artists]
- Use sort order artist name, and remove 'feat. xxx' and 'vs. xxx'
- Prepend [year] to album title, or append [year] in the case of soundtrack/various artist
- If releasetype is 'single' or 'ep', add -Single or -EP to the year, so it sorts after that year
- If only one matched track, omit album and track number [originally also used: or if 2 or less matched tracks AND that's <= 25 percent of the total]
- If the album artist doesn't match the artist, include the artist in the track name
- If RemasterDate tag is present, add [nnnn Remaster] suffix
- If release type contains 'live', append [live] to title
- Special character replacements: Remove'?', quote => double single quote, colon => dash with spaces
Examples:
[A Capella]/ArtistName/[Year] AlbumName/01 TrackName.mp3
[Soundtrack]/AlbumName [Year]/01 TrackName.mp3
[Soundtrack]/AlbumName [Year]/StandaloneTrack.mp3
[Various Artists]/AlbumName [Year]/01 TrackName [ArtistName].mp3
[Various Artists]/AlbumName [Year]/StandaloneTrack [ArtistName].mp3
ArtistName/StandaloneTrack.mp3
ArtistName/[Year] AlbumName/01 TrackName.mp3
ArtistName/[Year-Single] AlbumName/01 TrackName [ArtistName].mp3
)
$noop(Some derived boolean values)
$set(_various,$eq(%albumartist%,Various Artists))
$set(_soundtrack,$in(%releasetype%,soundtrack))
$set(_live,$in(%releasetype%,live))
$set(_showArtistFolder,$not($or($get(_various),$get(_soundtrack))))
$set(_dateFirst,$get(_showArtistFolder))
$set(_showArtistInTitle,$or($and(%_multiartist%,$ne(%artist%,%albumartist%)),$get(_various)))
$set(_standalone,$lte($matchedtracks(),1))
$noop($set(_standalone,$or($lte($matchedtracks(),1),$and($lte($matchedtracks(),2),$lte($div($mul($matchedtracks(),100),%_totalalbumtracks%),25)))))
$set(_hideAlbumFolder,$and($get(_showArtistFolder),$get(_standalone)))
$set(_showAlbumFolder,$not($get(_hideAlbumFolder)))
$set(_showTrackNumber,$not($get(_standalone)))
$noop(Derive artist name and tweak for folder name)
$set(_artist,$rreplace($if2(%albumartistsort%,%artistsort%,%albumartist%,%artist%), \([Ff]eat\\.\).+\$|\(vs\\.\).+\$,))
$set(_artist,$rreplace($get(_artist),\\.\$,))
$noop(Adjust special characters in album name)
$set(_album,%album%)
$set(_album,$replace($get(_album),: , - ))
$set(_album,$replace($get(_album),?,))
$set(_album,$replace($get(_album),“,''))
$set(_album,$replace($get(_album),”,''))
$set(_album,$replace($get(_album),",''))
$set(_album,$replace($get(_album),’,'))
$set(_album,$rreplace($get(_album),\\.\$,))
$noop(Adjust special characters in song title)
$set(_title,%title%)
$set(_title,$replace($get(_title),: , - ))
$set(_title,$replace($get(_title),?,))
$set(_title,$replace($get(_title),“,''))
$set(_title,$replace($get(_title),”,''))
$set(_title,$replace($get(_title),",''))
$set(_title,$replace($get(_title),’,'))
$set(_dateInfo,$if(%date%,[$left(%date%,4)$if($in(%releasetype%,single),-Single)$if($in(%releasetype%,ep),-EP)]))
$set(_trackNumber,$if($get(_showTrackNumber),$if($gt(%totaldiscs%,1),$if($gt(%totaldiscs%,9),$num(%discnumber%,2),%discnumber%)-,)$if($and(%albumartist%,%tracknumber%),$num(%tracknumber%,2) ,)))
$noop(The actual naming is here)
$if($eq($get(Grouping),acapella),[A Capella]/)
$if($get(_soundtrack),[Soundtrack],$if($get(_various),[Various Artists],$get(_artist)))/
$if($get(_showAlbumFolder),$if($get(_dateFirst),$get(_dateInfo) )$get(_album)$if($not($get(_dateFirst)), $get(_dateInfo))/)
$get(_trackNumber)$get(_title)$if($get(_showArtistInTitle), [%artist%])$if($get(RemasterDate), [$get(RemasterDate) Remaster])$if($get(_live), [live])
$noop(Enable this by changing "," to "1," to show debug details in the bottom panel of the script editor)
$if(,[TEST=$get(_standalone) $get(genre): $matchedtracks() of %_totalalbumtracks% = $div($mul($matchedtracks(),100),%_totalalbumtracks%)\%])
A note about remasters: I have a lot of files purchased from Amazon that say things like “[2018 Remaster]” in their title, and I bought them specifically because they sound better (I know that’s not always the case, but a lot of things were mixed pretty badly in the 80’s). So I want to know this, but MusicBraniz typically doesn’t track it.
So here’s what I did: I made a script (not a naming script) that I run manually when tracks are in the Picard “middle panel” (select all, right-click run scripts…). The script is called “Set RemasterDate from title [run before match]”. It needs to be run from that panel, because once it is matched to a release in the right panel, the original title is no longer available for scripting. This script uses regular expressions to extract the year from any title that contains the word “Remaster” (a year before that word, after that word, or just the year of the release if the title doesn’t mention a year). The result is stored in a custom tag called RemasterDate, which the above naming script uses to add “[YYYY Remaster]” back to the end of the track name.
$if($in($get(title),Remaster),$set(RemasterDate,$if2($rsearch($get(title),\(\\d{4}\) Remaster),$rsearch($get(title),Remaster?e?d \(\\d{4}\)),$left(%date%,4))))
So now I have everything just as I would like it (at least until I find the next thing I want to tweak). Cool!