Difference between revisions of "Foobar2000:Title Formatting Reference"

From Hydrogenaudio Knowledgebase
Jump to: navigation, search
(Removed various useless/outdated info.)
($directory_path(path))
 
(115 intermediate revisions by 45 users not shown)
Line 1: Line 1:
{{fb2k}}
+
{{sidebar foobar2000 title formatting}}
This article contains information about built-in titleformatting functions and field references with special meaning. References to documentation about fields and function which can only be used in specific components or which are provided by specific components can be found at the end of this article.
+
This article contains information about built-in title formatting functions and field references, plus additional documentation about fields and functions which can only be used in specific components or which are provided by specific components.
  
A field reference is a field name enclosed in percent signs, for example ''%artist%''. A function call starts with a dollar sign, followed by the function name and the parameter list. A parameter list can either be empty - denoted as ''()'' - or contain one or more parameters separated by commata, for example ''$abbr(%artist%)''. Note that there must be no whitespace between the dollar sign and the function name, or the function name and the opening parenthesis of the parameter list.
+
Please see [[Foobar2000:Title Formatting Introduction|Title Formatting Introduction]] for a general overview of title format syntax and its basic rules. The article [[foobar2000:Titleformat Examples|Titleformat Examples]] offers user-submitted examples of code for specific purposes; feel free to add your own if you think it can be of use to others.
  
Please see [[Foobar2000:Titleformat_Introduction|Titleformat Introduction]] for a presentation of titleformat syntax in general.
+
For details of the query syntax, which uses some of these fields to find files for playlists, etc., see the [[Foobar2000:Query_syntax|Query Syntax]] article.
  
= Field remappings =
+
== Syntax ==
  
Some of the fields accessible through ''%name%'' are remapped to other values to make writing titleformat scripts more convenient.
+
A title formatting script consists of any combination of literal text, field references, function calls, comments, and line break characters. The script always outputs a text string (which can be empty).
  
== Metadata ==
+
A '''comment''' is a line starting with two slashes, e.g. {{code|// this is a comment}}.
  
=== %album artist% ===
+
A '''field reference''' is a field name enclosed in percent signs, for example {{code|%artist%}}.
Name of the artist of the album specified track belongs to. Checks following metadata fields, in this order: "album artist", "artist", "composer", "performer". The difference between this and ''%artist%'' is that ''%album artist%'' is intended for use where consistent value across entire album is needed even when per-track artists values vary.
+
  
=== %album% ===
+
A '''function call''' starts with a dollar sign, followed by the function name and the parameter list. A parameter list can either be empty – denoted as {{code|()}} – or contain one or more parameters separated by commas, for example {{code|$abbr(%artist%)}}. A parameter can be literal text, a field reference, or another function call. Note that there must be no whitespace between the dollar sign and the function name, or the function name and the opening parenthesis of the parameter list.
Name of the album specified track belongs to. Checks following metadata fields, in this order: "album", "venue".
+
  
=== %artist% ===
+
Any other text is '''literal text'''. In literal text, the character {{code|%}}, {{code|$}}, {{code|[}}, {{code|]}}, or {{code|'}} (apostrophe/single quote) must be escaped by enclosing it in {{code|'}} (apostrophe/single quote) characters. For example, {{code|'['}} (a left bracket in single quotes) results in a literal {{code|[}} (left bracket). As a special case, {{code|<nowiki>''</nowiki>}} (two single quotes in a row) results in one single quote. In the playlist, {{code|&lt;}} and {{code|&gt;}} are also special; see [[#Dimmed and highlighted text|Dimmed and highlighted text]].
Name of the artist of the track. Checks following metadata fields, in this order: "artist", "album artist", "composer", "performer".
+
  
=== %disc% ===
+
When the script is evaluated, the output string is assembled by evaluating the function parameters, function calls, and field references. Comments and line break characters (CR and LF/newline) are ignored; to output a line break, use {{code|$crlf()}}. Each field reference becomes the field's value, as a string. Each function becomes a string or number, and/or a truth value (not output) which can be used by another function.
Index of disc specified track belongs to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.
+
  
This remapping exists only for compatibility with old scripts. It is recommended to use %discnumber% instead.
+
'''Note: The interface for entering custom columns and grouping schemes for the Default UI playlist does not support line breaks; scripts must be written all on one line, without comments.'''
  
=== %discnumber% ===
+
== Arithmetic functions ==
Index of disc specified track belongs to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.
+
  
=== %track artist% ===
+
The functions in this section can be used to perform arithmetic on integer numbers. A string will be automatically converted to a number and vice versa. The conversion to a number uses the longest prefix of the string that can be interpreted as number. Leading whitespace is ignored. Decimal points are not supported. Examples:
Name of the artist of the track; present only if ''%album artist%'' is different than ''%artist%'' for specific track. Intended for use together with ''%album artist%'', to indicate track-specific artist info, e.g. "%album artist% - %title%[ '//' %track artist%]". In this case, the last part will be displayed only when track-specific artist info is present.
+
* ''c3po'' → 0
 +
* ''4.8'' → 4
 +
* ''-12'' -12
 +
* ''- 12'' → 0
  
=== %title% ===
+
=== $add(a,b, ...) ===
Title of the track. If "title" metadata field is missing, file name is used instead.
+
 
+
=== %track% ===
+
Returns the tracknumber padded to two digits from the left with zeroes. The tracknumber is taken from the tracknumber tag; if that does not exist, it is taken from the track tag. If neither exist, this field is undefined.
+
 
+
This remapping exists only for compatibility with old scripts. It is recommended to use %tracknumber% instead.
+
 
+
=== %tracknumber% ===
+
Two-digit index of specified track within the album. Available only when "tracknumber" field is present in track’s metadata.
+
 
+
== Technical information ==
+
 
+
=== %bitrate% ===
+
Bitrate of the track; includes dynamic VBR bitrate display for currently played track.
+
 
+
=== %channels% ===
+
Number of channels in the track (mono/stereo/etc). Returns the number of channels in text form; returns "mono" and "stereo" instead of "1" and "2".
+
 
+
=== %filesize% ===
+
Defined as ''%_filesize%''. Returns the filesize in bytes.
+
 
+
=== %samplerate% ===
+
Sample rate of the track, in Hz.
+
 
+
=== %codec% ===
+
Name of codec used to encode the track. If exact codec name is not available, file extension is used.
+
 
+
== Special fields ==
+
 
+
= Control flow =
+
 
+
The functions in this section can be used to conditionally execute statements.
+
 
+
=== [...] (conditional section) ===
+
 
+
Evaluates the expression between ''['' and '']''. If it has the truth value ''true'', its string value and the truth value ''true'' are returned. Otherwise an empty string and ''false'' are returned.
+
 
+
Example: ''[%artist%]'' returns the value of the artist tag, if it exists. Otherwise it returns nothing, when ''artist'' would return "?".
+
 
+
=== $if(cond,then) ===
+
 
+
If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, ''false'' is returned.
+
 
+
=== $if(cond,then,else) ===
+
 
+
If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, the ''else'' part is evaluated and its value returned.
+
 
+
=== $if2(a,else) ===
+
 
+
Like ''$if(a,a,else)'' except that ''a'' is only evaluated once.
+
 
+
=== $if3(a1,a2,...,aN,else) ===
+
 
+
Evaluates arguments ''a1'' ... ''aN'', until one is found that evaluates to ''true''. If that happens, its value is returned. Otherwise the ''else'' part is evaluated and its value returned.
+
 
+
=== $ifequal(n1,n2,then,else) ===
+
 
+
Compares the integer numbers ''n1'' and ''n2'', if ''n1'' is equal to ''n2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
+
 
+
=== $ifgreater(n1,n2,then,else) ===
+
 
+
Compares the integer numbers ''n1'' and ''n2'', if ''n1'' is greater than ''n2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
+
 
+
=== $iflonger(s1,s2,then,else) ===
+
 
+
Compares the length of the strings ''s1'' and ''s2'', if ''s1'' is longer than ''s2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
+
 
+
=== $select(n,a1,...,aN) ===
+
 
+
If the value of ''n'' is between 1 and N, ''an'' is evaluated and its value returned. Otherwise ''false'' is returned.
+
 
+
= Arithmetic functions =
+
 
+
The functions in this section can be used to perform arithmetic on integer numbers. A string will be automatically converted to a number and vice versa. The conversion to a number uses the longest prefix of the string, that can be interpreted as number. Leading whitespace is ignored.
+
 
+
Example: "c3po" → 0, " -12" → -12, but "- 12" → 0
+
 
+
=== $add(a,b) ===
+
  
 
Adds ''a'' and ''b''.
 
Adds ''a'' and ''b''.
Line 118: Line 38:
 
=== $div(a,b) ===
 
=== $div(a,b) ===
  
Divides ''a'' through ''b''. If ''b'' evaluates to zero, it returns ''a''.
+
Divides ''a'' by ''b'' and rounds down to an integer. If ''b'' evaluates to zero, it returns ''a''.
  
 
Can be used with an arbitrary number of arguments. ''$div(a,b,...)'' is the same as ''$div($div(a,b),...)''.
 
Can be used with an arbitrary number of arguments. ''$div(a,b,...)'' is the same as ''$div($div(a,b),...)''.
Line 156: Line 76:
 
=== $rand() ===
 
=== $rand() ===
  
Generates a random number in the range from 0 to 2<sup>32</sup>-1.
+
Generates a random number in the range from 0 to 2<sup>32</sup>-1. Available only in sort-related contexts, such as the ''Edit → Sort → Sort by ...'' menu command.
  
 
=== $sub(a,b) ===
 
=== $sub(a,b) ===
Line 164: Line 84:
 
Can be used with an arbitrary number of arguments. ''$sub(a,b,...)'' is the same as ''$sub($sub(a,b),...)''.
 
Can be used with an arbitrary number of arguments. ''$sub(a,b,...)'' is the same as ''$sub($sub(a,b),...)''.
  
= Boolean functions =
+
== Boolean functions ==
  
 
The functions in this section can be used to work with truth values (''true'' and ''false''), which have no explicit representation in titleformat scripts. They do not return a string or number value. You can use them for more complex conditions with ''$if'' and related functions.
 
The functions in this section can be used to work with truth values (''true'' and ''false''), which have no explicit representation in titleformat scripts. They do not return a string or number value. You can use them for more complex conditions with ''$if'' and related functions.
  
=== $and(...) ===
+
Foobar does not have a concept of TRUE and FALSE in a programming language sense where 0 or empty string are considered FALSE and other values TRUE. Therefore there is no difference between numeric 0 and string representation '0' which both are considered as values, and being attached a boolean value FALSE. Apostrophes are only required to escape certain syntax characters. Values are treated as numbers during arithmetic operations like'' $add()''.
  
Logical And of an arbitrary number of arguments. Returns ''true'', if and only if all arguments evaluate to ''true''.
+
=== $and(expr, ...) ===
  
Special case: ''$and(x,y)'' is ''true'', if both ''x'' and ''y'' are ''true''. Otherwise it is ''false''.
+
Logical And of an arbitrary number of arguments. Returns ''true'', if and only if all ''expr'' arguments evaluate to ''true''.
  
=== $or(...) ===
+
=== $or(expr, ...) ===
  
Logical Or of an arbitrary number of arguments. Returns ''true'', if at least one argument evaluates to ''true''.
+
Logical Or of an arbitrary number of arguments. Returns ''true'', if at least one expression evaluates to ''true''.
  
Special case: ''$or(x,y)'' is ''true'', if ''x'' or ''y'' is ''true'', or if both are ''true''. Otherwise it is ''false''.
+
=== $not(expr) ===
  
=== $not(x) ===
+
Logical Not. Returns the logical opposite of EXPR: ''false'', if ''expr'' is ''true'' and ''true'' if ''expr'' is false.
  
Logical Not. Returns ''false'', if ''x'' is ''true'', otherwise it returns ''true''.
+
=== $xor(expr,...) ===
 
+
=== $xor(...) ===
+
  
 
Logical Exclusive-or of an arbitrary number of arguments. Returns ''true'', if an odd number of arguments evaluate to ''true''.
 
Logical Exclusive-or of an arbitrary number of arguments. Returns ''true'', if an odd number of arguments evaluate to ''true''.
  
Special case: ''$xor(x,y)'' is ''true'', if one of ''x'' and ''y'' is ''true'', but not both. Otherwise it is ''false''.
+
Special case: ''$xor(expr1,expr2)'' returns ''true'', if EXPR1 or EXPR2 is ''true''. If both expressions are true, returns ''false''.
  
= Color functions =
+
== Control flow functions ==
  
=== $blend(color1,color2,part,total) ===
+
The functions in this section can be used to conditionally execute statements.
  
Returns a color that is a blend between ''color1'' and ''color2''. If ''part'' is smaller than or equal to zero, ''color1'' is returned. If ''part'' is greater than or equal to ''total'', ''color2'' is returned. Otherwise a blended color is returned that is ''part'' parts ''color1'' and ''total''-''part'' parts ''color2''. The blending is performed in the RGB color space.
+
=== [...] (conditional section) ===
  
=== $hsl() ===
+
Evaluates the expression between ''['' and '']''. If it has the truth value ''true'', its string value and the truth value ''true'' are returned. Otherwise an empty string and ''false'' are returned.
  
Resets the text color to the default color.
+
Example: ''[%artist%]'' returns the value of the artist tag, if it exists. Otherwise it returns nothing, when ''artist'' would return "?".
  
=== $hsl(h,s,l) ===
+
=== $if(cond,then) ===
  
Sets the color for text in the HSL color space. ''h'', ''s'' and ''l'' are the hue, saturation, and lightness of the color for unselected text. The color for selected text is set to the inverse color.
+
If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, ''false'' is returned.
The ranges of ''h'', ''s'', and ''l'' are from 0 to 240; the function is designed to interpret those values in the same way as the standard Windows color dialog.
+
  
=== $hsl(h1,s1,l1,h2,s2,l2) ===
+
Plain strings are FALSE. Field lookups and functions can introduce a boolean value of TRUE. <br />
 +
<u>Examples</u>:<br />
 +
<u>1</u>
 +
<code>
 +
#False:
 +
$if(0,True,False)
 +
# False:
 +
$if('0',True,False)
 +
# True or False:
 +
[$add(%rating%,1)]
 +
</code><br />
 +
The last one would display the value of %rating% plus one, if and only if %rating% is set for the track.
  
Sets the color for text in the HSL color space. ''h1'', ''s1'' and ''l1'' are the hue, saturation, and lightness of the color for unselected text. ''h2'', ''s2'' and ''l2'' are the hue, saturation, and lightness of the color for selected text.
+
<u>2</u>
 +
Ignore inserting the %album artist%, if it contains the word "various".  
 +
<code>
 +
# Wrong:
 +
$if([%album artist%=Various],,%artist%-)
 +
# Good approach:
 +
$if($stricmp(%album artist%,Various),,%artist%-)
 +
</code>
  
=== $rgb() ===
+
=== $if(cond,then,else) ===
  
Resets the text color to the default color.
+
If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, the ''else'' part is evaluated and its value returned.
  
=== $rgb(r,g,b) ===
+
=== $if2(expr,else) ===
  
Sets the color for text. ''r'', ''g'' and ''b'' are the red, green and blue component of the color for unselected text. The color for selected text is set to the inverse color.
+
Like ''$if(expr,expr,else)'' except that ''expr'' is only evaluated once. In other words, if expression ''expr'' is true, ''expr'' is returned, otherwise the ''else'' part is evaluated and ''expr'' is returned as true.
  
=== $rgb(r1,g1,b1,r2,g2,b2) ===
+
=== $if3(a1,a2,...,aN,else) ===
  
Sets the color for text. ''r1'', ''g1'' and ''b1'' are the red, green and blue component of the color for unselected text. ''r2'', ''g2'' and ''b2'' are the red, green and blue component of the color for selected text.
+
Evaluates arguments ''a1'' ... ''aN'', until one is found that evaluates to ''true''. If that happens, its value is returned. Otherwise the ''else'' part is evaluated and its value returned.
  
=== $transition(string,color1,color2) ===
+
=== $ifequal(int1,int2,then,else) ===
  
Inserts color codes into ''string'', so that the first character has ''color1'', the last character has ''color2'', and intermediate characters have blended colors. The blending is performed in the RGB color space. Note that color codes are additional characters that will also be counted by string manipulation functions. For example, if you need to truncate a string, you should do this before applying ''$transition''.
+
Compares the integer numbers ''int1'' and ''int2'', if ''int1'' is equal to ''int2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
  
= Now playing info =
+
=== $ifgreater(int1,int2,then,else) ===
The following functions and fields are usable for scripts used with the currently playing item, for example the status bar, the main window title and the copy command script.
+
  
== Special fields ==
+
Compares the integer numbers ''int1'' and ''int2'', if ''int1'' is greater than ''int2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
  
=== %playback_time% ===
+
=== $iflonger(str,n,then,else) ===
Returns the elapsed time formatted as [HH:]MM:SS.
+
  
=== %playback_time_seconds% ===
+
Compares the length of the string ''str'' to the number ''n'', if ''str'' is longer than ''n'' characters, the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
Returns elapsed time in seconds.
+
Old version: <code>%_time_elapsed%</code>
+
  
=== %playback_time_remaining% ===
+
=== $select(n,a1,...,aN) ===
Returns remaining time until track ends, formatted as [HH:]MM:SS.
+
Old version: <code>%_time_remaining%</code>
+
  
=== %playback_time_remaining_seconds% ===
+
If the value of ''n'' is between 1 and N, ''an'' is evaluated and its value returned. Otherwise ''false'' is returned.
Returns remaining time in seconds.
+
Old version: <code>%_time_remaining_seconds%</code>
+
  
=== %length% ===
+
== String functions ==
Returns the length of the track formatted as hours, minutes, and seconds.
+
Old version: <code>%_time_total%</code>
+
  
=== %length_ex% ===
+
The functions in this section can be used to manipulate character strings.
Returns the length of the track formatted as hours, minutes, seconds, and milliseconds.
+
  
=== %length_seconds% ===
+
=== $abbr(str) ===
Returns the length of the track in seconds.
+
Old version: <code>%_time_total_seconds%</code>
+
  
=== %length_seconds_fp% ===
+
Returns abbreviation of string ''str''. Words which begin with an alphanumeric character are shortened to the first character. Spaces and parentheses are stripped. Example:
Returns the length of the track in seconds as floating point number.
+
* $abbr('This is a Long Title (12-inch version) [needs tags]') → TiaLT1v[needst
  
=== %length_samples% ===
+
=== $abbr(str,len) ===
Returns the length of the track in samples.
+
  
= Playlist info =
+
Returns abbreviation of ''str'', if ''str'' is longer than ''len'' characters, otherwise returns ''str''.
The following functions and fields are usable for playlist scripts such as masstagger.
+
  
== Special fields ==
+
=== $ansi(str) ===
  
=== %isplaying% ===
+
Converts string ''str'' to system codepage and back. Any characters that are not present in the system codepage will be removed / replaced. Useful for mass-renaming files to ensure compatibility with non-unicode-capable software.
  
Returns "1" if file is currently playing and empty string otherwise.
+
=== $ascii(str) ===
  
The old version <code>%_isplaying%</code> still works.
+
Converts string ''str'' to ASCII. Any characters that are not present in ASCII will be removed / replaced.
  
=== %ispaused% ===
+
=== $caps(str) ===
  
Returns "1" if playback is paused, empty string otherwise.
+
Converts first letter in every word of string ''str'' to uppercase, and all other letters to lowercase.
  
The old version <code>%_ispaused%</code> still works.
+
=== $caps2(str) ===
  
=== %list_index% ===
+
Converts first letter in every word of string ''str'' to uppercase, and leaves all other letters as they are.
  
Returns a zero-padded playlist index of specified item. The first item is at index 1.
+
=== $char(nbr) ===
  
Also see [[Foobar2000:Titleformat Reference#%playlist_number%|%playlist_number%]].
+
Returns Unicode character of ''nbr''. You can search for characters and find the matching decimal number on this [http://www.fileformat.info/info/unicode/char/search.htm site].
  
The old version <code>%_playlist_number%</code> still works.
+
=== $crc32(str) ===
  
=== %list_total% ===
+
Computes the CRC32 of the string ''str'' as a number. Intended for use in coloring scripts.
  
Returns number of items in the playlist.
+
Example: $rgb($mod($crc32(%album%),256),128,128)
  
= String functions =
+
=== $crlf() ===
  
The functions in this section can be used to manipulate character strings.
+
Inserts end-of-line marker (carriage return, line feed). Can be used to generate multiple lines in the output, for example for the tooltip of the system  notification area ("systray") icon.
  
=== $abbr(x) ===
+
=== $cut(str,len) ===
  
Returns abbreviation of ''x''.
+
Returns first ''len'' characters from the left of the string ''str''. This function is the same as $left(a,len). Negative numbers produce the entire string. Examples:
 +
* ''$cut('abc123',3)'' → abc
 +
* ''$cut('abc123',0)'' → (nothing)
 +
* ''$cut('abc123',-1)'' → abc123
  
=== $abbr(x,len) ===
+
=== $directory(path) ===
  
Returns abbreviation of ''x'', if ''x'' is longer than ''len'' characters, otherwise returns ''x''.
+
Extracts only the directory name (not full path, ie given path as 'D:\music\jazz\filename.mp3', this will output 'jazz') from the file ''path''.
  
=== $ansi(x) ===
+
=== $directory(path,n) ===
  
Converts ''x'' to system codepage and back. Any characters that are not present in the system codepage will be removed / replaced. Useful for mass-renaming files to ensure compatibility with non-unicode-capable software.
+
Extracts directory name from the file ''path''; goes up by ''n'' levels.
  
=== $ascii(x) ===
+
=== $directory_path(path) ===
  
Converts ''x'' to ASCII. Any characters that are not present in ASCII will be removed / replaced.
+
Extracts directory path from the file ''path''.
 +
ie. given path as 'D:\music\jazz\filename.mp3', this will output 'D:\music\jazz'
  
=== $caps(x) ===
+
=== $ext(path) ===
  
Converts first letter in every word of x to uppercase, and all other letters to lowercase.
+
Extracts file extension from string ''path''; a file name or full path.
  
=== $caps2(x) ===
+
=== $filename(path) ===
  
Converts first letter in every word of x to uppercase, and leaves all other letters as they are.
+
Extracts file name from full ''path''.
  
=== $char(x) ===
+
=== $fix_eol(str) ===
  
Inserts Unicode character with code ''x''.
+
If ''str'' contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by " (...)". Otherwise ''str'' is returned unaltered.
  
=== $crc32(a) ===
+
=== $fix_eol(str,indicator) ===
  
Computes the CRC32 of the string ''a'' as a number. Intended for use in coloring scripts.
+
If ''str'' contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by ''indicator''. Otherwise ''str'' is returned unaltered.
  
Example: $rgb($mod($crc32(%album%),256),128,128)
+
=== $hex(int,len) ===
  
=== $crlf() ===
+
Formats the integer number ''int'' in hexadecimal notation with ''len'' digits. Pads with zeros from the left if necessary.
  
Inserts end-of-line marker (carriage return, line feed). Can be used to generate multiple lines in the output, for example for the tooltip of the system  notification area ("systray") icon.
+
=== $insert(str,insert,n) ===
  
=== $cut(a,len) ===
+
Inserts ''insert'' into ''str'' after ''n'' characters.
  
Returns first ''len'' characters on the left of ''a''.
+
=== $left(str,len) ===
  
=== $directory(x) ===
+
Returns first ''len'' characters from the left of the string ''str''. This function is the same as $cut(str,len). Negative numbers produce the entire string. Examples:
 +
* ''$left('abc123',3)'' → abc
 +
* ''$left('abc123',0)'' → (nothing)
 +
* ''$left('abc123',-1)'' → abc123
  
Extracts directory name from the file path ''x''.
+
=== $len(str) ===
  
=== $directory(x,n) ===
+
Returns length of string ''str'' in characters.
  
Extracts directory name from the file path ''x''; goes up by ''n'' levels.
+
=== $len2(str) ===
  
=== $ext(x) ===
+
Returns length of string ''str'' in characters, respecting double-width character rules (double-width characters will be counted as two).
  
Extracts file extension from ''x'' which must be a file name or path.
+
=== $longer(str1,str2) ===
  
=== $filename(x) ===
+
Returns ''true'', if string ''str1'' is longer than string ''str2'', false otherwise.
  
Extracts file name from full path.
+
=== $lower(str) ===
  
=== $fix_eol(x) ===
+
Converts string ''str'' to lowercase.
  
If ''x'' contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by " (...)". Otherwise ''x'' is returned unaltered.
+
=== $longest(arg,...) ===
  
=== $fix_eol(x,indicator) ===
+
Returns the longest of its arguments. Can be used with an arbitrary number of strings.
  
If ''x'' contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by ''indicator''. Otherwise ''x'' is returned unaltered.
+
=== $num(nbr,len) ===
  
=== $hex(n) ===
+
Formats the integer number ''nbr'' in decimal notation with ''len'' characters. Pads with zeros from the left if necessary. ''len'' includes the dash when the number is negative. If ''nbr'' is not numeric, it is treated as zero. Examples:
  
Formats the integer number ''n'' in hexadecimal notation.
+
* ''$num(123,5)'' → 00123
 +
* ''$num(-123,5)'' → -0123
 +
* ''$num(4.8,5)'' → 00004
 +
* ''$num(A1,5)'' → 00000
  
=== $hex(n,len) ===
+
=== $pad(str,len) ===
  
Formats the integer number ''n'' in hexadecimal notation with ''len'' digits. Pads with zeros from the left if necessary.
+
Creates a left-aligned version of the string ''str''. If ''str'' is shorter than ''len'' characters, the function adds spaces to the right of ''str'' to make the result ''len'' characters long. Otherwise the function returns ''str'' unchanged.
  
=== $insert(a,b,n) ===
+
=== $pad_right(str,len) ===
  
Inserts ''b'' into ''a'' after ''n'' characters.
+
Creates a right-aligned version of the string ''str''. If ''str'' is shorter than ''len'' characters, the function adds spaces to the left of ''str'' to make the result ''len'' characters long. Otherwise the function returns ''str'' unchanged.
  
=== $left(a,len) ===
+
=== $pad(str,len,char) ===
  
Returns the first ''len'' characters from the left of ''a''.
+
Creates a left-aligned version of the string ''str''. If ''str'' is shorter than ''len'' characters, the function adds ''char'' to the right of ''str'' to make the result ''len'' characters long. Otherwise the function returns ''str'' unchanged.
  
=== $len(a) ===
+
=== $pad_right(str,len,char) ===
  
Returns length of string ''a'' in characters.
+
Creates a right-aligned version of the string ''str''. If ''str'' is shorter than ''len'' characters, the function adds ''char'' to the left of ''str'' to make the result ''len'' characters long. Otherwise the function returns ''str'' unchanged.
  
=== $len2(a) ===
+
=== $padcut(str,len) ===
  
Returns length of string x in characters, respecting double-width character rules (double-width characters will be counted as two).
+
Returns first ''len'' characters from the left of ''str'', if ''str'' is longer than ''len'' characters. Otherwise adds spaces to the right of ''str'' to make the result ''len'' characters long.
  
=== $longer(a,b) ===
+
=== $padcut(str,len,char) ===
  
Returns ''true'', if string ''a'' is longer than string ''b'', false otherwise.
+
Returns first ''len'' characters from the left of ''str'', if ''str'' is longer than ''len'' characters. Otherwise adds ''char'' to the right of ''str'' to make the result ''len'' characters long.
  
=== $lower(a) ===
+
=== $padcut_right(str,len) ===
  
Converts ''a'' to lowercase.
+
Returns first ''len'' characters from the left of ''str'', if ''str'' is longer than ''len'' characters. Otherwise adds spaces to the left of ''str'' to make the result ''len'' characters long.
  
=== $longest(a,...) ===
+
=== $padcut_right(str,len,char) ===
  
Returns the longest of its arguments. Can be used with an arbitrary number of strings.
+
Returns first ''len'' characters from the left of ''str'', if ''str'' is longer than ''len'' characters. Otherwise adds ''char'' to the left of ''str'' to make the result ''len'' characters long.
  
=== $num(n,len) ===
+
=== $progress(pos,range,len,char1,char2) ===
  
Formats the integer number ''n'' in decimal notation with ''len'' digits. Pads with zeros from the left if necessary.
+
Creates a progress bar: ''pos'' contains position, ''range'' contains range, ''len'' progress bar length in characters, ''char1'' and ''char2'' are characters to build progress bar with.
  
=== $pad(x,len) ===
+
Example:''$progress(%_time_elapsed_seconds%, %_time_total_seconds%, 20,'#','=')'' produces "====#===============", the # character is moving with playback position.
  
Pads ''x'' from the left with spaces to ''len'' characters.
+
=== $progress2(pos,range,len,char1,char2) ===
  
=== $pad_right(x,y) ===
+
Creates a progress bar: ''pos'' contains position, ''range'' contains range, ''len'' progress bar length in characters, ''char1'' and ''char2'' are characters to build progress bar with. Produces different appearance than ''$progress''.
  
Pads ''x'' from the right with spaces to ''len'' characters.
+
=== $repeat(expr,count) ===
  
=== $pad(x,len,char) ===
+
Returns ''count'' copies of ''expr''. Note that ''expr'' is evaluated once before its value is used, so ''$repeat'' cannot be used for loops.
  
Pads ''x'' from the left with ''char'' to ''len'' characters.
+
=== $replace(str,search,replace) ===
  
=== $pad_right(x,len,char) ===
+
Replaces all occurrences of string ''search'' in string ''str'' with string ''replace''.
  
Pads ''x'' from the right with ''char'' to ''len'' characters.
+
Can also be used with an arbitrary number of arguments. Note that ''$replace(str,search1,replace1,search2,replace2)'' is generally not the same as ''$replace($replace(str,search1,replace1),search2,replace2)''.
  
=== $padcut(x,len) ===
+
Example: ''$replace(ab,a,b,b,c)'' → "bc", ''$replace($replace(ab,a,b),b,c)'' → "cc"
  
Returns first ''len'' characters from the left of ''x'', if ''x'' is longer than ''len'' characters. Otherwise pads ''x'' from the left with spaces to ''len'' characters.
+
=== $right(str,len) ===
  
=== $padcut_right(x,len) ===
+
Returns the first ''len'' characters from the right of string ''str''.
  
Returns first ''len'' characters from the left of ''x'', if ''x'' is longer than ''len'' characters. Otherwise pads ''x'' from the right with spaces to ''len'' characters.
+
=== $roman(int) ===
  
=== $progress(pos,range,len,a,b) ===
+
Formats the integer number ''int'' in roman notation.
  
Creates a progress bar: ''pos'' contains position, ''range'' contains range, ''len'' progress bar length in characters, ''a'' and ''b'' are characters to build progress bar with.
+
=== $rot13(str) ===
  
Example:''$progress(%_time_elapsed_seconds%, %_time_total_seconds%, 20,'#','=')'' produces "====#===============", the # character is moving with playback position.
+
Performs [http://en.wikipedia.org/wiki/ROT13 ROT13] transformation to given string.
  
=== $progress2(pos,range,len,a,b) ===
+
Example: ''$rot13('foobar2000')'' → "sbbone2000".
  
Creates a progress bar: ''pos'' contains position, ''range'' contains range, ''len'' progress bar length in characters, ''a'' and ''b'' are characters to build progress bar with. Produces different appearance than ''$progress''.
+
=== $shortest(str,...strN) ===
  
=== $repeat(a,n) ===
+
Returns the first shortest element of its arguments. Can be used with an arbitrary number of strings.
  
Returns ''n'' copies of ''a''. Note that ''a'' is evaluated once before its value is used, so ''$repeat'' cannot be used for loops.
+
=== $strchr(str,char) ===
  
=== $replace(a,b,c) ===
+
Returns position of first occurrence of character ''char'' in string ''str''.
  
Replaces all occurrences of string ''b'' in string ''a'' with string ''c''.
+
Example: ''$strchr(abca,a)'' → 1
  
Can also be used with an arbitrary number of arguments. Note that ''$replace(a,b1,c1,b2,c2)'' is generally not the same as ''$replace($replace(a,b1,c1),b2,c2)''.
+
=== $strrchr(str,char) ===
  
Example: ''$replace(ab,a,b,b,c)'' → "bc", ''$replace($replace(ab,a,b),b,c)'' → "cc"
+
Returns positions of last occurrence of character ''char'' in string ''str''.
  
=== $right(a,len) ===
+
Example: ''$strrchr(abca,a)'' → 4
  
Returns the first ''len'' characters from the right of ''a''.
+
=== $strstr(str1,str2) ===
  
=== $roman(n) ===
+
Returns position of first occurrence of string ''str2'' in string ''str1''. Function is case-sensitive.
  
Formats the integer number ''n'' in roman notation.
+
=== $strcmp(str1,str2) ===
  
=== $rot13() ===
+
Performs a case-sensitive comparison of the strings ''str1'' and ''str2''.
  
Performs [http://en.wikipedia.org/wiki/ROT13 ROT13] transformation to given string.
+
=== $stricmp(str1,str2) ===
  
Example: ''$rot13('foobar2000')'' → "sbbone2000".
+
Performs a case-insensitive comparison of the strings ''str1'' and ''str2''.
  
=== $shortest ===
+
=== $stripprefix(str) ===
  
Returns the shortest of its arguments. Can be used with an arbitrary number of strings.
+
Removes ''A'' and ''The'' prefixes from string ''str''.  
  
=== $strchr(s,c) ===
+
=== $stripprefix(str,prefix1,prefix2,...) ===
  
Finds first occurence of character ''c'' in string ''s''.
+
Removes the specified prefixes from string ''str''.  
  
Example: ''$strchr(abca,a)'' → 1
+
=== $substr(str,from,to) ===
  
=== $strrchr(s,c) ===
+
Returns substring of string ''str'', starting from ''FROM''-th character and ending at ''TO''-th character.
  
Finds last occurence of character ''c'' in string ''s''.
+
=== $swapprefix(str) ===
  
Example: ''$strrchr(abca,a)'' → 4
+
Moves ''A'' and ''The'' prefixes to the end of string ''str''.
  
=== $strstr(s1,s2) ===
+
=== $swapprefix(str,prefix1,prefix2,...) ===
  
Finds first occurence of string ''s2'' in string ''s1''.
+
Moves the specified prefixes to the end of string ''str''.  
  
=== $strcmp(s1,s2) ===
+
=== $trim(str) ===
  
Performs a case-sensitive comparison of the strings ''s1'' and ''s2''.
+
Removes leading and trailing spaces from string ''str''.
 
+
=== $stricmp(s1,s2) ===
+
 
+
Performs a case-insensitive comparison of the strings ''s1'' and ''s2''.
+
 
+
=== $substr(s,m,n) ===
+
 
+
Returns substring of string ''s'', starting from ''m''-th character and ending at ''n''-th character.
+
 
+
=== $trim(s) ===
+
 
+
Removes leading and trailing spaces from string ''s''.
+
  
 
=== $tab() ===
 
=== $tab() ===
Line 501: Line 419:
 
Inserts one tabulator character.
 
Inserts one tabulator character.
  
=== $tab(n) ===
+
=== $tab(count) ===
  
Inserts ''n'' tabulator characters.
+
Inserts ''count'' tabulator characters.
  
=== $upper(s) ===
+
=== $upper(str) ===
  
Converts string ''s'' to uppercase.
+
Converts string ''str'' to uppercase.
  
= Track info =
+
== Track info fields and functions ==
  
The functions and fields in this section can be used to access information about tracks. See [[Foobar2000:0.9 Track Info Panel Mod (foo uie trackinfo mod)|this]] for more info about Track info mod.
+
The functions and fields in this section can be used to access information about tracks.
  
== Metadata ==
+
=== Metadata fields and functions ===
  
=== $meta(name) ===
+
Generally, metadata from the files (whether in tags or a cue sheet) is mapped directly to a field which can be referenced case-insensitively. For example, the first tag named ''URL'' can be referenced as ''%url%'', and the first standard comment tag can be referenced as ''%comment%''.
 +
 
 +
The following functions are also available for accessing metadata:
 +
 
 +
==== $meta(name) ====
 
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ", " as separator.
 
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ", " as separator.
  
Example: ''$meta(artist)'' → "He, She, It"
+
Example: ''$meta(artist)'' → "He, She, They"
  
=== $meta(name,n) ===
+
==== $meta(name,n) ====
 
Returns value of ''n''-th (0,1,2 and so on) tag called ''name''.
 
Returns value of ''n''-th (0,1,2 and so on) tag called ''name''.
  
 
Example: ''$meta(artist,1)'' → "She"
 
Example: ''$meta(artist,1)'' → "She"
  
=== $meta_sep(name,sep) ===
+
==== $meta_sep(name,sep) ====
 
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ''sep'' as separator.
 
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ''sep'' as separator.
  
Example: ''$meta_sep(artist,' + ')'' → "He + She + It"
+
Example: ''$meta_sep(artist,' + ')'' → "He + She + They"
  
=== $meta_sep(name,sep,lastsep) ===
+
==== $meta_sep(name,sep,lastsep) ====
 
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ''sep'' as separator between all but the last two values which are concatenated with ''lastsep''.
 
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ''sep'' as separator between all but the last two values which are concatenated with ''lastsep''.
  
Example: ''$meta_sep(artist,', ',', and ')'' → "He, She, and It"
+
Example: ''$meta_sep(artist,', ',', and ')'' → "He, She, and They"
  
=== $meta_test(...) ===  
+
==== $meta_test(...) ====
 
Returns ''1'', if all given tags exist, ''undefined'' otherwise.
 
Returns ''1'', if all given tags exist, ''undefined'' otherwise.
  
 
Example: ''$meta_test(artist,title)'' → true
 
Example: ''$meta_test(artist,title)'' → true
  
=== $meta_num(name) ===
+
==== $meta_num(name) ====
 
Returns the number of values for the tag called ''name''.
 
Returns the number of values for the tag called ''name''.
  
 
Example: ''$meta_num(artist)'' → 3
 
Example: ''$meta_num(artist)'' → 3
  
=== $tracknumber() ===
+
=== Remapped metadata fields ===
Returns the tracknumber padded to 2 digits with zeroes.
+
  
=== $tracknumber(n) ===
+
The following fields have special remapped values to make writing title format scripts more convenient:
Returns the tracknumber padded to ''n'' digits with zeros.
+
  
== Technical information ==
+
==== %album artist% ====
 +
Name of the artist of the album specified track belongs to. Checks following metadata fields, in this order: "album artist", "artist", "composer", "performer". The difference between this and ''%artist%'' is that ''%album artist%'' is intended for use where consistent value across entire album is needed even when per-track artists values vary.
 +
 
 +
==== %album% ====
 +
Name of the album specified track belongs to. Checks following metadata fields, in this order: "album", "venue".
 +
 
 +
==== %artist% ====
 +
Name of the artist of the track. Checks following metadata fields, in this order: "artist", "album artist", "composer", "performer". For a SHOUTcast stream which contains metadata, it is the StreamTitle up to the first "-" character.
 +
 
 +
==== %discnumber% ====
 +
Index of disc specified track belongs to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.
 +
 
 +
==== %totaldiscs% ====
 +
Index of total discs specified tracks belong to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.
 +
 
 +
==== %track artist% ====
 +
Name of the artist of the track; present only if ''%album artist%'' is different than ''%artist%'' for specific track. Intended for use together with ''%album artist%'', to indicate track-specific artist info, e.g. "%album artist% - %title%[ '//' %track artist%]". In this case, the last part will be displayed only when track-specific artist info is present.
 +
 
 +
==== %title% ====
 +
Title of the track. If "title" metadata field is missing, file name is used instead. For a SHOUTcast stream which contains metadata, it is the StreamTitle after the first "-" character.
 +
 
 +
==== %tracknumber% ====
 +
Two-digit index of specified track within the album. Available only when "tracknumber" field is present in track’s metadata. An extra '0' is placed in front of single digit track numbers (5 becomes 05) &ndash; otherwise the tracknumber field is returned unchanged (e.g. the following values remain as they are: 006, 05, 104, A3, two, -1, -).
 +
 
 +
==== %track number% ====
 +
Similar to %tracknumber%, however single digit track numbers are not reformatted to have an extra 0.
 +
 
 +
=== Technical information fields ===
 +
 
 +
==== %bitrate% ====
 +
Bitrate of the track in kilobits per second. VBR files will show a dynamic display for currently played track (outside of the playlist).
 +
 
 +
==== %channels% ====
 +
Number of channels in the track, as text; either "mono", "stereo" for 1 or 2 channels, respectively, otherwise a number followed by "ch", e.g. "6ch".
 +
 
 +
==== %codec% ====
 +
Name of codec used to encode the track, e.g. PCM, FLAC, MP3, or AAC. If exact codec name is not available, file extension is used. The Default UI's standard Codec column displays the same info, but sometimes adds details, e.g. "MP3 / VBR V2" or "AAC / LC".
 +
 
 +
==== %filesize% ====
 +
The exact file size in bytes.
 +
Old version: <code>%_filesize%</code>
 +
 
 +
==== %filesize_natural% ====
 +
The approximate file size, automatically formatted in appropriate units such as megabytes or kilobytes, e.g. "8.49 MB"
 +
 
 +
==== %length% ====
 +
The length of the track formatted as hours, minutes, and seconds, rounded to the nearest second.
 +
Old version: <code>%_time_total%</code>
 +
 
 +
==== %length_ex% ====
 +
The length of the track formatted as hours, minutes, seconds, and milliseconds, rounded to the nearest millisecond.
 +
 
 +
==== %length_seconds% ====
 +
The length of the track in seconds, rounded to the nearest second.
 +
Old version: <code>%_time_total_seconds%</code>
 +
 
 +
==== %length_seconds_fp% ====
 +
The length of the track in seconds as a floating point number.
 +
 
 +
==== %length_samples% ====
 +
The length of the track in samples.
 +
 
 +
==== %samplerate% ====
 +
Sample rate of the track, in Hz.
 +
 
 +
=== Technical information functions ===
  
=== $info(name) ===
+
==== $info(name) ====
 
Returns value of technical information field called ''name''.
 
Returns value of technical information field called ''name''.
  
Line 561: Line 546:
  
 
Here is an '''informative''' list of recognized fields. Some of these depend on the media file type being queried.
 
Here is an '''informative''' list of recognized fields. Some of these depend on the media file type being queried.
 
(→See also: [[Foobar2000_Talk:Titleformat_Reference#Other_information|Talk page]])
 
  
 
{| border="0" cellspacing="0" cellpadding="2"
 
{| border="0" cellspacing="0" cellpadding="2"
Line 590: Line 573:
 
|channels
 
|channels
 
| style="background-color:#EEF"|'''Channels''' count (''e.g.'' 2 <nowiki>[for stereo]</nowiki>)
 
| style="background-color:#EEF"|'''Channels''' count (''e.g.'' 2 <nowiki>[for stereo]</nowiki>)
 +
|-
 +
|channel_mode
 +
| style="background-color:#EEF"|'''Channel Mode''', description of channels (''e.g.'' 3 front, 2 rear surround channels + LFE)
 
|-
 
|-
 
|bitspersample
 
|bitspersample
Line 606: Line 592:
 
|-
 
|-
 
|ENC_DELAY
 
|ENC_DELAY
| style="background-color:#EEF"|LAME proprietary MP3 '''enc_delay''' value (''e.g.'' 576)
+
| style="background-color:#EEF"|LAME proprietary MP3 '''enc_delay''' value for gapless playback (''e.g.'' 576)
 
|-
 
|-
 
|ENC_PADDING
 
|ENC_PADDING
| style="background-color:#EEF"|LAME proprietary MP3 '''enc_padding''' value (''e.g.'' 1536)
+
| style="background-color:#EEF"|LAME proprietary MP3 '''enc_padding''' value for gapless playback (''e.g.'' 1536)
 
|-
 
|-
 
|MP3_ACCURATE_LENGTH
 
|MP3_ACCURATE_LENGTH
| style="background-color:#EEF"|'''mp3_accurate_length''' supported (LAME proprietary header)? (''e.g.'' yes)
+
| style="background-color:#EEF"|MP3 duration (%length% etc.) takes into account LAME or iTunes gapless playback info (''e.g.'' yes)*
 
|-
 
|-
 
|MP3_STEREO_MODE
 
|MP3_STEREO_MODE
Line 624: Line 610:
 
|}
 
|}
  
=== $channels() ===
 
Returns number of channels in text format.
 
  
Example: ''$channels()'' → "stereo"
+
<div style="font-size: 90%"><nowiki>*</nowiki> ''MP3_ACCURATE_LENGTH won't exist if gapless playback info isn't present or the file is not an MP3. The info can be in a LAME tag in the VBR header, or in an iTunSMPB ID3v2 comment tag. Gapless playback info is taken into account in .m4a files, but there's no special field to say so.''</div>
  
=== %replaygain_album_gain% ===
+
==== $channels() ====
 +
The number of channels in text format.
  
Returns ReplayGain album gain value.
+
Example: ''$channels()'' → "stereo"
  
=== %replaygain_album_peak% ===
+
==== %replaygain_album_gain% ====
 +
The ReplayGain album gain value.
  
Returns ReplayGain album peak value.
+
==== %replaygain_album_peak% ====
 +
The ReplayGain album peak value.
  
=== %replaygain_track_gain% ===
+
==== %replaygain_album_peak_db% ====
 +
The ReplayGain album peak value in decibels.
  
Returns ReplayGain track gain value.
+
==== %replaygain_track_gain% ====
 +
The ReplayGain track gain value.
  
=== %replaygain_track_peak% ===
+
==== %replaygain_track_peak% ====
 +
The ReplayGain track peak value.
  
Returns ReplayGain track peak value.
+
==== %replaygain_track_peak_db% ====
 +
The ReplayGain track peak value in decibels.
  
== Special fields ==
+
=== Special fields ===
  
=== $extra(name) ===
 
Returns the value of the special field called ''name''. These fields can also be accessed as ''%_name%''; note the additional underscore. This syntax is from an older version of Foobar2000 {{Foobar2000v08}}. The following fields can be used normally.
 
 
==== %filename% ====
 
==== %filename% ====
Returns the filename without directory and extension.
+
The filename without directory and extension.
 +
 
 
==== %filename_ext% ====
 
==== %filename_ext% ====
Returns the filename with extension, but without the directory.
+
The filename with extension, but without the directory.
 +
 
 
==== %directoryname% ====
 
==== %directoryname% ====
Returns the name of the parent directory only, not the complete path.
+
The name of the parent directory only, not the complete path.
==== %lastmodified% ====
+
 
Returns the date and time the file was last modified. Eg: ''2005-12-22 00:04:10''
+
==== %last_modified% ====
 +
The date and time the file was last modified. Eg: ''2005-12-22 00:04:10''
 +
 
 
==== %path% ====
 
==== %path% ====
Returns the path.
+
The complete path, including the filename and extension.
==== %path_raw% ====
+
 
Returns the path as URL including the protocol scheme.
+
==== %_path_raw% ====
 +
The path as URL including the protocol scheme.
 +
 
 
==== %subsong% ====
 
==== %subsong% ====
Returns the subsong index. The subsong index is used to distuingish multiple tracks in a single file, for example for cue sheets, tracker modules and various container formats.
+
The subsong index. The subsong index is used to distuingish multiple tracks in a single file, for example for cue sheets, tracker modules and various container formats.
==== $extra(foobar2000_version) ====
+
Returns a string representing the version of foobar2000.
+
  
= Variable operations =
+
==== %_foobar2000_version% ====
 +
A string representing the version of foobar2000.
  
Variables can be used to store strings and number. They cannot store truth values. They are best used to store intermediate results that you need multiple times. Variable names are not case-sensitive.
+
== Time and date functions ==
 +
 
 +
These functions are used to manipulate time/date strings, notably (but not limited to), [[Foobar2000:Titleformat_Playback_Statistics|those gathered]] by the [[Foobar2000:Components/Playback Statistics v3.x (foo playcount)|Playback Statistics component]].
 +
 
 +
=== $year(time) ===
 +
Retrieves the year part (formatted as four digits) from a time/date string.
 +
 
 +
=== $month(time) ===
 +
Retrieves the month part (formatted as two digits) from a time/date string.
 +
 
 +
=== $day_of_month(time) ===
 +
Retrieves the day of month part (formatted as two digits) from a time/date string.
 +
 
 +
=== $date(time) ===
 +
Retrieves the date part (formatted as YYYY-MM-DD) from a time/date string.
 +
 
 +
=== $time(time) ===
 +
Retrieves the time part (formatted as HH:MM:SS or HH:MM) from a date/time string.
 +
 
 +
== Variable operations ==
 +
 
 +
Variables can be used to store strings and numbers. They cannot store truth values. They are best used to store intermediate results that you need multiple times. Variable names are not case-sensitive.
  
 
For example:
 
For example:
Line 686: Line 701:
 
2000</pre>
 
2000</pre>
 
|}
 
|}
 +
 
=== $get(name) ===
 
=== $get(name) ===
 
+
Returns the value that was last stored in the variable ''name'', if the variable was not defined (yet), it returns nothing. The truth value returned by ''$get'' indicates if the variable ''name'' was defined and is a non-empty string.
Returns the value that was last stored in the variable ''name'', if the variable was not defined (yet), it returns nothing. The truth value returned by ''$get'' indicates if the variable ''name'' was defined
+
  
 
=== $put(name,value) ===
 
=== $put(name,value) ===
 
+
Stores ''value'' in the variable ''name'' and returns ''value'' unaltered.
Stores ''value'' in the variable ''name'' and returns ''value'' unaltered
+
  
 
=== $puts(name,value) ===
 
=== $puts(name,value) ===
 +
Stores ''value'' in the variable ''name'' and returns nothing.
  
Stores ''value'' in the variable ''name'' and returns nothing
+
== Component-specific fields and functions ==
  
= Component-provided fields and functions on tracks =
+
This section lists fields and functions which are specific to certain components. Unless otherwise stated, the fields and functions are only usable in the context of those components.
  
This section lists components that provide additional fields and functions that are useable in the context of any track.
+
=== Now playing info ===
  
== Playback statistics ==
+
The following fields related to the currently playing item are only usable in certain locations outside of the playlist, e.g. in the status bar, the main window title and the copy command script.
  
* [http://www.foobar2000.org/beta/components.html Playback statistics homepage]
+
==== %playback_time% ====
* [[Foobar2000:Titleformat Playback Statistics|Playback statistics titleformat reference]]
+
The elapsed time formatted as [HH:]MM:SS.
  
= Component-specific fields and functions =
+
==== %playback_time_seconds% ====
 +
The elapsed time in seconds.
 +
Old version: <code>%_time_elapsed%</code>
  
This section lists components that provide additional fields and functions that are only usable in the context of the particular component.
+
==== %playback_time_remaining% ====
 +
The time remaining until the track ends, formatted as [HH:]MM:SS.
 +
Old version: <code>%_time_remaining%</code>
  
== Album list ==
+
==== %playback_time_remaining_seconds% ====
 +
The time remaining until the track ends, in seconds.
 +
Old version: <code>%_time_remaining_seconds%</code>
  
The official album list component supports creating multiple tree entries using special commands.
+
=== Playlist-only fields ===
  
* [http://www.foobar2000.org/ Album list homepage]
+
The following fields are only usable in playlist display formatting (i.e., the column title formatting patterns).
* [[Foobar2000:Titleformat Album List|Album list titleformat reference]]
+
  
== Columns UI ==
+
==== %isplaying% ====
 +
"1" if file is currently playing, empty string otherwise.
  
* [http://music.morbo.org/wiki/columns_ui:manual Columns UI homepage]
+
==== %ispaused% ====
* [http://music.morbo.org/wiki/columns_ui:config:global_variables Global variables reference]
+
"1" if playback is paused, empty string otherwise.
* [http://music.morbo.org/wiki/columns_ui:config:colour_string Playlist colors reference]
+
* [http://music.morbo.org/wiki/columns_ui:config:playlist_switcher_titleformatting Playlist switcher reference]
+
  
== Cwbowron's titleformatting (foo_cwb_hooks) ==
+
==== %list_index% ====
 +
A zero-padded playlist index of specified item. The first item is at index 1.
  
Cwbowron's titleformatting, <tt>foo_cwb_hooks</tt>, adds various functions and variables to global titleformatting.
+
==== %list_total% ====
 +
The number of items in the playlist.
 +
 
 +
==== %queue_index% ====
 +
Index of the specified item in the playback queue. If the item has been queued multiple times, %queue_index% evaluates to the first index.
 +
 
 +
==== %queue_indexes% ====
 +
List of indexes of the specified item in the playback queue. Same as %queue_index% unless the item has been queued more than once.
 +
 
 +
==== %queue_total% ====
 +
Total amount of tracks in playback queue. Available only for queued tracks, for technical reasons.
 +
 
 +
=== Playlist text color ===
 +
 
 +
==== Dimmed and highlighted text ====
 +
 
 +
In the Default UI playlist, text color can be adjusted by enclosing it in angle-brackets. The only options are to make the text dimmer (mixing the default color with the background color) or brighter (mixing the default color with the highlight color):
 +
 
 +
* ''&lt;text>'' – dim ''text''
 +
* ''&lt;&lt;text>>'' – dimmer ''text''
 +
* ''&lt;&lt;&lt;text>>>'' – dimmest ''text''
 +
* ''>text&lt;'' – bright ''text''
 +
* ''>>text&lt;&lt;'' – brighter ''text''
 +
* ''>>>text&lt;&lt;&lt;'' – brightest ''text''
 +
 
 +
==== Historical and Columns UI color functions ====
 +
 
 +
Prior to version 1.0, the default UI playlist supported the following color functions, which are still available in the Columns UI playlist:
 +
 
 +
===== $blend(color1,color2,part,total) =====
 +
Returns a color that is a blend between ''color1'' and ''color2''. If ''part'' is smaller than or equal to zero, ''color1'' is returned. If ''part'' is greater than or equal to ''total'', ''color2'' is returned. Otherwise a blended color is returned that is ''part'' parts ''color1'' and ''total''-''part'' parts ''color2''. The blending is performed in the RGB color space.
 +
 
 +
===== $hsl() =====
 +
Resets the text color to the default color.
 +
 
 +
===== $hsl(h,s,l) =====
 +
Sets the color for text in the HSL color space. ''h'', ''s'' and ''l'' are the hue, saturation, and lightness of the color for unselected text. The color for selected text is set to the inverse color.
 +
The ranges of ''h'', ''s'', and ''l'' are from 0 to 240; the function is designed to interpret those values in the same way as the standard Windows color dialog.
 +
 
 +
===== $hsl(h1,s1,l1,h2,s2,l2) =====
 +
Sets the color for text in the HSL color space. ''h1'', ''s1'' and ''l1'' are the hue, saturation, and lightness of the color for unselected text. ''h2'', ''s2'' and ''l2'' are the hue, saturation, and lightness of the color for selected text.
 +
 
 +
===== $rgb() =====
 +
Resets the text color to the default color.
 +
 
 +
===== $rgb(r,g,b) =====
 +
Sets the color for text. ''r'', ''g'' and ''b'' are the red, green and blue component of the color for unselected text. The color for selected text is set to the inverse color.
 +
 
 +
===== $rgb(r1,g1,b1,r2,g2,b2) =====
 +
Sets the color for text. ''r1'', ''g1'' and ''b1'' are the red, green and blue component of the color for unselected text. ''r2'', ''g2'' and ''b2'' are the red, green and blue component of the color for selected text.
 +
 
 +
===== $transition(string,color1,color2) =====
 +
Inserts color codes into ''string'', so that the first character has ''color1'', the last character has ''color2'', and intermediate characters have blended colors. The blending is performed in the RGB color space. Note that color codes are additional characters that will also be counted by string manipulation functions. For example, if you need to truncate a string, you should do this before applying ''$transition''.
 +
 
 +
=== Album List ===
 +
 
 +
* [[Foobar2000:Titleformat_Album_List|Album List Title Formatting]]
 +
* [[Foobar2000:Preferences:Album List|Preferences: Album List]]
 +
 
 +
=== Playback Statistics ===
 +
 
 +
The foo_playcount component adds a number of fields for playback statistics and ratings. The fields can be used anywhere track info can be displayed. See the documentation for details:
 +
* [http://www.foobar2000.org/components/view/foo_playcount Playback statistics homepage]
 +
* [[Foobar2000:Titleformat Playback Statistics|Playback statistics titleformat reference]]
  
* [[Foobar2000:Components 0.9/Cwbowron's Title formating (foo cwb hooks)|foo_cwb_hooks titleformat reference]]
+
=== Playlist Organizer ===
  
== Panels UI ==
+
This component adds a number of fields to control the display of a list of playlists. See the documentation for details:
 +
* [[Foobar2000:Components/Playlist Organizer (foo_plorg)#Nodes|Playlist Organizer: Nodes Title Formatting]]
  
* [[Foobar2000:Components 0.9/Panels UI (foo ui panels)|Panels UI]]
+
=== Columns UI ===
* [[Foobar2000:Components 0.9/Panels UI (foo ui panels)/Commands|Panels UI titleformat reference]]
+
  
= Additional Reading =
+
This component replaces the Default UI framework, including the playlist. See the documentation for details:
 +
* [http://yuo.be/columns.php Columns UI homepage]
 +
* [http://yuo.be/wiki/columns_ui:config:global_variables Global variables reference]
 +
* [http://yuo.be/wiki/columns_ui:config:colour_string Playlist colors reference]
 +
* [http://yuo.be/wiki/columns_ui:config:playlist_switcher_titleformatting Playlist switcher reference]
  
* [[Foobar2000:Titleformat_Introduction|Introduction to titleformat scripts]]
+
== Additional Reading ==
* '''titleformat_help.html''' in your Foobar2000 directory (ie C:\Program Files\foobar2000\titleformat_help.html) file:///C:/Program%20Files/foobar2000/titleformat_help.html
+
  
 +
* [[Foobar2000:Title Formatting Introduction|Introduction to titleformat scripts]]
 +
* The file '''titleformat_help.html''' in your Foobar2000 directory, e.g. file:///C:/Program%20Files%20(x86)/foobar2000/titleformat_help.html
  
 
[[Category:foobar2000 Guides|Titleformat Reference]]
 
[[Category:foobar2000 Guides|Titleformat Reference]]

Latest revision as of 08:07, 7 December 2023

This article contains information about built-in title formatting functions and field references, plus additional documentation about fields and functions which can only be used in specific components or which are provided by specific components.

Please see Title Formatting Introduction for a general overview of title format syntax and its basic rules. The article Titleformat Examples offers user-submitted examples of code for specific purposes; feel free to add your own if you think it can be of use to others.

For details of the query syntax, which uses some of these fields to find files for playlists, etc., see the Query Syntax article.

Contents

Syntax

A title formatting script consists of any combination of literal text, field references, function calls, comments, and line break characters. The script always outputs a text string (which can be empty).

A comment is a line starting with two slashes, e.g. // this is a comment.

A field reference is a field name enclosed in percent signs, for example %artist%.

A function call starts with a dollar sign, followed by the function name and the parameter list. A parameter list can either be empty – denoted as () – or contain one or more parameters separated by commas, for example $abbr(%artist%). A parameter can be literal text, a field reference, or another function call. Note that there must be no whitespace between the dollar sign and the function name, or the function name and the opening parenthesis of the parameter list.

Any other text is literal text. In literal text, the character %, $, [, ], or ' (apostrophe/single quote) must be escaped by enclosing it in ' (apostrophe/single quote) characters. For example, '[' (a left bracket in single quotes) results in a literal [ (left bracket). As a special case, '' (two single quotes in a row) results in one single quote. In the playlist, < and > are also special; see Dimmed and highlighted text.

When the script is evaluated, the output string is assembled by evaluating the function parameters, function calls, and field references. Comments and line break characters (CR and LF/newline) are ignored; to output a line break, use $crlf(). Each field reference becomes the field's value, as a string. Each function becomes a string or number, and/or a truth value (not output) which can be used by another function.

Note: The interface for entering custom columns and grouping schemes for the Default UI playlist does not support line breaks; scripts must be written all on one line, without comments.

Arithmetic functions

The functions in this section can be used to perform arithmetic on integer numbers. A string will be automatically converted to a number and vice versa. The conversion to a number uses the longest prefix of the string that can be interpreted as number. Leading whitespace is ignored. Decimal points are not supported. Examples:

  • c3po → 0
  • 4.8 → 4
  • -12 → -12
  • - 12 → 0

$add(a,b, ...)

Adds a and b.

Can be used with an arbitrary number of arguments. $add(a,b,...) is the same as $add($add(a,b),...).

$div(a,b)

Divides a by b and rounds down to an integer. If b evaluates to zero, it returns a.

Can be used with an arbitrary number of arguments. $div(a,b,...) is the same as $div($div(a,b),...).

$greater(a,b)

Returns true, if a is greater than b, otherwise false.

$max(a,b)

Returns the maximum of a and b.

Can be used with an arbitrary number of arguments. $max(a,b,...) is the same as $max($max(a,b),...).

$min(a,b)

Returns the minimum of a and b.

Can be used with an arbitrary number of arguments. $min(a,b,...) is the same as $min($min(a,b),...).

$mod(a,b)

Computes the remainder of dividing a through b. The result has the same sign as a. If b evaluates to zero, the result is a.

Can be used with an arbitrary number of arguments. $mod(a,b,...) is the same as $mod($mod(a,b),...).

$mul(a,b)

Multiplies a and b.

Can be used with an arbitrary number of arguments. $mul(a,b,...) is the same as $mul($mul(a,b),...).

$muldiv(a,b,c)

Multiplies a and b, then divides by c. The result is rounded to the nearest integer.

$rand()

Generates a random number in the range from 0 to 232-1. Available only in sort-related contexts, such as the Edit → Sort → Sort by ... menu command.

$sub(a,b)

Subtracts b from a.

Can be used with an arbitrary number of arguments. $sub(a,b,...) is the same as $sub($sub(a,b),...).

Boolean functions

The functions in this section can be used to work with truth values (true and false), which have no explicit representation in titleformat scripts. They do not return a string or number value. You can use them for more complex conditions with $if and related functions.

Foobar does not have a concept of TRUE and FALSE in a programming language sense where 0 or empty string are considered FALSE and other values TRUE. Therefore there is no difference between numeric 0 and string representation '0' which both are considered as values, and being attached a boolean value FALSE. Apostrophes are only required to escape certain syntax characters. Values are treated as numbers during arithmetic operations like $add().

$and(expr, ...)

Logical And of an arbitrary number of arguments. Returns true, if and only if all expr arguments evaluate to true.

$or(expr, ...)

Logical Or of an arbitrary number of arguments. Returns true, if at least one expression evaluates to true.

$not(expr)

Logical Not. Returns the logical opposite of EXPR: false, if expr is true and true if expr is false.

$xor(expr,...)

Logical Exclusive-or of an arbitrary number of arguments. Returns true, if an odd number of arguments evaluate to true.

Special case: $xor(expr1,expr2) returns true, if EXPR1 or EXPR2 is true. If both expressions are true, returns false.

Control flow functions

The functions in this section can be used to conditionally execute statements.

[...] (conditional section)

Evaluates the expression between [ and ]. If it has the truth value true, its string value and the truth value true are returned. Otherwise an empty string and false are returned.

Example: [%artist%] returns the value of the artist tag, if it exists. Otherwise it returns nothing, when artist would return "?".

$if(cond,then)

If cond evaluates to true, the then part is evaluated and its value returned. Otherwise, false is returned.

Plain strings are FALSE. Field lookups and functions can introduce a boolean value of TRUE.
Examples:
1

#False: 
$if(0,True,False)
# False: 
$if('0',True,False)
# True or False: 
[$add(%rating%,1)]


The last one would display the value of %rating% plus one, if and only if %rating% is set for the track.

2 Ignore inserting the %album artist%, if it contains the word "various".

# Wrong: 
$if([%album artist%=Various],,%artist%-)
# Good approach:
$if($stricmp(%album artist%,Various),,%artist%-) 

$if(cond,then,else)

If cond evaluates to true, the then part is evaluated and its value returned. Otherwise, the else part is evaluated and its value returned.

$if2(expr,else)

Like $if(expr,expr,else) except that expr is only evaluated once. In other words, if expression expr is true, expr is returned, otherwise the else part is evaluated and expr is returned as true.

$if3(a1,a2,...,aN,else)

Evaluates arguments a1 ... aN, until one is found that evaluates to true. If that happens, its value is returned. Otherwise the else part is evaluated and its value returned.

$ifequal(int1,int2,then,else)

Compares the integer numbers int1 and int2, if int1 is equal to int2, the then part is evaluated and its value returned. Otherwise the else part is evaluated and its value returned.

$ifgreater(int1,int2,then,else)

Compares the integer numbers int1 and int2, if int1 is greater than int2, the then part is evaluated and its value returned. Otherwise the else part is evaluated and its value returned.

$iflonger(str,n,then,else)

Compares the length of the string str to the number n, if str is longer than n characters, the then part is evaluated and its value returned. Otherwise the else part is evaluated and its value returned.

$select(n,a1,...,aN)

If the value of n is between 1 and N, an is evaluated and its value returned. Otherwise false is returned.

String functions

The functions in this section can be used to manipulate character strings.

$abbr(str)

Returns abbreviation of string str. Words which begin with an alphanumeric character are shortened to the first character. Spaces and parentheses are stripped. Example:

  • $abbr('This is a Long Title (12-inch version) [needs tags]') → TiaLT1v[needst

$abbr(str,len)

Returns abbreviation of str, if str is longer than len characters, otherwise returns str.

$ansi(str)

Converts string str to system codepage and back. Any characters that are not present in the system codepage will be removed / replaced. Useful for mass-renaming files to ensure compatibility with non-unicode-capable software.

$ascii(str)

Converts string str to ASCII. Any characters that are not present in ASCII will be removed / replaced.

$caps(str)

Converts first letter in every word of string str to uppercase, and all other letters to lowercase.

$caps2(str)

Converts first letter in every word of string str to uppercase, and leaves all other letters as they are.

$char(nbr)

Returns Unicode character of nbr. You can search for characters and find the matching decimal number on this site.

$crc32(str)

Computes the CRC32 of the string str as a number. Intended for use in coloring scripts.

Example: $rgb($mod($crc32(%album%),256),128,128)

$crlf()

Inserts end-of-line marker (carriage return, line feed). Can be used to generate multiple lines in the output, for example for the tooltip of the system notification area ("systray") icon.

$cut(str,len)

Returns first len characters from the left of the string str. This function is the same as $left(a,len). Negative numbers produce the entire string. Examples:

  • $cut('abc123',3) → abc
  • $cut('abc123',0) → (nothing)
  • $cut('abc123',-1) → abc123

$directory(path)

Extracts only the directory name (not full path, ie given path as 'D:\music\jazz\filename.mp3', this will output 'jazz') from the file path.

$directory(path,n)

Extracts directory name from the file path; goes up by n levels.

$directory_path(path)

Extracts directory path from the file path. ie. given path as 'D:\music\jazz\filename.mp3', this will output 'D:\music\jazz'

$ext(path)

Extracts file extension from string path; a file name or full path.

$filename(path)

Extracts file name from full path.

$fix_eol(str)

If str contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by " (...)". Otherwise str is returned unaltered.

$fix_eol(str,indicator)

If str contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by indicator. Otherwise str is returned unaltered.

$hex(int,len)

Formats the integer number int in hexadecimal notation with len digits. Pads with zeros from the left if necessary.

$insert(str,insert,n)

Inserts insert into str after n characters.

$left(str,len)

Returns first len characters from the left of the string str. This function is the same as $cut(str,len). Negative numbers produce the entire string. Examples:

  • $left('abc123',3) → abc
  • $left('abc123',0) → (nothing)
  • $left('abc123',-1) → abc123

$len(str)

Returns length of string str in characters.

$len2(str)

Returns length of string str in characters, respecting double-width character rules (double-width characters will be counted as two).

$longer(str1,str2)

Returns true, if string str1 is longer than string str2, false otherwise.

$lower(str)

Converts string str to lowercase.

$longest(arg,...)

Returns the longest of its arguments. Can be used with an arbitrary number of strings.

$num(nbr,len)

Formats the integer number nbr in decimal notation with len characters. Pads with zeros from the left if necessary. len includes the dash when the number is negative. If nbr is not numeric, it is treated as zero. Examples:

  • $num(123,5) → 00123
  • $num(-123,5) → -0123
  • $num(4.8,5) → 00004
  • $num(A1,5) → 00000

$pad(str,len)

Creates a left-aligned version of the string str. If str is shorter than len characters, the function adds spaces to the right of str to make the result len characters long. Otherwise the function returns str unchanged.

$pad_right(str,len)

Creates a right-aligned version of the string str. If str is shorter than len characters, the function adds spaces to the left of str to make the result len characters long. Otherwise the function returns str unchanged.

$pad(str,len,char)

Creates a left-aligned version of the string str. If str is shorter than len characters, the function adds char to the right of str to make the result len characters long. Otherwise the function returns str unchanged.

$pad_right(str,len,char)

Creates a right-aligned version of the string str. If str is shorter than len characters, the function adds char to the left of str to make the result len characters long. Otherwise the function returns str unchanged.

$padcut(str,len)

Returns first len characters from the left of str, if str is longer than len characters. Otherwise adds spaces to the right of str to make the result len characters long.

$padcut(str,len,char)

Returns first len characters from the left of str, if str is longer than len characters. Otherwise adds char to the right of str to make the result len characters long.

$padcut_right(str,len)

Returns first len characters from the left of str, if str is longer than len characters. Otherwise adds spaces to the left of str to make the result len characters long.

$padcut_right(str,len,char)

Returns first len characters from the left of str, if str is longer than len characters. Otherwise adds char to the left of str to make the result len characters long.

$progress(pos,range,len,char1,char2)

Creates a progress bar: pos contains position, range contains range, len progress bar length in characters, char1 and char2 are characters to build progress bar with.

Example:$progress(%_time_elapsed_seconds%, %_time_total_seconds%, 20,'#','=') produces "====#===============", the # character is moving with playback position.

$progress2(pos,range,len,char1,char2)

Creates a progress bar: pos contains position, range contains range, len progress bar length in characters, char1 and char2 are characters to build progress bar with. Produces different appearance than $progress.

$repeat(expr,count)

Returns count copies of expr. Note that expr is evaluated once before its value is used, so $repeat cannot be used for loops.

$replace(str,search,replace)

Replaces all occurrences of string search in string str with string replace.

Can also be used with an arbitrary number of arguments. Note that $replace(str,search1,replace1,search2,replace2) is generally not the same as $replace($replace(str,search1,replace1),search2,replace2).

Example: $replace(ab,a,b,b,c) → "bc", $replace($replace(ab,a,b),b,c) → "cc"

$right(str,len)

Returns the first len characters from the right of string str.

$roman(int)

Formats the integer number int in roman notation.

$rot13(str)

Performs ROT13 transformation to given string.

Example: $rot13('foobar2000') → "sbbone2000".

$shortest(str,...strN)

Returns the first shortest element of its arguments. Can be used with an arbitrary number of strings.

$strchr(str,char)

Returns position of first occurrence of character char in string str.

Example: $strchr(abca,a) → 1

$strrchr(str,char)

Returns positions of last occurrence of character char in string str.

Example: $strrchr(abca,a) → 4

$strstr(str1,str2)

Returns position of first occurrence of string str2 in string str1. Function is case-sensitive.

$strcmp(str1,str2)

Performs a case-sensitive comparison of the strings str1 and str2.

$stricmp(str1,str2)

Performs a case-insensitive comparison of the strings str1 and str2.

$stripprefix(str)

Removes A and The prefixes from string str.

$stripprefix(str,prefix1,prefix2,...)

Removes the specified prefixes from string str.

$substr(str,from,to)

Returns substring of string str, starting from FROM-th character and ending at TO-th character.

$swapprefix(str)

Moves A and The prefixes to the end of string str.

$swapprefix(str,prefix1,prefix2,...)

Moves the specified prefixes to the end of string str.

$trim(str)

Removes leading and trailing spaces from string str.

$tab()

Inserts one tabulator character.

$tab(count)

Inserts count tabulator characters.

$upper(str)

Converts string str to uppercase.

Track info fields and functions

The functions and fields in this section can be used to access information about tracks.

Metadata fields and functions

Generally, metadata from the files (whether in tags or a cue sheet) is mapped directly to a field which can be referenced case-insensitively. For example, the first tag named URL can be referenced as %url%, and the first standard comment tag can be referenced as %comment%.

The following functions are also available for accessing metadata:

$meta(name)

Returns value of tag called name. If multiple values of that tag exist, they are concatenated with ", " as separator.

Example: $meta(artist) → "He, She, They"

$meta(name,n)

Returns value of n-th (0,1,2 and so on) tag called name.

Example: $meta(artist,1) → "She"

$meta_sep(name,sep)

Returns value of tag called name. If multiple values of that tag exist, they are concatenated with sep as separator.

Example: $meta_sep(artist,' + ') → "He + She + They"

$meta_sep(name,sep,lastsep)

Returns value of tag called name. If multiple values of that tag exist, they are concatenated with sep as separator between all but the last two values which are concatenated with lastsep.

Example: $meta_sep(artist,', ',', and ') → "He, She, and They"

$meta_test(...)

Returns 1, if all given tags exist, undefined otherwise.

Example: $meta_test(artist,title) → true

$meta_num(name)

Returns the number of values for the tag called name.

Example: $meta_num(artist) → 3

Remapped metadata fields

The following fields have special remapped values to make writing title format scripts more convenient:

%album artist%

Name of the artist of the album specified track belongs to. Checks following metadata fields, in this order: "album artist", "artist", "composer", "performer". The difference between this and %artist% is that %album artist% is intended for use where consistent value across entire album is needed even when per-track artists values vary.

%album%

Name of the album specified track belongs to. Checks following metadata fields, in this order: "album", "venue".

%artist%

Name of the artist of the track. Checks following metadata fields, in this order: "artist", "album artist", "composer", "performer". For a SHOUTcast stream which contains metadata, it is the StreamTitle up to the first "-" character.

%discnumber%

Index of disc specified track belongs to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.

%totaldiscs%

Index of total discs specified tracks belong to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.

%track artist%

Name of the artist of the track; present only if %album artist% is different than %artist% for specific track. Intended for use together with %album artist%, to indicate track-specific artist info, e.g. "%album artist% - %title%[ '//' %track artist%]". In this case, the last part will be displayed only when track-specific artist info is present.

%title%

Title of the track. If "title" metadata field is missing, file name is used instead. For a SHOUTcast stream which contains metadata, it is the StreamTitle after the first "-" character.

%tracknumber%

Two-digit index of specified track within the album. Available only when "tracknumber" field is present in track’s metadata. An extra '0' is placed in front of single digit track numbers (5 becomes 05) – otherwise the tracknumber field is returned unchanged (e.g. the following values remain as they are: 006, 05, 104, A3, two, -1, -).

%track number%

Similar to %tracknumber%, however single digit track numbers are not reformatted to have an extra 0.

Technical information fields

%bitrate%

Bitrate of the track in kilobits per second. VBR files will show a dynamic display for currently played track (outside of the playlist).

%channels%

Number of channels in the track, as text; either "mono", "stereo" for 1 or 2 channels, respectively, otherwise a number followed by "ch", e.g. "6ch".

%codec%

Name of codec used to encode the track, e.g. PCM, FLAC, MP3, or AAC. If exact codec name is not available, file extension is used. The Default UI's standard Codec column displays the same info, but sometimes adds details, e.g. "MP3 / VBR V2" or "AAC / LC".

%filesize%

The exact file size in bytes. Old version: %_filesize%

%filesize_natural%

The approximate file size, automatically formatted in appropriate units such as megabytes or kilobytes, e.g. "8.49 MB"

%length%

The length of the track formatted as hours, minutes, and seconds, rounded to the nearest second. Old version: %_time_total%

%length_ex%

The length of the track formatted as hours, minutes, seconds, and milliseconds, rounded to the nearest millisecond.

%length_seconds%

The length of the track in seconds, rounded to the nearest second. Old version: %_time_total_seconds%

%length_seconds_fp%

The length of the track in seconds as a floating point number.

%length_samples%

The length of the track in samples.

%samplerate%

Sample rate of the track, in Hz.

Technical information functions

$info(name)

Returns value of technical information field called name.

For convenience, the %__name% alias is also available.

Example: $info(channels) → 2

Here is an informative list of recognized fields. Some of these depend on the media file type being queried.

field name Description
General
codec Codec (e.g. MP3)
codec_profile Codec Profile (e.g. CBR)
samplerate Sample Rate, in hertz (e.g. 44100)
bitrate Bitrate, in kilobits per second (e.g. 320)
tool Tool used to produce the file, possibly guessed (e.g. LAME3.97)
encoding Encoding lossiness (e.g. lossy)
channels Channels count (e.g. 2 [for stereo])
channel_mode Channel Mode, description of channels (e.g. 3 front, 2 rear surround channels + LFE)
bitspersample Bits Per Sample (e.g. 16)
tagtype Tag Type, comma-separated list of tag formats (e.g. id3v2|apev2)
cue_embedded Embedded Cuesheet presence (e.g. no [may be empty!])
md5 Audio MD5 hash, if container defines it (e.g. 1E24A910D91EF09A8CF403C9B6963961)
Other
ENC_DELAY LAME proprietary MP3 enc_delay value for gapless playback (e.g. 576)
ENC_PADDING LAME proprietary MP3 enc_padding value for gapless playback (e.g. 1536)
MP3_ACCURATE_LENGTH MP3 duration (%length% etc.) takes into account LAME or iTunes gapless playback info (e.g. yes)*
MP3_STEREO_MODE Stereo mode used in MP3 file (e.g. mono, stereo, joint stereo, etc.)
VERSION Version of tool (e.g. 3.99)
FLAGS Flags of tool (e.g. 22)


* MP3_ACCURATE_LENGTH won't exist if gapless playback info isn't present or the file is not an MP3. The info can be in a LAME tag in the VBR header, or in an iTunSMPB ID3v2 comment tag. Gapless playback info is taken into account in .m4a files, but there's no special field to say so.

$channels()

The number of channels in text format.

Example: $channels() → "stereo"

%replaygain_album_gain%

The ReplayGain album gain value.

%replaygain_album_peak%

The ReplayGain album peak value.

%replaygain_album_peak_db%

The ReplayGain album peak value in decibels.

%replaygain_track_gain%

The ReplayGain track gain value.

%replaygain_track_peak%

The ReplayGain track peak value.

%replaygain_track_peak_db%

The ReplayGain track peak value in decibels.

Special fields

%filename%

The filename without directory and extension.

%filename_ext%

The filename with extension, but without the directory.

%directoryname%

The name of the parent directory only, not the complete path.

%last_modified%

The date and time the file was last modified. Eg: 2005-12-22 00:04:10

%path%

The complete path, including the filename and extension.

%_path_raw%

The path as URL including the protocol scheme.

%subsong%

The subsong index. The subsong index is used to distuingish multiple tracks in a single file, for example for cue sheets, tracker modules and various container formats.

%_foobar2000_version%

A string representing the version of foobar2000.

Time and date functions

These functions are used to manipulate time/date strings, notably (but not limited to), those gathered by the Playback Statistics component.

$year(time)

Retrieves the year part (formatted as four digits) from a time/date string.

$month(time)

Retrieves the month part (formatted as two digits) from a time/date string.

$day_of_month(time)

Retrieves the day of month part (formatted as two digits) from a time/date string.

$date(time)

Retrieves the date part (formatted as YYYY-MM-DD) from a time/date string.

$time(time)

Retrieves the time part (formatted as HH:MM:SS or HH:MM) from a date/time string.

Variable operations

Variables can be used to store strings and numbers. They cannot store truth values. They are best used to store intermediate results that you need multiple times. Variable names are not case-sensitive.

For example:

code output
$put(foo,bar)$char(10)
$get(foo)$char(10)
$get(Foo)$char(10)
$puts(foo,2000)$char(10)
$get(foo)$char(10)
bar
bar
bar

2000

$get(name)

Returns the value that was last stored in the variable name, if the variable was not defined (yet), it returns nothing. The truth value returned by $get indicates if the variable name was defined and is a non-empty string.

$put(name,value)

Stores value in the variable name and returns value unaltered.

$puts(name,value)

Stores value in the variable name and returns nothing.

Component-specific fields and functions

This section lists fields and functions which are specific to certain components. Unless otherwise stated, the fields and functions are only usable in the context of those components.

Now playing info

The following fields related to the currently playing item are only usable in certain locations outside of the playlist, e.g. in the status bar, the main window title and the copy command script.

%playback_time%

The elapsed time formatted as [HH:]MM:SS.

%playback_time_seconds%

The elapsed time in seconds. Old version: %_time_elapsed%

%playback_time_remaining%

The time remaining until the track ends, formatted as [HH:]MM:SS. Old version: %_time_remaining%

%playback_time_remaining_seconds%

The time remaining until the track ends, in seconds. Old version: %_time_remaining_seconds%

Playlist-only fields

The following fields are only usable in playlist display formatting (i.e., the column title formatting patterns).

%isplaying%

"1" if file is currently playing, empty string otherwise.

%ispaused%

"1" if playback is paused, empty string otherwise.

%list_index%

A zero-padded playlist index of specified item. The first item is at index 1.

%list_total%

The number of items in the playlist.

%queue_index%

Index of the specified item in the playback queue. If the item has been queued multiple times, %queue_index% evaluates to the first index.

%queue_indexes%

List of indexes of the specified item in the playback queue. Same as %queue_index% unless the item has been queued more than once.

%queue_total%

Total amount of tracks in playback queue. Available only for queued tracks, for technical reasons.

Playlist text color

Dimmed and highlighted text

In the Default UI playlist, text color can be adjusted by enclosing it in angle-brackets. The only options are to make the text dimmer (mixing the default color with the background color) or brighter (mixing the default color with the highlight color):

  • <text> – dim text
  • <<text>> – dimmer text
  • <<<text>>> – dimmest text
  • >text< – bright text
  • >>text<< – brighter text
  • >>>text<<< – brightest text

Historical and Columns UI color functions

Prior to version 1.0, the default UI playlist supported the following color functions, which are still available in the Columns UI playlist:

$blend(color1,color2,part,total)

Returns a color that is a blend between color1 and color2. If part is smaller than or equal to zero, color1 is returned. If part is greater than or equal to total, color2 is returned. Otherwise a blended color is returned that is part parts color1 and total-part parts color2. The blending is performed in the RGB color space.

$hsl()

Resets the text color to the default color.

$hsl(h,s,l)

Sets the color for text in the HSL color space. h, s and l are the hue, saturation, and lightness of the color for unselected text. The color for selected text is set to the inverse color. The ranges of h, s, and l are from 0 to 240; the function is designed to interpret those values in the same way as the standard Windows color dialog.

$hsl(h1,s1,l1,h2,s2,l2)

Sets the color for text in the HSL color space. h1, s1 and l1 are the hue, saturation, and lightness of the color for unselected text. h2, s2 and l2 are the hue, saturation, and lightness of the color for selected text.

$rgb()

Resets the text color to the default color.

$rgb(r,g,b)

Sets the color for text. r, g and b are the red, green and blue component of the color for unselected text. The color for selected text is set to the inverse color.

$rgb(r1,g1,b1,r2,g2,b2)

Sets the color for text. r1, g1 and b1 are the red, green and blue component of the color for unselected text. r2, g2 and b2 are the red, green and blue component of the color for selected text.

$transition(string,color1,color2)

Inserts color codes into string, so that the first character has color1, the last character has color2, and intermediate characters have blended colors. The blending is performed in the RGB color space. Note that color codes are additional characters that will also be counted by string manipulation functions. For example, if you need to truncate a string, you should do this before applying $transition.

Album List

Playback Statistics

The foo_playcount component adds a number of fields for playback statistics and ratings. The fields can be used anywhere track info can be displayed. See the documentation for details:

Playlist Organizer

This component adds a number of fields to control the display of a list of playlists. See the documentation for details:

Columns UI

This component replaces the Default UI framework, including the playlist. See the documentation for details:

Additional Reading