“Tangling” is an Org Mode feature that extracts code blocks into a
target file, see the :header-args:
metadata for this section.
Also, “noweb” variables are used between <<
and >>
, noweb variables are
expanded on the target file applying the contents of the referred to
code block.
NOTE: Indentation is done using TABs and NEWLINEs because even though
Picard doesn't seem to delete them, they should be ignored by
filesystems anyway.
Likewise any SPACE character seen in the script DOES matter and goes
to the final filename, if not held by an if statement.
$noop(
<<indentation-note>>
)
This script is used to organize and format the file names of audio tracks in MusicBrainz Picard, a free and open-source software tool for organizing and formatting audio file metadata.
This is the third iteration from an old script.
- Formats track numbers and disc numbers with leading zeros to ensure proper sorting
- Includes media formats and/or extensions in the filepath, including DSD, SACD, and Vinyl
- Allows for customization with compartmentalized variables
- Includes logic for handling tracks by various artists
To use this script in MusicBrainz Picard, follow these steps:
- Open MusicBrainz Picard and select the tracks you want to rename.
- Go to
Options
in menu bar, then clickOptions
from dropdown menu
- Select the ”
File Naming
” tab - Click the
Edit file naming script
button and add this naming script.
The script includes several variables and functions for formatting metadata fields, such as the artist name, album title, track number, and disc number:
This checks if the current release is a part of multiple discs release, add it to the album directory name with a padded number if necessary.
$set(checkPadDiscNumber
,$if2(
$if($gte(%totaldiscs%,10000), $if(%discnumber%, \(Disc $num(%discnumber%,5)\)),)
,$if($gte(%totaldiscs%,1000), $if(%discnumber%, \(Disc $num(%discnumber%,4)\)),)
,$if($gte(%totaldiscs%,100), $if(%discnumber%, \(Disc $num(%discnumber%,3)\)),)
,$if($gte(%totaldiscs%,10), $if(%discnumber%, \(Disc $num(%discnumber%,2)\)),)
,$if($gt(%totaldiscs%,1), $if(%discnumber%, \(Disc $num(%discnumber%,1)\)),)
)
)
Similar to Multi-disc release check but it always adds the track
number with at least a padding of 2, e.g. ”05
”.
$set(checkPadTrackNumber
,$if2(
$if(%_paddedtracknumber%,%_paddedtracknumber%)
,$if($gte(%totaltracks%,10000), $if(%tracknumber%,$num(%tracknumber%,5)),)
,$if($gte(%totaltracks%,1000), $if(%tracknumber%,$num(%tracknumber%,4)),)
,$if($gte(%totaltracks%,100), $if(%tracknumber%,$num(%tracknumber%,3)),)
,$if($gte(%totaltracks%,10), $if(%tracknumber%,$num(%tracknumber%,2)),)
,$if($gte(%totaltracks%,1), $if(%tracknumber%,$num(%tracknumber%,2)),)
)
)
Adds extension and media format information to the album name, including:
- sampling rate
- bit-depth
- extension
- special media (Vinyl, SACD, DSD)
$set(mediaFormatSpec
$noop(DSD is always '1bit' so only output this if greater than 1)
,$if($gt(%_bits_per_sample%,1),%_bits_per_sample%bit )
$noop(#TODO: Fix Opus output here:)
$div(%_sample_rate%,1000)$if($ne($mod(%_sample_rate%,1000),0),.$left($mod(%_sample_rate%,1000),1))kHz
$if($not($eq_any(%_extension%,dsf,dff,dsd)),$upper( %_extension%))
$if($in(%media%,Vinyl), Vinyl)
$noop(Output this before SACD because there are Vinyl rips recorded in DSD)
$if($eq_any(%_extension%,dsf,dff,dsd), DSD)
$if($in(%media%,SACD), SACD)
)
- Note: I use a special/custom tag for tracking albums that are not in
MusicBrainz’s databases. Here the following line can be added to
append a marker string to the album directory name:
if($eq(%NOT_ON_MUSICBRAINZ_DB%,true), #NOTONMBDB)
Check if release type is single
to append that to file naming
$set(getReleaseType
,$if($eq(%releasetype%,single),\(Single\))
$if($eq(%releasetype%,ep),\(EP\))
)
$set(getInitial
,$upper($left($if2(%albumartist%,%artist%),1))
)
Check if %albumartist%
is Various Artists
to use that as the artist
root directory for releases that are such.
$set(getVariousArtistsRoot
,$if($eq(%albumartist%,Various Artists),Various Artists)
)
Returns the first value of either %originalyear%
, %originaldate%
or
%date%
.
$set(getReleaseYear
,$if2(
$if(%originalyear%,$left(%originalyear%,4))
,$if(%originaldate%,$left(%originaldate%,4))
,$if(%date%,$left(%date%,4))
)
)
Truncates the album name from %album%
.
$noop( limit album name output to 120 characters )
$set(getAlbumNameTruncated
,$left( $replace(%album%,/,), 120)
)
$set(notVariousArtists
,$ne(%albumartist%,Various Artists)
)
Vinyl releases usually use a SIDE>TRACKNUMBER format like A1
, A2
, and
B3
, B4
.
$set(checkVinylTrackNumber
,$if($and($in(%media%,Vinyl),%_musicbrainz_tracknumber%),%_musicbrainz_tracknumber%)
)
Gets the first value of either %albumartist%
or, %artist%
and if it is
a multiple-artists field choose the first value, up untill the
standard separator ”;
”.
$set(getAlbumArtist
,$if2(
$noop(This searches for the first multiple artist separator `;' and truncates after it:)
$left($if2(%albumartist%,%artist%),$find($if2(%albumartist%,%artist%),;))
,$if2(%albumartist%,%artist%)
)
)
$set(getMultiChannels
,$if($gt(%_channels%,2), %_channels%Ch)
)
Complimentary of Check for special vinyl track numbering and Track number padding.
$set(getTrackNumber
,$if2(%checkVinylTrackNumber%,%checkPadTrackNumber%)
)
$set(getTitleTruncated
,$left(%title%,120)
)
Some releases have a “disc subtitle” that specify location or work.
$set(getDiscSubtitle
,$if(%discsubtitle%,\(%discsubtitle%\))
)
$set(generalFormat
,%getInitial%
/
%getAlbumArtist%
/
[%getReleaseYear%] %getAlbumNameTruncated% %getReleaseType% %checkPadDiscNumber% %getDiscSubtitle% [%mediaFormatSpec%]%getMultiChannels%
/
%getTrackNumber%. %getTitleTruncated%
)
$set(variousArtistsFormat
,[%getVariousArtistsRoot%]
/
%getAlbumNameTruncated% %checkPadDiscNumber% [%getReleaseYear%] [%mediaFormatSpec%]%getMultiChannels%
/
%getTrackNumber%. %getTitleTruncated%
)
The following $rreplace
functions delete special chars if replacing
with unicode variants using the built-in plug-in failed. Also replace
double or more spaces with just one.
$set(rreplacePattern,[:?"_*\\]+)
$set(VASanitized
,$rreplace($rreplace(%variousArtistsFormat%,%rreplacePattern%,),\\s+, )
)
$set(generalSanitized
,$rreplace($rreplace(%generalFormat%,%rreplacePattern%,),\\s+, )
)
Final format for the directory structure, obsfuscated by the variables that store it.
$if(%notVariousArtists%
,%generalSanitized%
,%VASanitized%
)
- Adapted from thebradleys’ naming script: Repository for neat file name string patterns and tagger script snippets#4
- Influenced by Fatal-Picard-Script: rickeymandraque/Fatal-Picard-Script/nocomment.picard