MusicBrainz Picard/Documentation/Scripting: Difference between revisions
m (26 revision(s)) |
PavanChander (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
=Scripting in Picard= |
|||
This page describes a simple scripting language implemented in [[Picard Qt|PicardQt]]. |
This page describes a simple scripting language implemented in [[Picard Qt|PicardQt]]. |
||
==Syntax== |
==Syntax== |
||
Line 19: | Line 15: | ||
===%_extension%=== |
===%_extension%=== |
||
* Extension of the file name. For example ''mp3'' for file ''01 Track.mp3''. |
|||
</ul> |
|||
==Functions== |
==Functions== |
||
Line 26: | Line 21: | ||
===$if(if,then,else)=== |
===$if(if,then,else)=== |
||
* If <code><nowiki>if</nowiki></code> is not empty, it returns <code><nowiki>then</nowiki></code>, otherwise it returns <code><nowiki>else</nowiki></code>. |
|||
</ul> |
|||
===$if2(a1,a2,a3,...)=== |
===$if2(a1,a2,a3,...)=== |
||
* Returns first non empty argument. |
|||
</ul> |
|||
===$lower(text)=== |
===$lower(text)=== |
||
* Returns <code><nowiki>text</nowiki></code> in lower case. |
|||
</ul> |
|||
===$upper(text)=== |
===$upper(text)=== |
||
* Returns <code><nowiki>text</nowiki></code> in upper case. |
|||
</ul> |
|||
===$left(text,num)=== |
===$left(text,num)=== |
||
* Returns first <code><nowiki>num</nowiki></code> characters from <code><nowiki>text</nowiki></code>. |
|||
</ul> |
|||
===$right(text,num)=== |
===$right(text,num)=== |
||
* Returns last <code><nowiki>num</nowiki></code> characters from <code><nowiki>text</nowiki></code>. |
|||
</ul> |
|||
===$num(num,len)=== |
===$num(num,len)=== |
||
* Returns <code><nowiki>num</nowiki></code> formatted to <code><nowiki>len</nowiki></code> digits. |
|||
</ul> |
|||
===$replace(text,search,replace)=== |
===$replace(text,search,replace)=== |
||
* Replaces occurrences of <code><nowiki>search</nowiki></code> in <code><nowiki>text</nowiki></code> with value of <code><nowiki>replace</nowiki></code> and returns the resulting string. |
|||
</ul> |
|||
===$rsearch(text,pattern)=== |
===$rsearch(text,pattern)=== |
||
* [http://docs.python.org/lib/re-syntax.html Regular expression] search. This function will return the first matching group. |
|||
</ul> |
|||
===$rreplace(text,pattern,replace)=== |
===$rreplace(text,pattern,replace)=== |
||
* [http://docs.python.org/lib/re-syntax.html Regular expression] replace. |
|||
</ul> |
|||
===$in(x,y)=== |
===$in(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> contains <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$unset(name)=== |
===$unset(name)=== |
||
* Unsets the variable <code><nowiki></nowiki></code>name<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$set(name, value)=== |
===$set(name, value)=== |
||
* Sets the variable <code><nowiki></nowiki></code>name<code><nowiki></nowiki></code> to <code><nowiki></nowiki></code>value<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$get(name)=== |
===$get(name)=== |
||
* Returns the variable <code><nowiki></nowiki></code>name<code><nowiki></nowiki></code> (equivalent to <code><nowiki></nowiki></code>%name%<code><nowiki></nowiki></code>). |
|||
</ul> |
|||
===$copy(new,old)=== |
===$copy(new,old)=== |
||
* Copies metadata from variable <code><nowiki></nowiki></code>old<code><nowiki></nowiki></code> to <code><nowiki></nowiki></code>new<code><nowiki></nowiki></code>. The difference between <code><nowiki></nowiki></code>$set(new,%old%)<code><nowiki></nowiki></code> is that <code><nowiki></nowiki></code>$copy(new,old)<code><nowiki></nowiki></code> copies multi-value variables without flattening them. |
|||
</ul> |
|||
===$trim(text[,char])=== |
===$trim(text[,char])=== |
||
* Trims all leading and trailing whitespaces from <code><nowiki></nowiki></code>text<code><nowiki></nowiki></code>. The optional second parameter specifies the character to trim. |
|||
</ul> |
|||
===$add(x,y)=== |
===$add(x,y)=== |
||
* Add <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code> to <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$sub(x,y)=== |
===$sub(x,y)=== |
||
* Substracts <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code> from <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$div(x,y)=== |
===$div(x,y)=== |
||
* Divides <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> by <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$mod(x,y)=== |
===$mod(x,y)=== |
||
* Returns the remainder of <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> divided by <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$mul(x,y)=== |
===$mul(x,y)=== |
||
* Multiplies <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> by <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$or(x,y)=== |
===$or(x,y)=== |
||
* Returns true, if either <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> or <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code> not empty. |
|||
</ul> |
|||
===$and(x,y)=== |
===$and(x,y)=== |
||
* Returns true, if both <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> and <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code> are not empty. |
|||
</ul> |
|||
===$not(x)=== |
===$not(x)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> is empty. |
|||
</ul> |
|||
===$eq(x,y)=== |
===$eq(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> equals <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$ne(x,y)=== |
===$ne(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> not equals <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$lt(x,y)=== |
===$lt(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> is lower than <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$lte(x,y)=== |
===$lte(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> is lower than or equals <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$gt(x,y)=== |
===$gt(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> is greater than <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$gte(x,y)=== |
===$gte(x,y)=== |
||
* Returns true, if <code><nowiki></nowiki></code>x<code><nowiki></nowiki></code> is greater than or equals <code><nowiki></nowiki></code>y<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
===$noop(...)=== |
===$noop(...)=== |
||
* Does nothing (useful for comments or disabling a block of code). |
|||
</ul> |
|||
===$len(text)=== |
===$len(text)=== |
||
* Returns the number of characters in text. |
|||
</ul> |
|||
===$performer(pattern="", join=", ")=== |
===$performer(pattern="", join=", ")=== |
||
* Returns the performers where the performance type (e.g. "vocal") matches <code><nowiki></nowiki></code>pattern<code><nowiki></nowiki></code>, joined by <code><nowiki></nowiki></code>join<code><nowiki></nowiki></code>. |
|||
</ul> |
|||
==Examples== |
==Examples== |
||
Line 196: | Line 158: | ||
$set(album,$rreplace(%album%,\\s\\\(disc \\d+\\\),)) |
$set(album,$rreplace(%album%,\\s\\\(disc \\d+\\\),)) |
||
</pre> |
</pre> |
||
* Would it be possible to trim all of ''(disc 1: Subtitle Here)'' and also set the disc number? --[[User:AaronCooper|AaronCooper]] (2007-03-07) |
|||
** You can use the plugin from [[Picard Qt/Plugins|PicardQt/Plugins]]. --[[User:LukasLalinsky|LukasLalinsky]] |
|||
*** %totaldiscs% Doesn't really work, is there some way to fix that? --Madness |
|||
</ul> |
|||
</ul> |
|||
</ul> |
|||
===Use case 2: Artist names=== |
===Use case 2: Artist names=== |
||
Line 208: | Line 167: | ||
$set(artist,%orchestra%)) |
$set(artist,%orchestra%)) |
||
</pre> |
</pre> |
||
* ''Stupid assumption that all classical albums have "feat. conductor" in the title, but it shows the idea. :)'' |
|||
</ul> |
|||
===Use case 3: Live tracks on live albums=== |
===Use case 3: Live tracks on live albums=== |
||
Line 248: | Line 206: | ||
* Tracks in releases: Band Name - year - Release Name/##. Track Name.ext |
* Tracks in releases: Band Name - year - Release Name/##. Track Name.ext |
||
[[Category:Picard]] [[Category:Development]] |
Revision as of 18:26, 9 July 2009
This page describes a simple scripting language implemented in PicardQt.
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 PicardTags for list of variables available in TaggerScript.
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
.
$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
contains
y
.
$unset(name)
- Unsets the variable
name
.
$set(name, value)
- Sets the variable
name
to
value
.
$get(name)
- Returns the variable
name
(equivalent to
%name%
).
$copy(new,old)
- Copies metadata from variable
old
to
new
. 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
to
x
.
$sub(x,y)
- Substracts
y
from
x
.
$div(x,y)
- Divides
x
by
y
.
$mod(x,y)
- Returns the remainder of
x
divided by
y
.
$mul(x,y)
- Multiplies
x
by
y
.
$or(x,y)
- Returns true, if either
x
or
y
not empty.
$and(x,y)
- Returns true, if both
x
and
y
are not empty.
$not(x)
- Returns true, if
x
is empty.
$eq(x,y)
- Returns true, if
x
equals
y
.
$ne(x,y)
- Returns true, if
x
not equals
y
.
$lt(x,y)
- Returns true, if
x
is lower than
y
.
$lte(x,y)
- Returns true, if
x
is lower than or equals
y
.
$gt(x,y)
- Returns true, if
x
is greater than
y
.
$gte(x,y)
- Returns true, if
x
is greater than or equals
y
.
$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 by
join
.
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 PicardQt/Plugins. --LukasLalinsky
- %totaldiscs% Doesn't really work, is there some way to fix that? --Madness
- You can use the plugin from PicardQt/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