Difference between revisions of "MusicBrainz Picard/Documentation/Scripting"
(Add "Various Artists" script) |
(→$left(text,num): Add undocumented $matchedtracks()) |
||
Line 37: | Line 37: | ||
===$left(text,num)=== |
===$left(text,num)=== |
||
− | * Returns first <code><nowiki>num</nowiki></code> characters from <code><nowiki>text</nowiki></code>. |
+ | * Returns first <code><nowiki>num</nowiki></code> characters from <code><nowiki>text</nowiki></code>. |
+ | |||
+ | ===$matchedtracks()=== |
||
+ | |||
+ | * Returns the number of matched tracks within a release. |
||
===$right(text,num)=== |
===$right(text,num)=== |
Revision as of 00:47, 19 December 2010
This page describes the simple scripting language implemented in Picard Tagger.
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%
- Extension of the file name. For example mp3 for file 01 Track.mp3.
Functions
$if(if,then,else)
- If
if
is not empty, it returnsthen
, otherwise it returnselse
.
$if2(a1,a2,a3,...)
- Returns first non empty argument.
$lower(text)
- Returns
text
in lower case.
$upper(text)
- Returns
text
in upper case.
$left(text,num)
- Returns first
num
characters fromtext
.
$matchedtracks()
- Returns the number of matched tracks within a release.
$right(text,num)
- Returns last
num
characters fromtext
.
$num(num,len)
- Returns
num
formatted tolen
digits.
$replace(text,search,replace)
- Replaces occurrences of
search
intext
with value ofreplace
and returns the resulting string.
$rsearch(text,pattern)
- Regular expression search. This function will return the first matching group.
$rreplace(text,pattern,replace)
- Regular expression replace.
$in(x,y)
- Returns true, if
x
containsy
.
$unset(name)
- Unsets the variable
name
.
$set(name, value)
- Sets the variable
name
tovalue
.
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.
$get(name)
- Returns the variable
name
(equivalent to%name%
).
$copy(new,old)
- Copies metadata from variable
old
tonew
. The difference between$set(new,%old%)
is that$copy(new,old)
copies multi-value variables without flattening them.
$trim(text[,char])
- Trims all leading and trailing whitespaces from
text
. The optional second parameter specifies the character to trim.
$add(x,y)
- Add
y
tox
.
$sub(x,y)
- Subtracts
y
fromx
.
$div(x,y)
- Divides
x
byy
.
$mod(x,y)
- Returns the remainder of
x
divided byy
.
$mul(x,y)
- Multiplies
x
byy
.
$or(x,y)
- Returns true, if either
x
ory
not empty.
$and(x,y)
- Returns true, if both
x
andy
are not empty.
$not(x)
- Returns true, if
x
is empty.
$eq(x,y)
- Returns true, if
x
equalsy
.
$ne(x,y)
- Returns true, if
x
not equalsy
.
$lt(x,y)
- Returns true, if
x
is lower thany
.
$lte(x,y)
- Returns true, if
x
is lower than or equalsy
.
$gt(x,y)
- Returns true, if
x
is greater thany
.
$gte(x,y)
- Returns true, if
x
is greater than or equalsy
.
$noop(...)
- Does nothing (useful for comments or disabling a block of code).
$len(text)
- Returns the number of characters in text.
$performer(pattern="",join=", ")
- Returns the performers where the performance type (e.g. "vocal") matches
pattern
, joined byjoin
.
$firstalphachar(text,nonalpha="#")
- Returns the first character of
text
. Iftext
is not an alphabetic characternonalpha
is returned instead.
$initials(text)
- Returns the first character of each word in
text
, if it is an alphabetic character.
$truncate(text,length)
- Truncate
text
tolength
.
Examples
Use case 1: Disc numbers
$set(discnumber,$rsearch(%album%,\\\(disc \(\\d+\)\\\))) $set(album,$rreplace(%album%,\\s\\\(disc \\d+\\\),))
- Would it be possible to trim all of (disc 1: Subtitle Here) and also set the disc number? --AaronCooper (2007-03-07)
- You can use the plugin from Picard Plugins. --LukasLalinsky
- %totaldiscs% Doesn't really work, is there some way to fix that? --Madness
- You can use the plugin from Picard Plugins. --LukasLalinsky
Use case 2: Artist names
$if($search(%album%,(feat. conductor)), $set(artist,%orchestra%))
- Stupid assumption that all classical albums have "feat. conductor" in the title, but it shows the idea. :)
Use case 3: Live tracks on live albums
$if($and($eq(%releasetype%,live),$not($in(%title%,\(live\)))),$set(title,%title% \(live\)))
Lower case filenames with underscores
$lower($replace(%albumartist%/%album%/$num(%tracknumber%,2) %title%, ,_))
(Year) only if available
$if(%date%,\($left(%date%,4)\))
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.
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:
- Non-Album Tracks: [non-album tracks]/Band Name - Track Name.ext
- Tracks in releases: Band Name - year - Release Name/##. Track Name.ext
Put subdiscs (disc 1, bonus disc, ...) in subdirectory
This one puts all sorts of subdiscs in one directory. For the subalbum it uses the full name.
$if2(%albumartist%,%artist%)/$if(%date%,\($left(%date%,4)\) )$if($rsearch(%album%,\(\\\([^\\\)]*disc[^\\\)]*\\\)\)),$rreplace(%album%,\\\([^\\\)]*disc[^\\\)]*\\\),)/)%album%/$num(%tracknumber%,2) %artist% - %title%
Result:
- Band Name/(year) Release Name/Release Name (disc #: Subname)/## Band Name - Track Name.ext
- Band Name/(year) Release Name/Release Name (bonus disc: Subname)/## Band Name - Track Name.ext
So a tree could look something like:
Ayreon/ (2000) Universal Migrator/ Universal Migrator (disc 1_ The Dream Sequencer)/ 01 ... Universal Migrator (disc 2_ Flight of the Migrator)/ 01 ...
Or:
Belle and Sebastian/ (2008) The BBC Sessions/ The BBC Sessions (bonus disc_ Live in Belfast, 2001)/ 01 Belle and Sebastian - Here Comes the Sun.mp3 02 ... 01 Belle and Sebastian - The State I Am In.mp3 02 ...
It only doensn't handle colons nicely. Also it catches every 'disc' between parentheses, so there could be albums where it goes wrong, for example if an album is named "Groovy Beats (disco mix)" it will end up in a double directory.
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))