Scripting Functions

Mp3tag offers various built-in scripting functions, which can be used at various places in the program.

These functions offer advanced display and converting options and are to be used in combination with Format Strings and Available Placeholders.

General Functions

Replace

$replace(string,from,to) or $replace(string,from1,to1,from2,to2,...)

Example: $replace(%title%,_,-)

This example replaces all underscores with dashes. You can provide additional pairs of from/to as parameters.

Case Conversion Normal

$caps(string,...)

Example: $caps(%artist%)
This example converts the given string to normal case. The second parameter is optional and specifies additional characters that trigger upper case.

Case conversion Normal (without changing uppercase characters)

$caps2(string)

Example: $caps2(%artist%)
This example converts the given string to normal case without changing uppercase characters. The second parameter is optional and specifies the characters that trigger upper case.

Case conversion Sentence

$caps3(string)

Example: $caps3(%artist%)
This example converts the given string to first-letter upper case. The second parameter is optional and specifies additional characters that trigger upper case.

Case conversion UPPER

$upper(string)

Example: $upper(%artist%)
This example converts the given string to upper case.

Case conversion lower

$lower(string)

Example: $lower(%artist%)
This example converts the given string to lower case.

Pad decimal number with leading zeros

$num(x,y)

Example: $num(%track%,3)
This example returns the track number with three digits.

String Functions

Function Description
$ansi(x) returns the string x converted to the ANSI codepage.
$char(x) returns the Unicode character for decimal code point x.
$cutLeft(x,n) removes the first n characters of string x and returns the result.
$cutRight(x,n) removes the last n characters of string x and returns the result.
$fmtNum(x) formats number x with separator for thousands according to current locale settings.
$left(x,n) returns the leftmost n characters of string x.
$len(x) returns the length of string x.
$mid(x,i,n) returns the first n characters of text x, starting at character i. If n is ommited, the character at position i is returned.
$ord(x) returns the decimal Unicode code point of the first character of string x. Currently supports characters up to U+FFFF.
$repeat(x,n) returns the string x n times.
$regexp(x,expr,repl) replaces the pattern specified by the regular expression expr in the string x by repl. The fourth optional parameter enables ignore case (1) or disables the ignore case setting (0). Please note that you have to escape comma and other special characters in expr.
$reverse(x) reverses the order of the characters in string x.
$right(x,n) returns the rightmost n characters of text x.
$strcmp(x,y) compares strings x and y case-sensitively.
$stricmp(x,y) compares strings x and y case-insensitively.
$strchr(x,y) finds the first occurrence of character y in string x.
$strrchr(x,y) finds the last occurrence of character y in string x.
$strstr(x,y) finds the first occurrence of string y in string x.
$trim(x) trims all leading and trailing whitespace from the string x. The optional second parameter specifies the character to trim.
$trimLeft(x) trims all leading whitespace from the string x. The optional second parameter specifies the character to trim.
$trimRight(x) trims all trailing whitespace from the string x. The optional second parameter specifies the character to trim.

Boolean Functions

Function Description
$and(x,y) returns true if x and y are true.
$eql(x,y) returns true if x equals y. If x and y are strings, they're compare case-insensitively.
$geql(x,y) returns true if x is greater than or equal to y.
$gt(x,y) returns true if x is greater than y.
$if(x,y,z) if x is true, y is returned, otherwise z.
$if2(x,y) if x is true, x is returned, otherwise y.
$ifgreater(a,b,x,y) if number a is greater than number b, x is returned, otherwise y.
$iflonger(a,b,x,y) if string a is longer than number b, x is returned, otherwise y.
$isdigit(x) returns true if character x is a decimal number.
$leql(x,y) returns true if x is less than or equal to y.
$lt(x,y) returns true if x is less than y.
$neql(x,y) returns true if x not equal to y.
$not(x) returns true if x is false.
$odd(x) returns true if x is odd.
$or(x,y) returns true if x or y (or any additional argument given) is true.

Arithmetic functions

Function Description
$add(x,y) adds y to 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.
$rand() returns a pseudorandom number.
$sub(x,y) subtracts y from x.

Metadata (including multiple tag fields)

Function Description
$meta(x) returns all values of field x (e.g. $meta(artist)). Multiple values of a field are separated by ", ".
$meta(x,n) returns the nth value of field x (where n starts at 0, e.g. $meta(artist,1)).
$metasep(x,sep) returns all values of field x (e.g. $metasep(artist,; )). Multiple values of a field are separated by sep.
4 Likes