https://wiki.hydrogenaud.io/api.php?action=feedcontributions&user=24.184.166.112&feedformat=atomHydrogenaudio Knowledgebase - User contributions [en]2024-03-29T00:38:51ZUser contributionsMediaWiki 1.22.7https://wiki.hydrogenaud.io/index.php?title=Foobar2000:Title_Formatting_ReferenceFoobar2000:Title Formatting Reference2020-12-23T16:06:47Z<p>24.184.166.112: /* Track info fields and functions */</p>
<hr />
<div>{{fb2k}}<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
<br />
== Syntax ==<br />
<br />
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).<br />
<br />
A '''comment''' is a line starting with two slashes, e.g. {{code|// this is a comment}}.<br />
<br />
A '''field reference''' is a field name enclosed in percent signs, for example {{code|%artist%}}.<br />
<br />
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.<br />
<br />
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]].<br />
<br />
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.<br />
<br />
'''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.'''<br />
<br />
== Arithmetic functions ==<br />
<br />
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:<br />
* ''c3po'' → 0<br />
* ''4.8'' → 4<br />
* ''-12'' → -12<br />
* ''- 12'' → 0<br />
<br />
=== $add(a,b, ...) ===<br />
<br />
Adds ''a'' and ''b''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$add(a,b,...)'' is the same as ''$add($add(a,b),...)''.<br />
<br />
=== $div(a,b) ===<br />
<br />
Divides ''a'' by ''b'' and rounds down to an integer. If ''b'' evaluates to zero, it returns ''a''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$div(a,b,...)'' is the same as ''$div($div(a,b),...)''.<br />
<br />
=== $greater(a,b) ===<br />
<br />
Returns true, if ''a'' is greater than ''b'', otherwise false.<br />
<br />
=== $max(a,b) ===<br />
<br />
Returns the maximum of ''a'' and ''b''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$max(a,b,...)'' is the same as ''$max($max(a,b),...)''.<br />
<br />
=== $min(a,b) ===<br />
<br />
Returns the minimum of ''a'' and ''b''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$min(a,b,...)'' is the same as ''$min($min(a,b),...)''.<br />
<br />
=== $mod(a,b) ===<br />
<br />
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''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$mod(a,b,...)'' is the same as ''$mod($mod(a,b),...)''.<br />
<br />
=== $mul(a,b) ===<br />
<br />
Multiplies ''a'' and ''b''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$mul(a,b,...)'' is the same as ''$mul($mul(a,b),...)''.<br />
<br />
=== $muldiv(a,b,c) ===<br />
<br />
Multiplies ''a'' and ''b'', then divides by ''c''. The result is rounded to the nearest integer.<br />
<br />
=== $rand() ===<br />
<br />
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.<br />
<br />
=== $sub(a,b) ===<br />
<br />
Subtracts ''b'' from ''a''.<br />
<br />
Can be used with an arbitrary number of arguments. ''$sub(a,b,...)'' is the same as ''$sub($sub(a,b),...)''.<br />
<br />
== Boolean functions ==<br />
<br />
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.<br />
<br />
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()''.<br />
<br />
=== $and(expr, ...) ===<br />
<br />
Logical And of an arbitrary number of arguments. Returns ''true'', if and only if all ''expr'' arguments evaluate to ''true''.<br />
<br />
=== $or(expr, ...) ===<br />
<br />
Logical Or of an arbitrary number of arguments. Returns ''true'', if at least one expression evaluates to ''true''.<br />
<br />
=== $not(expr) ===<br />
<br />
Logical Not. Returns the logical opposite of EXPR: ''false'', if ''expr'' is ''true'' and ''true'' if ''expr'' is false.<br />
<br />
=== $xor(expr,...) ===<br />
<br />
Logical Exclusive-or of an arbitrary number of arguments. Returns ''true'', if an odd number of arguments evaluate to ''true''.<br />
<br />
Special case: ''$xor(expr1,expr2)'' returns ''true'', if EXPR1 or EXPR2 is ''true''. If both expressions are true, returns ''false''.<br />
<br />
== Control flow functions ==<br />
<br />
The functions in this section can be used to conditionally execute statements.<br />
<br />
=== [...] (conditional section) ===<br />
<br />
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.<br />
<br />
Example: ''[%artist%]'' returns the value of the artist tag, if it exists. Otherwise it returns nothing, when ''artist'' would return "?".<br />
<br />
=== $if(cond,then) ===<br />
<br />
If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, ''false'' is returned.<br />
<br />
Plain strings are FALSE. Field lookups and functions can introduce a boolean value of TRUE. <br /><br />
<u>Examples</u>:<br /><br />
<u>1</u><br />
<code><br />
#False: <br />
$if(0,True,False)<br />
# False: <br />
$if('0',True,False)<br />
# True or False: <br />
[$add(%rating%,1)]<br />
</code><br /><br />
The last one would display the value of %rating% plus one, if and only if %rating% is set for the track.<br />
<br />
<u>2</u><br />
Ignore inserting the %album artist%, if it contains the word "various". <br />
<code><br />
# Wrong: <br />
$if([%album artist%=Various],,%artist%-)<br />
# Good approach:<br />
$if($stricmp(%album artist%,Various),,%artist%-) <br />
</code><br />
<br />
=== $if(cond,then,else) ===<br />
<br />
If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, the ''else'' part is evaluated and its value returned.<br />
<br />
=== $if2(expr,else) ===<br />
<br />
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.<br />
<br />
=== $if3(a1,a2,...,aN,else) ===<br />
<br />
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.<br />
<br />
=== $ifequal(int1,int2,then,else) ===<br />
<br />
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.<br />
<br />
=== $ifgreater(int1,int2,then,else) ===<br />
<br />
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.<br />
<br />
=== $iflonger(str,n,then,else) ===<br />
<br />
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.<br />
<br />
=== $select(n,a1,...,aN) ===<br />
<br />
If the value of ''n'' is between 1 and N, ''an'' is evaluated and its value returned. Otherwise ''false'' is returned.<br />
<br />
== String functions ==<br />
<br />
The functions in this section can be used to manipulate character strings.<br />
<br />
=== $abbr(str) ===<br />
<br />
Returns abbreviation of string ''str''. Words which begin with an alphanumeric character are shortened to the first character. Spaces and parentheses are stripped. Example:<br />
* $abbr('This is a Long Title (12-inch version) [needs tags]') → TiaLT1v[needst<br />
<br />
=== $abbr(str,len) ===<br />
<br />
Returns abbreviation of ''str'', if ''str'' is longer than ''len'' characters, otherwise returns ''str''.<br />
<br />
=== $ansi(str) ===<br />
<br />
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.<br />
<br />
=== $ascii(str) ===<br />
<br />
Converts string ''str'' to ASCII. Any characters that are not present in ASCII will be removed / replaced.<br />
<br />
=== $caps(str) ===<br />
<br />
Converts first letter in every word of string ''str'' to uppercase, and all other letters to lowercase.<br />
<br />
=== $caps2(str) ===<br />
<br />
Converts first letter in every word of string ''str'' to uppercase, and leaves all other letters as they are.<br />
<br />
=== $char(nbr) ===<br />
<br />
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].<br />
<br />
=== $crc32(str) ===<br />
<br />
Computes the CRC32 of the string ''str'' as a number. Intended for use in coloring scripts.<br />
<br />
Example: $rgb($mod($crc32(%album%),256),128,128)<br />
<br />
=== $crlf() ===<br />
<br />
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.<br />
<br />
=== $cut(str,len) ===<br />
<br />
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:<br />
* ''$cut('abc123',3)'' → abc<br />
* ''$cut('abc123',0)'' → (nothing)<br />
* ''$cut('abc123',-1)'' → abc123<br />
<br />
=== $directory(path) ===<br />
<br />
Extracts directory name from the file ''path''.<br />
<br />
=== $directory(path,n) ===<br />
<br />
Extracts directory name from the file ''path''; goes up by ''n'' levels.<br />
<br />
=== $directory_path(path) ===<br />
<br />
Extracts directory path from the file ''path''.<br />
<br />
=== $ext(path) ===<br />
<br />
Extracts file extension from string ''path''; a file name or full path.<br />
<br />
=== $filename(path) ===<br />
<br />
Extracts file name from full ''path''.<br />
<br />
=== $fix_eol(str) ===<br />
<br />
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.<br />
<br />
=== $fix_eol(str,indicator) ===<br />
<br />
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.<br />
<br />
=== $hex(int,len) ===<br />
<br />
Formats the integer number ''int'' in hexadecimal notation with ''len'' digits. Pads with zeros from the left if necessary.<br />
<br />
=== $insert(str,insert,n) ===<br />
<br />
Inserts ''insert'' into ''str'' after ''n'' characters.<br />
<br />
=== $left(str,len) ===<br />
<br />
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:<br />
* ''$left('abc123',3)'' → abc<br />
* ''$left('abc123',0)'' → (nothing)<br />
* ''$left('abc123',-1)'' → abc123<br />
<br />
=== $len(str) ===<br />
<br />
Returns length of string ''str'' in characters.<br />
<br />
=== $len2(str) ===<br />
<br />
Returns length of string ''str'' in characters, respecting double-width character rules (double-width characters will be counted as two).<br />
<br />
=== $longer(str1,str2) ===<br />
<br />
Returns ''true'', if string ''str1'' is longer than string ''str2'', false otherwise.<br />
<br />
=== $lower(str) ===<br />
<br />
Converts string ''str'' to lowercase.<br />
<br />
=== $longest(arg,...) ===<br />
<br />
Returns the longest of its arguments. Can be used with an arbitrary number of strings.<br />
<br />
=== $num(nbr,len) ===<br />
<br />
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:<br />
<br />
* ''$num(123,5)'' → 00123<br />
* ''$num(-123,5)'' → -0123<br />
* ''$num(4.8,5)'' → 00004<br />
* ''$num(A1,5)'' → 00000<br />
<br />
=== $pad(str,len) ===<br />
<br />
Creates a left-aligned version of the string ''str''. If ''x'' 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.<br />
<br />
=== $pad_right(str,len) ===<br />
<br />
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.<br />
<br />
=== $pad(str,len,char) ===<br />
<br />
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.<br />
<br />
=== $pad_right(str,len,char) ===<br />
<br />
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.<br />
<br />
=== $padcut(str,len) ===<br />
<br />
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.<br />
<br />
=== $padcut(str,len,char) ===<br />
<br />
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.<br />
<br />
=== $padcut_right(str,len) ===<br />
<br />
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.<br />
<br />
=== $padcut_right(str,len,char) ===<br />
<br />
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.<br />
<br />
=== $progress(pos,range,len,char1,char2) ===<br />
<br />
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.<br />
<br />
Example:''$progress(%_time_elapsed_seconds%, %_time_total_seconds%, 20,'#','=')'' produces "====#===============", the # character is moving with playback position.<br />
<br />
=== $progress2(pos,range,len,char1,char2) ===<br />
<br />
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''.<br />
<br />
=== $repeat(expr,count) ===<br />
<br />
Returns ''count'' copies of ''expr''. Note that ''expr'' is evaluated once before its value is used, so ''$repeat'' cannot be used for loops.<br />
<br />
=== $replace(str,search,replace) ===<br />
<br />
Replaces all occurrences of string ''search'' in string ''str'' with string ''replace''.<br />
<br />
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)''.<br />
<br />
Example: ''$replace(ab,a,b,b,c)'' → "bc", ''$replace($replace(ab,a,b),b,c)'' → "cc"<br />
<br />
=== $right(str,len) ===<br />
<br />
Returns the first ''len'' characters from the right of string ''str''.<br />
<br />
=== $roman(int) ===<br />
<br />
Formats the integer number ''int'' in roman notation.<br />
<br />
=== $rot13(str) ===<br />
<br />
Performs [http://en.wikipedia.org/wiki/ROT13 ROT13] transformation to given string.<br />
<br />
Example: ''$rot13('foobar2000')'' → "sbbone2000".<br />
<br />
=== $shortest(str,...strN) ===<br />
<br />
Returns the first shortest element of its arguments. Can be used with an arbitrary number of strings.<br />
<br />
=== $strchr(str,char) ===<br />
<br />
Returns position of first occurrence of character ''char'' in string ''str''.<br />
<br />
Example: ''$strchr(abca,a)'' → 1<br />
<br />
=== $strrchr(str,char) ===<br />
<br />
Returns positions of last occurrence of character ''char'' in string ''str''.<br />
<br />
Example: ''$strrchr(abca,a)'' → 4<br />
<br />
=== $strstr(str1,str2) ===<br />
<br />
Returns position of first occurrence of string ''str2'' in string ''str1''. Function is case-sensitive.<br />
<br />
=== $strcmp(str1,str2) ===<br />
<br />
Performs a case-sensitive comparison of the strings ''str1'' and ''str2''.<br />
<br />
=== $stricmp(str1,str2) ===<br />
<br />
Performs a case-insensitive comparison of the strings ''str1'' and ''str2''.<br />
<br />
=== $stripprefix(str) ===<br />
<br />
Removes ''A'' and ''The'' prefixes from string ''str''. <br />
<br />
=== $stripprefix(str,prefix1,prefix2,...) ===<br />
<br />
Removes the specified prefixes from string ''str''. <br />
<br />
=== $substr(str,from,to) ===<br />
<br />
Returns substring of string ''str'', starting from ''FROM''-th character and ending at ''TO''-th character.<br />
<br />
=== $swapprefix(str) ===<br />
<br />
Moves ''A'' and ''The'' prefixes to the end of string ''str''. <br />
<br />
=== $swapprefix(str,prefix1,prefix2,...) ===<br />
<br />
Moves the specified prefixes to the end of string ''str''. <br />
<br />
=== $trim(str) ===<br />
<br />
Removes leading and trailing spaces from string ''str''.<br />
<br />
=== $tab() ===<br />
<br />
Inserts one tabulator character.<br />
<br />
=== $tab(count) ===<br />
<br />
Inserts ''count'' tabulator characters.<br />
<br />
=== $upper(str) ===<br />
<br />
Converts string ''str'' to uppercase.<br />
<br />
== Track info fields and functions ==<br />
<br />
The functions and fields in this section can be used to access information about tracks.<br />
<br />
=== Metadata fields and functions ===<br />
<br />
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%''.<br />
<br />
The following functions are also available for accessing metadata:<br />
<br />
==== $meta(name) ====<br />
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ", " as separator.<br />
<br />
Example: ''$meta(artist)'' → "He, She, They"<br />
<br />
==== $meta(name,n) ====<br />
Returns value of ''n''-th (0,1,2 and so on) tag called ''name''.<br />
<br />
Example: ''$meta(artist,1)'' → "She"<br />
<br />
==== $meta_sep(name,sep) ====<br />
Returns value of tag called ''name''. If multiple values of that tag exist, they are concatenated with ''sep'' as separator.<br />
<br />
Example: ''$meta_sep(artist,' + ')'' → "He + She + They"<br />
<br />
==== $meta_sep(name,sep,lastsep) ====<br />
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''.<br />
<br />
Example: ''$meta_sep(artist,', ',', and ')'' → "He, She, and They"<br />
<br />
==== $meta_test(...) ====<br />
Returns ''1'', if all given tags exist, ''undefined'' otherwise.<br />
<br />
Example: ''$meta_test(artist,title)'' → true<br />
<br />
==== $meta_num(name) ====<br />
Returns the number of values for the tag called ''name''.<br />
<br />
Example: ''$meta_num(artist)'' → 3<br />
<br />
=== Remapped metadata fields ===<br />
<br />
The following fields have special remapped values to make writing title format scripts more convenient:<br />
<br />
==== %album artist% ====<br />
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.<br />
<br />
==== %album% ====<br />
Name of the album specified track belongs to. Checks following metadata fields, in this order: "album", "venue".<br />
<br />
==== %artist% ====<br />
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.<br />
<br />
==== %discnumber% ====<br />
Index of disc specified track belongs to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.<br />
<br />
==== %totaldiscs% ====<br />
Index of total discs specified tracks belong to, within the album. Available only when "discnumber"/"disc" field is present in track’s metadata.<br />
<br />
==== %track artist% ====<br />
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.<br />
<br />
==== %title% ====<br />
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.<br />
<br />
==== %tracknumber% ====<br />
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).<br />
<br />
==== %track number% ====<br />
Similar to %tracknumber%, however single digit track numbers are not reformatted to have an extra 0.<br />
<br />
=== Technical information fields ===<br />
<br />
==== %bitrate% ====<br />
Bitrate of the track in kilobits per second. VBR files will show a dynamic display for currently played track (outside of the playlist).<br />
<br />
==== %channels% ====<br />
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".<br />
<br />
==== %codec% ====<br />
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".<br />
<br />
==== %filesize% ====<br />
The exact file size in bytes.<br />
Old version: <code>%_filesize%</code><br />
<br />
==== %filesize_natural% ====<br />
The approximate file size, automatically formatted in appropriate units such as megabytes or kilobytes, e.g. "8.49 MB"<br />
<br />
==== %length% ====<br />
The length of the track formatted as hours, minutes, and seconds, rounded to the nearest second.<br />
Old version: <code>%_time_total%</code><br />
<br />
==== %length_ex% ====<br />
The length of the track formatted as hours, minutes, seconds, and milliseconds, rounded to the nearest millisecond.<br />
<br />
==== %length_seconds% ====<br />
The length of the track in seconds, rounded to the nearest second.<br />
Old version: <code>%_time_total_seconds%</code><br />
<br />
==== %length_seconds_fp% ====<br />
The length of the track in seconds as a floating point number.<br />
<br />
==== %length_samples% ====<br />
The length of the track in samples.<br />
<br />
==== %samplerate% ====<br />
Sample rate of the track, in Hz.<br />
<br />
=== Technical information functions ===<br />
<br />
==== $info(name) ====<br />
Returns value of technical information field called ''name''.<br />
<br />
For convenience, the '''%__name%''' alias is also available.<br />
<br />
Example: ''$info(channels)'' → 2<br />
<br />
Here is an '''informative''' list of recognized fields. Some of these depend on the media file type being queried.<br />
<br />
{| border="0" cellspacing="0" cellpadding="2"<br />
! field name<br />
! Description<br />
|-<br />
| colspan="2" style="background-color:#CCF"|'''General'''<br />
|-<br />
|codec<br />
| style="background-color:#EEF"|'''Codec''' (''e.g.'' MP3)<br />
|-<br />
|codec_profile<br />
| style="background-color:#EEF"|'''Codec Profile''' (''e.g.'' CBR)<br />
|-<br />
|samplerate<br />
| style="background-color:#EEF"|'''Sample Rate''', in hertz (''e.g.'' 44100)<br />
|-<br />
|bitrate<br />
| style="background-color:#EEF"|'''Bitrate''', in kilobits per second (''e.g.'' 320)<br />
|-<br />
|tool<br />
| style="background-color:#EEF"|'''Tool''' used to produce the file, possibly guessed (''e.g.'' LAME3.97)<br />
|-<br />
|encoding<br />
| style="background-color:#EEF"|'''Encoding''' lossiness (''e.g.'' lossy)<br />
|-<br />
|channels<br />
| style="background-color:#EEF"|'''Channels''' count (''e.g.'' 2 <nowiki>[for stereo]</nowiki>)<br />
|-<br />
|channel_mode<br />
| style="background-color:#EEF"|'''Channel Mode''', description of channels (''e.g.'' 3 front, 2 rear surround channels + LFE)<br />
|-<br />
|__bitspersample<br />
| style="background-color:#EEF"|'''Bits Per Sample''' (''e.g.'' 16)<br />
|-<br />
|tagtype<br />
| style="background-color:#EEF"|'''Tag Type''', comma-separated list of tag formats (''e.g.'' id3v2|apev2)<br />
|-<br />
|cue_embedded<br />
| style="background-color:#EEF"|'''Embedded Cuesheet''' presence (''e.g.'' no <nowiki>[may be empty!]</nowiki>)<br />
|-<br />
|md5<br />
| style="background-color:#EEF"|'''Audio MD5''' hash, if container defines it (''e.g.'' 1E24A910D91EF09A8CF403C9B6963961)<br />
|-<br />
| colspan="2" style="background-color:#CCF"|'''Other'''<br />
|-<br />
|ENC_DELAY<br />
| style="background-color:#EEF"|LAME proprietary MP3 '''enc_delay''' value for gapless playback (''e.g.'' 576)<br />
|-<br />
|ENC_PADDING<br />
| style="background-color:#EEF"|LAME proprietary MP3 '''enc_padding''' value for gapless playback (''e.g.'' 1536)<br />
|-<br />
|MP3_ACCURATE_LENGTH<br />
| style="background-color:#EEF"|MP3 duration (%length% etc.) takes into account LAME or iTunes gapless playback info (''e.g.'' yes)*<br />
|-<br />
|MP3_STEREO_MODE<br />
| style="background-color:#EEF"|Stereo mode used in MP3 file (''e.g.'' mono, stereo, joint stereo, etc.)<br />
|-<br />
|VERSION<br />
| style="background-color:#EEF"|'''Version''' of tool (''e.g.'' 3.99)<br />
|-<br />
|FLAGS<br />
| style="background-color:#EEF"|'''Flags''' of tool (''e.g.'' 22)<br />
|}<br />
<br />
<br />
<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><br />
<br />
==== $channels() ====<br />
The number of channels in text format.<br />
<br />
Example: ''$channels()'' → "stereo"<br />
<br />
==== %replaygain_album_gain% ====<br />
The ReplayGain album gain value.<br />
<br />
==== %replaygain_album_peak% ====<br />
The ReplayGain album peak value.<br />
<br />
==== %replaygain_album_peak_db% ====<br />
The ReplayGain album peak value in decibels.<br />
<br />
==== %replaygain_track_gain% ====<br />
The ReplayGain track gain value.<br />
<br />
==== %replaygain_track_peak% ====<br />
The ReplayGain track peak value.<br />
<br />
==== %replaygain_track_peak_db% ====<br />
The ReplayGain track peak value in decibels.<br />
<br />
=== Special fields ===<br />
<br />
==== %filename% ====<br />
The filename without directory and extension.<br />
<br />
==== %filename_ext% ====<br />
The filename with extension, but without the directory.<br />
<br />
==== %directoryname% ====<br />
The name of the parent directory only, not the complete path.<br />
<br />
==== %last_modified% ====<br />
The date and time the file was last modified. Eg: ''2005-12-22 00:04:10''<br />
<br />
==== %path% ====<br />
The complete path, including the filename and extension.<br />
<br />
==== %_path_raw% ====<br />
The path as URL including the protocol scheme.<br />
<br />
==== %subsong% ====<br />
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.<br />
<br />
==== %_foobar2000_version% ====<br />
A string representing the version of foobar2000.<br />
<br />
== Time and date functions ==<br />
<br />
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]].<br />
<br />
=== $year(time) ===<br />
Retrieves the year part (formatted as four digits) from a time/date string.<br />
<br />
=== $month(time) ===<br />
Retrieves the month part (formatted as two digits) from a time/date string.<br />
<br />
=== $day_of_month(time) ===<br />
Retrieves the day of month part (formatted as two digits) from a time/date string.<br />
<br />
=== $date(time) ===<br />
Retrieves the date part (formatted as YYYY-MM-DD) from a time/date string.<br />
<br />
=== $time(time) ===<br />
Retrieves the time part (formatted as HH:MM:SS or HH:MM) from a date/time string.<br />
<br />
== Variable operations ==<br />
<br />
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.<br />
<br />
For example:<br />
{| border="0" cellspacing="0" cellpadding="2"<br />
! code<br />
! output<br />
|-<br />
|<pre>$put(foo,bar)$char(10)<br />
$get(foo)$char(10)<br />
$get(Foo)$char(10)<br />
$puts(foo,2000)$char(10)<br />
$get(foo)$char(10)</pre><br />
| style="background-color:#EEF" |<pre>bar<br />
bar<br />
bar<br />
<br />
2000</pre><br />
|}<br />
<br />
=== $get(name) ===<br />
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.<br />
<br />
=== $put(name,value) ===<br />
Stores ''value'' in the variable ''name'' and returns ''value'' unaltered.<br />
<br />
=== $puts(name,value) ===<br />
Stores ''value'' in the variable ''name'' and returns nothing.<br />
<br />
== Component-specific fields and functions ==<br />
<br />
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.<br />
<br />
=== Now playing info ===<br />
<br />
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.<br />
<br />
==== %playback_time% ====<br />
The elapsed time formatted as [HH:]MM:SS.<br />
<br />
==== %playback_time_seconds% ====<br />
The elapsed time in seconds.<br />
Old version: <code>%_time_elapsed%</code><br />
<br />
==== %playback_time_remaining% ====<br />
The time remaining until the track ends, formatted as [HH:]MM:SS.<br />
Old version: <code>%_time_remaining%</code><br />
<br />
==== %playback_time_remaining_seconds% ====<br />
The time remaining until the track ends, in seconds.<br />
Old version: <code>%_time_remaining_seconds%</code><br />
<br />
=== Playlist-only fields ===<br />
<br />
The following fields are only usable in playlist display formatting (i.e., the column title formatting patterns).<br />
<br />
==== %isplaying% ====<br />
"1" if file is currently playing, empty string otherwise.<br />
<br />
==== %ispaused% ====<br />
"1" if playback is paused, empty string otherwise.<br />
<br />
==== %list_index% ====<br />
A zero-padded playlist index of specified item. The first item is at index 1.<br />
<br />
==== %list_total% ====<br />
The number of items in the playlist.<br />
<br />
==== %queue_index% ====<br />
Index of the specified item in the playback queue. If the item has been queued multiple times, %queue_index% evaluates to the first index.<br />
<br />
==== %queue_indexes% ====<br />
List of indexes of the specified item in the playback queue. Same as %queue_index% unless the item has been queued more than once.<br />
<br />
==== %queue_total% ====<br />
Total amount of tracks in playback queue. Available only for queued tracks, for technical reasons. <br />
<br />
=== Playlist text color ===<br />
<br />
==== Dimmed and highlighted text ====<br />
<br />
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):<br />
<br />
* ''&lt;text>'' – dim ''text''<br />
* ''&lt;&lt;text>>'' – dimmer ''text''<br />
* ''&lt;&lt;&lt;text>>>'' – dimmest ''text''<br />
* ''>text&lt;'' – bright ''text''<br />
* ''>>text&lt;&lt;'' – brighter ''text''<br />
* ''>>>text&lt;&lt;&lt;'' – brightest ''text''<br />
<br />
==== Historical and Columns UI color functions ====<br />
<br />
Prior to version 1.0, the default UI playlist supported the following color functions, which are still available in the Columns UI playlist:<br />
<br />
===== $blend(color1,color2,part,total) =====<br />
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.<br />
<br />
===== $hsl() =====<br />
Resets the text color to the default color.<br />
<br />
===== $hsl(h,s,l) =====<br />
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.<br />
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.<br />
<br />
===== $hsl(h1,s1,l1,h2,s2,l2) =====<br />
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.<br />
<br />
===== $rgb() =====<br />
Resets the text color to the default color.<br />
<br />
===== $rgb(r,g,b) =====<br />
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.<br />
<br />
===== $rgb(r1,g1,b1,r2,g2,b2) =====<br />
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.<br />
<br />
===== $transition(string,color1,color2) =====<br />
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''.<br />
<br />
=== Album List ===<br />
<br />
* [[Foobar2000:Titleformat_Album_List|Album List Title Formatting]]<br />
* [[Foobar2000:Preferences:Album List|Preferences: Album List]]<br />
<br />
=== Playback Statistics ===<br />
<br />
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:<br />
* [http://www.foobar2000.org/components/view/foo_playcount Playback statistics homepage]<br />
* [[Foobar2000:Titleformat Playback Statistics|Playback statistics titleformat reference]]<br />
<br />
=== Playlist Organizer ===<br />
<br />
This component adds a number of fields to control the display of a list of playlists. See the documentation for details:<br />
* [[Foobar2000:Components/Playlist Organizer (foo_plorg)#Nodes|Playlist Organizer: Nodes Title Formatting]]<br />
<br />
=== Columns UI ===<br />
<br />
This component replaces the Default UI framework, including the playlist. See the documentation for details:<br />
* [http://yuo.be/columns.php Columns UI homepage]<br />
* [http://yuo.be/wiki/columns_ui:config:global_variables Global variables reference]<br />
* [http://yuo.be/wiki/columns_ui:config:colour_string Playlist colors reference]<br />
* [http://yuo.be/wiki/columns_ui:config:playlist_switcher_titleformatting Playlist switcher reference]<br />
<br />
== Additional Reading ==<br />
<br />
* [[Foobar2000:Title Formatting Introduction|Introduction to titleformat scripts]]<br />
* The file '''titleformat_help.html''' in your Foobar2000 directory, e.g. file:///C:/Program%20Files%20(x86)/foobar2000/titleformat_help.html<br />
<br />
[[Category:foobar2000 Guides|Titleformat Reference]]</div>24.184.166.112