Help with script for filenaming scheme

I have been trying and modifying scripts but cannot make headway. Can somebody please help me with a script for Musicbrainz Picard for the following naming scheme:

NAMING:
ARTIST: “name surname (“the” or “A”)” taken to back in brackets

SONG: ARTIST-SONG TITLE-# (feat - other artists in title) - bitrate/quality - orig date

ALBUM: “ARTIST-ALBUM TITLE-(date in brackets)-(CD1 etc only if multiple discs))

ARTIST ALBUMS:
folders for artists and subfolders for the albums
ALBUM-folder: as subfolders in that of ARTIST
loose SONGS in root of ARTIST folder

COMPILATIONS to be under “_VA”
folder “_VA” and subfolders for the albums
SubFoldername: “ALBUM TITLE-(date in brackets)-(CD1 etc only if multiple discs)

SOUNDTRACKS to be under “_ST”
folder “_ST” and subfolders for the albums
SubFoldername: “ALBUM TITLE(ST for “movie title”)-(date in brackets)-(CD1 etc only if multiple discs)”

This is not the easiest script, so let’s do it part by part and then assemble the final script:

There is a easy way, that does somewhat what you want, but without the brackets:

$swapprefix(%albumartist%)

This will result in “Beatles, The”. But you want the brackets, so try this:

$set(_albumartistprefix,$rsearch(%albumartist%,^\(The|A\)\\s+))
$if(%_albumartistprefix%,$rreplace(%albumartist%,^\(%_albumartistprefix%\)\(.*\),\\2 \(\\1\)),%albumartist%)

For easier usage later we create two hidden variables %_albumartist% and %_artist% we use for naming:

$set(_nameprefixes,The|A)
$set(_albumartistprefix,$rsearch(%albumartist%,^\(%_nameprefixes%\)\\s+))
$set(_albumartist,$if(%_albumartistprefix%,$rreplace(%albumartist%,^\(%_albumartistprefix%\)\(.*\),\\2 \(\\1\)),%albumartist%))
$set(_artistprefix,$rsearch(%artist%,^\(%_nameprefixes%\)\\s+))
$set(_artist,$if(%_artistprefix%,$rreplace(%artist%,^\(%_artistprefix%\)\(.*\),\\2 \(\\1\)),%artist%))

Not sure about some details you want, but try this one with the “Feat. Artists in Titles” installed:

%_artist%-%title%-%tracknumber% - %_bitrate% - %originaldate%

Let’s save this as a variable %_file% for better readability later:

$set(_file,%_artist%-%title%-%tracknumber% - %_bitrate% - %originaldate%)

You can still tweak some details, e.g. should track number be with leading zero or not. If it should use $num(%tracknumber%,2) instead of just %tracknumber%. Also %originaldate% is the original date of the release. We don’t have this for individual recordings. There was some discussion about this recently here. In theory it would be possible to get this with a plugin, in practice it would likely be very slow to do so.

%_albumartist%-%album%-\(%date%\)$if($gt(%totaldiscs%,1),-CD%discnumber%)

Again let’s save this as a variable %_album% for better readability later:

$set(_album,%_albumartist%-%album%-\(%date%\)$if($gt(%totaldiscs%,1),-CD%discnumber%))

The artist folder and subfolder:

%_albumartist%/%_album%/

But wou want different behavior for non-album tracks, so we add the %_album%/ part only, if album is not “[non-album tracks]”:

%_albumartist%/$if($ne(%album%,[non-album tracks]),%_album%/)

So a different folder name for VA releases. We get this by replacing the %_albumartist%/ part above with $if($eq(%compilation%,1),_VA,%_albumartist%)/ to get:

$if($eq(%compilation%,1),_VA,%_albumartist%)/$if($ne(%album%,[non-album tracks]),%_album%/)

Another case. So we use $inmulti(%releasetype%,soundtrack) to detect soundtracks. How exactly to combine this depends whether soundtracks take precedence over VA and single artist releases. The following assumes you want all your soundtracks under _ST, even if it is a soundtrack by only a single artists:

$if($inmulti(%releasetype%,soundtrack),_ST,$if($eq(%compilation%,1),_VA,%_albumartist%)/$if($ne(%album%,[non-album tracks]),%_album%/))

This is our script to name the folders.

The final scripting
Now we have the folder script, the actual file name and some helper variables to hold the more complex scripting. First add the helper variables to Options > Scripting as the following script (with $noop I just set some comments):

$noop(Move name prefixes The and A to the end in brackets. You can add additional prefixes separated by | if you want to.)
$set(_nameprefixes,The|A)

$set(_albumartistprefix,$rsearch(%albumartist%,^\(%_nameprefixes%\)\\s+))
$set(_albumartist,$if(%_albumartistprefix%,$rreplace(%albumartist%,^\(%_albumartistprefix%\)\(.*\),\\2 \(\\1\)),%albumartist%))

$set(_artistprefix,$rsearch(%albumartist%,^\(%_nameprefixes%\)\\s+))
$set(_artist,$if(%_artistprefix%,$rreplace(%artist%,^\(%_artistprefix%\)\(.*\),\\2 \(\\1\)),%artist%))

$noop(Set album name for renaming)
$set(_album,%_albumartist%-%album%-\(%date%\)$if($gt(%totaldiscs%,1),-CD%discnumber%))

$noop(The actual file name for renaming)
$set(_file,%_artist%-%title%-%tracknumber% - %_bitrate% - %originaldate%)

Then in Options > File Naming we have to assemble the final naming script by combining the folder naming with the file naming:

$if($inmulti(%releasetype%,soundtrack),_ST,$if($eq(%compilation%,1),_VA,%_albumartist%)/$if($ne(%album%,[non-album tracks]),%_album%/))%_file%

Disclaimer: I have not tested this :smiley: Please try carefully, and let us know if you need some tweaking. But this should be a good start.

4 Likes

The one problem I see with your script, @outsidecontext, is the handling of compilations. MB sets the compilation flag whenever there’s multiple artists on the release, so a Tony Bennett album with a single song credited to “Tony Bennett & Elvis Costello” will trip your “Compilation == 1” conditional. I’m assuming that @gideonjp.vanzyl is referring to VA compilations, so checking for the “Various Artists” album artist would probably be the better way to go.

2 Likes

Thanks a million @outsidecontext. I am trying this out and will let you know.
Yes Billy, I am referring to VA compilations. How would I therefore check for “Various Artists”?

To do this, you would change the one line of @outsidecontext’s code from

$if($eq(%compilation%,1),_VA,%_albumartist%)/$if($ne(%album%,[non-album tracks]),%_album%/)

to

$if($eq(%musicbrainz_albumartistid%,89ad4ac3-39f7-470e-963a-56509c546377),_VA,%_albumartist%)/$if($ne(%album%,[non-album tracks]),%_album%/)

The usual “untested code” warning applies. :wink:

3 Likes

That was only true for Picard 1.2 and earlier. Since Picard 1.3 %compilation% indicates a Various Artists release. So $eq(%compilation%,1) should have the same result as $eq(%musicbrainz_albumartistid%,89ad4ac3-39f7-470e-963a-56509c546377)

2 Likes

I did not know that. I’ll have to test it out in my script.

I noticed that neither $eq(%musicbrainz_albumartistid%,89ad4ac3-39f7-470e-963a-56509c546377) or $eq(%compilation%,1) work if the artist credit includes other artists than Various Artists. Here’s a refined line based on the one from rdswift:

$if($eq($truncate(%musicbrainz_albumartistid%,36),89ad4ac3-39f7-470e-963a-56509c546377),_VA,%_albumartist%)

The “_VA” triggers only if VA is the first artist. Here’s some example credits:

  • Varios Artistas :white_check_mark:
  • Various Artists feat. Hatsune Miku :white_check_mark:
  • Buddy Miller & Friends :x:

After looking at the VA aliases, this pattern seemed pretty consistent: If VA is first, the release is a “VA release”. If it’s not first, it’s not a “VA release”.

1 Like