MusicBrainz Picard / Documentation / Scripting

This page describes the simple scripting language implemented in MusicBrainz Picard.

Contents

Syntax

The syntax is derived from Foobar2000's titleformat. There are three base elements: text, variable and function. Variables consist of alpha-numeric characters enclosed in percent signs (e.g. %artist%). Functions start with a dollar sign and end with an argument list enclosed in parentheses (e.g. $lower(...)).

To use parenthesis or commas as-is inside a function call you must escape them with a backslash.

Metadata Variables

See Picard tags for list of usable variables.

Technical Variables

%_extension%

Functions

$if(if,then,else)

$if2(a1,a2,a3,...)

$lower(text)

$upper(text)

$left(text,num)

$matchedtracks()

Added in version 0.12

$right(text,num)

$num(num,len)

$replace(text,search,replace)

$rsearch(text,pattern)

$rreplace(text,pattern,replace)

$in(x,y)

$inmulti(x,y)

$unset(name)

$set(name, value)

Note: To create a variable which can be used for the file naming string, but which will not be written as a tag in the file, prefix the variable name with an underscore.  %something% will create a "something" tag; %_something% will not.

$setmulti(name, value, separator="; ")

$setmulti(genre,$lower(%genre%))
. (Since Picard 1.0)

$get(name)

$copy(new,old)

$copymerge(new,old)

$trim(text[,char])

$add(x,y)

$sub(x,y)

$div(x,y)

$mod(x,y)

$mul(x,y)

$or(x,y)

$and(x,y)

$not(x)

$eq(x,y)

$ne(x,y)

$lt(x,y)

$lte(x,y)

$gt(x,y)

$gte(x,y)

$noop(...)

$len(text)

$performer(pattern="",join=", ")

$firstalphachar(text,nonalpha="#")

$initials(text)

$truncate(text,length)

$firstwords(text,length)

$swapprefix(text,*prefixes="A","The")

$delprefix(text,*prefixes="A","The")

Tagger Script Examples

OptionsOptions...AdvancedScripting

Tagger Script usually creates, modifies or deletes metadata variables.

Artist names

$if($search(%album%,(feat. conductor)),
  $set(artist,%orchestra%))

Live tracks on live albums

$if($and($eq(%releasetype%,live),$not($in(%title%,\(live\)))),$set(title,%title% \(live\)))

Remove "feat." from track titles

$set(title,$rreplace(%title%,\\s\\\(feat. [^\)]+\\\),))

Convert triple-dot to ellipsis

$set(title,$replace(%title%,...,…))
$set(album,$replace(%album%,...,…))

This one is useful for people concerned about correct typography and also fixes one problem on Linux: if an album (assuming it's also a directory) is called something like "...for you!", it is considered hidden and therefore might be not accessible from some applications.

Remove "Various Artists" on compilations

By default, Picard marks various-artist compilations with an album artist called "Various Artists". Even if you don't have anything by Torsten Pröfrock, it still means that you player will sort your comps between Vangelis and VCR instead of down at the end, which you may not want.

This is easy to fix:

$if($and($eq(%compilation%,1), $eq(%albumartist%,Various Artists)), $unset(albumartist) $unset(albumartistsort))

Merge writers into both composer and lyricist tags

Supported from version 1.0

Suppose you want to add anyone involved in writing to both the composer and lyricist tags.

$copymerge(composer,writer)
$copymerge(lyricist,writer)
$unset(writer)


File Naming Examples

OptionsOptions...File naming

Lower case filenames with underscores

$lower($replace(%albumartist%/%album%/$num(%tracknumber%,2) %title%, ,_))

(Year) only if available

$if(%date%,\($left(%date%,4)\))

Use a different naming pattern for NATs

$if($eq([non-album tracks],%album%),[non-album tracks]/%tracknumber%. %artist% - ,%artist% - $if(%date%, $left(%date%,4) )- %album%/%tracknumber%.)%title%

Result:

Organize by alphabetical folders excluding leading The

To keep music organized by initial letter of artist's name you must first set the directory where saved files are to be stored in Options --> Moving Files. Then under Options --> File Naming check Rename files when saving. This script will then move saved files to your Moving Files location using the following hierarchy:
Result:

for Various Artists-Albums

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

$left($if2(%albumartistsort%, %artistsort%),30)/
$if(%date%,$left(%date%,4)) - $left(%album%,40) \(%releasestatus%-%releasetype%\)/
$left(%album%,30) \(%releasestatus%-%releasetype%\)-$if($gt(%totaldiscs%,1),$if2(%media%,CD)%discnumber%-,)$num(%tracknumber%,2)-$left(%title%,30)

,
$upper($firstalphachar($if2(%albumartistsort%, %artistsort%),#))
/$left($if2(%albumartistsort%, %artistsort%),18)/
$if(%date%,$left(%date%,4)) - $left(%album%,40) \(%releasestatus%-%releasetype%\)/
$left(%album%,30) \(%releasestatus%-%releasetype%\)-$if($gt(%totaldiscs%,1),$if2(%media%,CD)%discnumber%-,)$num(%tracknumber%,2)-$left(%title%,30)

)