MusicBrainz Picard/Documentation/Scripting: Difference between revisions

From MusicBrainz Wiki
Jump to navigationJump to search
((Imported from MoinMoin))
 
(manually redirecting anyone naughtily linking to the wiki instead of /doc/)
 
(77 intermediate revisions by 24 users not shown)
Line 1: Line 1:
=Scripting in Picard=
#REDIRECT [[MusicBrainz Picard]]

This section describes a simple scripting language implemented in [[Picard Qt|PicardQt]].

==Syntax==

The syntax is derived from [http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Titleformat_Reference Foobar2000's titleformat]. There are three base elements: '''text''', '''variable''' and '''function'''. Variables consist of alpha-numeric characters enclosed in percent signs (e.g. <code><nowiki>%artist%</nowiki></code>). Functions start with a dollar sign and end with an argument list enclosed in parentheses (e.g. <code><nowiki>$lower(...)</nowiki></code>).

==Variables==

<ul><li style="list-style-type:none">''TODO: Add all tag names from [[Unified Tagging|UnifiedTagging]] here.''
</ul>

==Functions==

===$if(if,then,else)===

<ul><li style="list-style-type:none">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,...)===

<ul><li style="list-style-type:none">Returns first non empty argument.
</ul>

===$lower(text)===

<ul><li style="list-style-type:none">Returns <code><nowiki>text</nowiki></code> in lower case.
</ul>

===$upper(text)===

<ul><li style="list-style-type:none">Returns <code><nowiki>text</nowiki></code> in upper case.
</ul>

===$left(text,num)===

<ul><li style="list-style-type:none">Returns first <code><nowiki>num</nowiki></code> characters from <code><nowiki>text</nowiki></code>.
</ul>

===$right(text,num)===

<ul><li style="list-style-type:none">Returns last <code><nowiki>num</nowiki></code> characters from <code><nowiki>text</nowiki></code>.
</ul>

===$num(num,len)===

<ul><li style="list-style-type:none">..
</ul>

===$replace(text,search,replace)===

<ul><li style="list-style-type:none">..
</ul>

===$search(text)===

<ul><li style="list-style-type:none">..
</ul>
<ul><li style="list-style-type:none">''TODO: add more functions, add descriptions''
</ul>

==Examples==

===Use case 1: Disc numbers===

<pre>$set(album,$replace(%album%,\(disc \d+(: [^)]+)\),))
$set(discnumber,$search(%album%,\(disc (\d+)\)))
</pre>

===Use case 2: Artist names===

<pre>$if($search(%album%,(feat. conductor)),
$set(artist,%orchestra%))
</pre>
<ul><li style="list-style-type:none">''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===

<pre>$if($and($eq(%albumstatus%,live),$not($search(%title,(\(live\))))),$set(title,%title% (live)))
</pre>

===Lower case filenames with underscores===

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

[[Category:To Be Reviewed]] [[Category:Picard]] [[Category:Development]]

Latest revision as of 21:16, 25 November 2014

Redirect to: