Foobar2000:Titleformat Examples: Difference between revisions

From Hydrogenaudio Knowledgebase
(→‎Test whether %tag% field contains string XYZ: added a method for handling empty or missing tags)
m (Added a link in the prose back to Foobar2000:Title Formatting Introduction, as it is easy to overlook the infobox. Added mention of DUI custom columns pattern input as another place multiline isn't supported.)
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{fb2k}}
{{sidebar foobar2000 title formatting}}
These are some examples of general title format usage contributed by users. They may be of utility to others using Masstagger or other components. Feel free to sign up and contribute your own examples!
These are some examples of general [[Foobar2000:Title Formatting Introduction|title format]] usage contributed by users. They may be of utility to those using Masstagger or other components. Feel free to sign up and contribute your own examples!


Please make sure that you rejoin scripts that have been split into multiple lines before pasting them into the masstagger window. The reason that they are split is to keep this page's formatting readable in your browser.
Please make sure that you rejoin scripts that have been split into multiple lines before pasting them into the Masstagger window or DUI custom columns pattern input. The reason that they are split is to keep this page's formatting readable in your browser.


==Shorter examples==
==Shorter examples==
Line 72: Line 72:
  $trim($left($get(tag),$sub($get(spacer),1)))
  $trim($left($get(tag),$sub($get(spacer),1)))
* Example: ''blah XYZ bleh'' returns ''blah''
* Example: ''blah XYZ bleh'' returns ''blah''
* Note: String ''XYZ'' can basically be any combination of characters or words.
* String ''XYZ'' can basically be any combination of characters or words.
 
* If the string isn't found, everything is returned


===Find first occurence of string XYZ in %tag% field, and return everything after XYZ:===
===Find first occurence of string XYZ in %tag% field, and return everything after XYZ:===
Line 106: Line 106:
* With a track that has genre set to ''electronic dance'', the output would be ''genre does not include rock''.
* With a track that has genre set to ''electronic dance'', the output would be ''genre does not include rock''.


Note that this will also return the false value if the field is blank or not present, the following can provide a third output instead:
Note that this will also return the false value if the field is missing or empty. The following can provide a third output in that scenario instead:
  $puts(string,XYZ)
  $puts(string,XYZ)
  $puts(tag,[%tag%])
  $puts(tag,[%tag%])
  $if($get(tag),$ifgreater($strstr($get(tag),$get(string)),0,tag contains string,tag does not contain string),tag is missing or empty)
  $if($get(tag),$ifgreater($strstr($get(tag),$get(string)),0,tag contains string,tag does not contain string),tag is missing or empty)
===Samplerate display with decimals (i.e. 44.1khz)===
Foobar2000 doesn't do floating point math. This is a problem if you want to display your sample rate in a decimal format. This mess of statements will fake this for you while adjusting for rates evenly divisible by 1000 and rates over 100khz.
<pre>$ifgreater($mod(%samplerate%,1000),0,
$insert($div(%samplerate%,100),'.',$sub($len($div(%samplerate%,100)),1)) kHz,
$div(%samplerate%,1000) kHz)</pre>
===Bit Depth display===
This will display the current bitdepth of your track. If there is no depth reported, it will automatically just return 16.
<pre>$ifequal([%__bitspersample%],0,16,%__bitspersample%)</pre>
==Custom columns for playlists==
===ReplayGain tag summary===
If album and track gain tags are present, it shows album gain followed by "alb", then track gain followed by "trk". If only track gain is present, it shows track gain is followed by "trk only". If neither tag is present, it shows "n/a". Remove the text-dimming angle brackets if you're not using this in a Default UI playlist column.
<pre>$if($or(%REPLAYGAIN_TRACK_GAIN%,%REPLAYGAIN_ALBUM_GAIN%),
$if(%REPLAYGAIN_ALBUM_GAIN%,%REPLAYGAIN_ALBUM_GAIN%' '<'alb'>
$if($not(%REPLAYGAIN_TRACK_GAIN%),<' only'>)' ')
$if(%REPLAYGAIN_TRACK_GAIN%,%REPLAYGAIN_TRACK_GAIN% <'trk'>
$if(%REPLAYGAIN_ALBUM_GAIN%,, <'only'>)),n/a)</pre>
===Artist and title with fallback for untagged files===
Shows artist, en dash, title in curly quotes, plus an optional note taken from the filename. Artist and title are read from tags if both are available, otherwise from the filename (in which case the artist is 'unknown' and title is the filename, unless the filename has a dash surrounded by spaces, assumed to be in the format ''artist - title''). If the file name ends with a bracketed note, e.g. ''Artist - Title [intro skips badly].mp3'', the note is appended to the output. Additionally, in the title, the text ''-inch'', or the double quote in ''7"'' and ''12"'', is replaced with the Unicode inch character, ''″''.
Remove the text-dimming and highlighting angle brackets if you're not using this in a Default UI playlist column.
<pre>$puts(FILENAME,%filename%)
$puts(TMP,$strstr($get(FILENAME), - ))
$ifgreater($get(TMP),0,
$puts(ARTIST,$trim($left($get(FILENAME),$sub($get(TMP),1))))
$puts(TITLE,$trim($right($get(FILENAME),$sub($len($get(FILENAME)),$add($get(TMP),2)))))
$puts(TITLEONLY,$left($get(TITLE),$sub($strstr($get(TITLE),' ['),1)))
$puts(NOTE,$substr($get(TITLE),$add($len($get(TITLEONLY)),2),$strrchr($get(TITLE),']'))),
$puts(ARTIST,unknown)
$puts(TITLE,$get(FILENAME))
$puts(TITLEONLY,$get(TITLE))
)
$puts(BESTARTIST,$if([$meta(artist)],$meta(artist),$get(ARTIST)))
$puts(BESTTITLE,$if3([$meta(title)],$meta(title),[$get(TITLEONLY)],unknown))
$puts(FORMATTEDTITLE,$replace($get(BESTTITLE),-inch,″,12",12″,7",7″))
>$get(BESTARTIST)<
< – “>
$get(FORMATTEDTITLE)<”>
$if($get(NOTE),<< $get(NOTE)>>)</pre>
===Peak to Loudness Ratio (PLR)===
If ReplayGain track gain tags are present, the PLR in [[bel|decibel]]s can be calculated and displayed as a single figure, rounded up, based on [[wikipedia:LUFS|LUFS]] (assuming the ReplayGain scan used EBU R128, not Classic ReplayGain). PLR can be used as an alternative to a [[foobar2000:Components/Dynamic Range Meter (foo_dynamic_range)|dynamic range tag]].
'''Note:''' The {{code|replaygain_track_peak_db}} field is only available in foobar2000 1.4.1 and later.
<pre>$if($and([%replaygain_track_gain%],[%replaygain_track_peak_db%]),
$puts(tpfs,$replace(%replaygain_track_peak_db%,.,,dB,))
$puts(lufs,$sub(-1800,$replace(%replaygain_track_gain%,.,)))
$puts(plr,$sub($get(tpfs),$get(lufs)))
$div($add(50,$get(plr)),100)
)</pre>
===75 FPS CD Timecode===
If you have any reason for displaying the 75fps timecode of your tracks, this will do it for you.
<pre>$puts(frm,$div(%samplerate%,75))
$puts(rem,$sub(%length_samples%,$mul(%length_seconds_fp%,%samplerate%)))
$left(%length_ex%,$sub($len(%length_ex%),4)):$num($div($get(rem),$get(frm)),2)</pre>
==Playlist grouping schemes==
===Album artist and album title, with fallbacks ===
With this grouping scheme, tracks with album tags are kept separate from streams and other loose tracks. The album artist is taken from %band%, %album artist%, or %artist%, otherwise 'unknown artist'.
<pre>$if($stricmp($left(%path%,7),'http://'),<Internet streams>,
$if($meta_test(album),
$if($meta_test(band),%band%,
$if($meta_test(album artist),%album artist%,
$if($meta_test(artist),%artist%,unknown artist))) – %album%,
<non-album tracks>))
</pre>

Latest revision as of 16:14, 5 April 2024

These are some examples of general title format usage contributed by users. They may be of utility to those using Masstagger or other components. Feel free to sign up and contribute your own examples!

Please make sure that you rejoin scripts that have been split into multiple lines before pasting them into the Masstagger window or DUI custom columns pattern input. The reason that they are split is to keep this page's formatting readable in your browser.

Shorter examples

Return corresponding tag field

%tag%
  • Example: If artist field is blah, %artist% will return blah.
  • Note: You can insert any character (or space) in between two tags, in front or after; so, if %artist% is blah and %title% is bleh: %artist%X%title% returns blahXbleh.

Trunctuate %tag% to a length of X characters

$cut(%tag%,X)
  • Example: If artist field is blah, $cut(%artist%,3) returns bla

Truncate %tag% by X characters, and add ... at the end of the cut

$cut(%tag%,X)...
  • Example: If artist field is blah, $cut(%artist%,3)... returns bla...

Return numerical value of %tag%, and pad with 0s to X characters

$num(%tag%,X)
  • Example: If %tracknumber% field is 3, $num(%tracknumber%,2) will return 03. If 13, it will return 13.

Return first two characters of a filename, and display as number (if present) padded with 0s to X characters

$num($left(%_filename%),2)
  • Example: A filename of 03_artist_title.mpc will return 03.

Find first occurrence of character X in %tag%, and return everything in front of X

$puts(spacer,$strchr(%tag%,X))
$trim($left(%tag%,$sub($get(spacer),1)))
  • Example: blah X bleh or blah X bleh X bluh returns blah (ie.: artist_album_title -----> title, in case X is _ )

Longer examples

In the next few strings, I have decided to make it possible to define the %tag% that should be edited and the character or string that is used to determine where to trunctuate; these can be defined as variables in the beginning of the string as $puts(tag,%tag%), $puts(char,X), etc. Basically the reason I have done this is to make it simpler to edit these strings, to what you want them to do at that exact moment, in the rather narrow masstager input field. That way it is possible to enter the needed tags and characters only once in the beginning of the line. Again, simply replace %tag% and X by the desired values. Also all of these strings will trim off the trailing and leading spaces of the output (in case there are any).

Find first occurence of character X in %tag%, and return everything in front of X

$puts(char,X)$puts(tag,%tag%)$puts(spacer,$strchr($get(tag),$get(char)))
$trim($left($get(tag),$sub($get(spacer),1)))
  • Example: blah X bleh or blah X bleh X bluh returns blah (ie.: artist_album_title -----> title, in case X is _ )
  • Note: this does exactly the same as the last string mentioned above, except for the introdution of the two variables in the front, meant for easy editing (see explanation above).

Find last occurence of character X in %tag%, and return everything in front of X

$puts(char,X)$puts(tag,%tag%)$puts(spacer,$strrchr($get(tag),$get(char)))
$trim($left($get(tag),$sub($get(spacer),1)))
  • Example: blah X bleh returns blah, and blah X bleh X bluh returns blah X bleh

Find first occurence of character X in %tag% field, and return everything after X

$puts(char,X)$puts(tag,%tag%)$puts(spacer,$strchr($get(tag),$get(char)))
$trim($right($get(tag),
$sub($len($get(tag)),$get(spacer))))
  • Example: blah X bleh returns bleh, and blah X bleh X bluh returns bleh X bluh

Find last occurence of character X in %tag% field, and return everything after X

$puts(char,X)$puts(tag,%tag%)$puts(spacer,$strrchr($get(tag),$get(char)))
$trim($right($get(tag),
$sub($len($get(tag)),$get(spacer))))
  • Example: blah X bleh returns bleh, and blah X bleh X bluh returns bluh

Find first occurence of character X and last occurence of character Y, and return everything in-between

$puts(char1,X)$puts(char2,Y)$puts(tag,%tag%)
$puts(spacer1,$strchr($get(tag),$get(char1)))
$puts(spacer2,$strrchr($get(tag),$get(char2)))
$trim($substr($get(tag),$add($get(spacer1),1),$sub($get(spacer2),1)))
  • Example: blah X bleh Y bluh returns bleh
  • Note: In most cases, X will probably be equal to y here.

Find first occurence of string XYZ, and return everything in front of string XYZ

$puts(string,XYZ)$puts(tag,%tag%)$puts(spacer,$strstr($get(tag),
$get(string)))
$trim($left($get(tag),$sub($get(spacer),1)))
  • Example: blah XYZ bleh returns blah
  • String XYZ can basically be any combination of characters or words.
  • If the string isn't found, everything is returned

Find first occurence of string XYZ in %tag% field, and return everything after XYZ:

$puts(string,XYZ)$puts(tag,%tag%)
$puts(spacer,$strstr($get(tag),$get(string)))
$trim($right($get(tag),$sub($len($get(tag)),
$add($get(spacer),$len($get(string))))))
  • Example: blah XYZ bleh returns bleh

Get everything between two strings of your choice

Assuming a text accessible via %someTag% contains the strings <coolTag> and <blaTag>, in that order, you can get everything between them (e.g. xyz from <coolTag>xyz<blaTag>) using this code:

$substr(%someTag%,$add($strstr(%someTag%,<coolTag>),$len(<coolTag>)),$sub($strstr(%someTag%,<blaTag>),1))

What does it do, and how?

  • $substr(%someTag%,X,Y) yields everything of %someTag% from the Xth character to the Yth character. In this case we have:
  • X = $add($strstr(%someTag%,<coolTag>),$len(<coolTag>)),
i.e. the position of <coolTag> in %someTag% plus the length of the word <coolTag>
  • Y = $sub($strstr(%someTag%,<blaTag>),1)
i.e. the position of <blaTag> in %someTag% minus one; the subtraction is performed because otherwise the code would yield < (the first character of <blaTag>) as the last character of the output string.

Test whether %tag% field contains string XYZ

$puts(string,XYZ)
$puts(tag,%tag%)
$ifgreater($strstr($get(tag),$get(string)),0,tag contains string,tag does not contain string)

An example of how this could be used:

$puts(string,rock)
$puts(tag,%genre%)
$ifgreater($strstr($get(tag),$get(string)),0,genre includes $get(string),genre does not include $get(string))
  • With a track that has genre set to classic rock, the output would be genre includes rock.
  • With a track that has genre set to electronic dance, the output would be genre does not include rock.

Note that this will also return the false value if the field is missing or empty. The following can provide a third output in that scenario instead:

$puts(string,XYZ)
$puts(tag,[%tag%])
$if($get(tag),$ifgreater($strstr($get(tag),$get(string)),0,tag contains string,tag does not contain string),tag is missing or empty)

Samplerate display with decimals (i.e. 44.1khz)

Foobar2000 doesn't do floating point math. This is a problem if you want to display your sample rate in a decimal format. This mess of statements will fake this for you while adjusting for rates evenly divisible by 1000 and rates over 100khz.

$ifgreater($mod(%samplerate%,1000),0,
$insert($div(%samplerate%,100),'.',$sub($len($div(%samplerate%,100)),1)) kHz,
$div(%samplerate%,1000) kHz)

Bit Depth display

This will display the current bitdepth of your track. If there is no depth reported, it will automatically just return 16.

$ifequal([%__bitspersample%],0,16,%__bitspersample%)

Custom columns for playlists

ReplayGain tag summary

If album and track gain tags are present, it shows album gain followed by "alb", then track gain followed by "trk". If only track gain is present, it shows track gain is followed by "trk only". If neither tag is present, it shows "n/a". Remove the text-dimming angle brackets if you're not using this in a Default UI playlist column.

$if($or(%REPLAYGAIN_TRACK_GAIN%,%REPLAYGAIN_ALBUM_GAIN%),
$if(%REPLAYGAIN_ALBUM_GAIN%,%REPLAYGAIN_ALBUM_GAIN%' '<'alb'>
$if($not(%REPLAYGAIN_TRACK_GAIN%),<' only'>)' ')
$if(%REPLAYGAIN_TRACK_GAIN%,%REPLAYGAIN_TRACK_GAIN% <'trk'>
$if(%REPLAYGAIN_ALBUM_GAIN%,, <'only'>)),n/a)

Artist and title with fallback for untagged files

Shows artist, en dash, title in curly quotes, plus an optional note taken from the filename. Artist and title are read from tags if both are available, otherwise from the filename (in which case the artist is 'unknown' and title is the filename, unless the filename has a dash surrounded by spaces, assumed to be in the format artist - title). If the file name ends with a bracketed note, e.g. Artist - Title [intro skips badly].mp3, the note is appended to the output. Additionally, in the title, the text -inch, or the double quote in 7" and 12", is replaced with the Unicode inch character, .

Remove the text-dimming and highlighting angle brackets if you're not using this in a Default UI playlist column.

$puts(FILENAME,%filename%)
$puts(TMP,$strstr($get(FILENAME), - ))
$ifgreater($get(TMP),0,
$puts(ARTIST,$trim($left($get(FILENAME),$sub($get(TMP),1))))
$puts(TITLE,$trim($right($get(FILENAME),$sub($len($get(FILENAME)),$add($get(TMP),2)))))
$puts(TITLEONLY,$left($get(TITLE),$sub($strstr($get(TITLE),' ['),1)))
$puts(NOTE,$substr($get(TITLE),$add($len($get(TITLEONLY)),2),$strrchr($get(TITLE),']'))),
$puts(ARTIST,unknown)
$puts(TITLE,$get(FILENAME))
$puts(TITLEONLY,$get(TITLE))
)
$puts(BESTARTIST,$if([$meta(artist)],$meta(artist),$get(ARTIST)))
$puts(BESTTITLE,$if3([$meta(title)],$meta(title),[$get(TITLEONLY)],unknown))
$puts(FORMATTEDTITLE,$replace($get(BESTTITLE),-inch,″,12",12″,7",7″))
>$get(BESTARTIST)<
< – “>
$get(FORMATTEDTITLE)<”>
$if($get(NOTE),<< $get(NOTE)>>)

Peak to Loudness Ratio (PLR)

If ReplayGain track gain tags are present, the PLR in decibels can be calculated and displayed as a single figure, rounded up, based on LUFS (assuming the ReplayGain scan used EBU R128, not Classic ReplayGain). PLR can be used as an alternative to a dynamic range tag.

Note: The replaygain_track_peak_db field is only available in foobar2000 1.4.1 and later.

$if($and([%replaygain_track_gain%],[%replaygain_track_peak_db%]),
$puts(tpfs,$replace(%replaygain_track_peak_db%,.,,dB,))
$puts(lufs,$sub(-1800,$replace(%replaygain_track_gain%,.,)))
$puts(plr,$sub($get(tpfs),$get(lufs)))
$div($add(50,$get(plr)),100)
)

75 FPS CD Timecode

If you have any reason for displaying the 75fps timecode of your tracks, this will do it for you.

$puts(frm,$div(%samplerate%,75))
$puts(rem,$sub(%length_samples%,$mul(%length_seconds_fp%,%samplerate%)))
$left(%length_ex%,$sub($len(%length_ex%),4)):$num($div($get(rem),$get(frm)),2)

Playlist grouping schemes

Album artist and album title, with fallbacks

With this grouping scheme, tracks with album tags are kept separate from streams and other loose tracks. The album artist is taken from %band%, %album artist%, or %artist%, otherwise 'unknown artist'.

$if($stricmp($left(%path%,7),'http://'),<Internet streams>,
$if($meta_test(album),
$if($meta_test(band),%band%,
$if($meta_test(album artist),%album artist%,
$if($meta_test(artist),%artist%,unknown artist))) – %album%,
<non-album tracks>))