Foobar2000:Titleformat Examples

From Hydrogenaudio Knowledgebase
Jump to: navigation, search
Foobar2000_Logo.png

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!

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.

Shorter examples[edit]

Return corresponding tag field[edit]

%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[edit]

$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[edit]

$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[edit]

$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[edit]

$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[edit]

$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[edit]

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[edit]

$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[edit]

$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[edit]

$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[edit]

$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[edit]

$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[edit]

$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:[edit]

$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[edit]

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[edit]

$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)

Custom columns for playlists[edit]

ReplayGain tag summary[edit]

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[edit]

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($replace($replace($get(BESTTITLE),-inch,″),12",12″),7",7″))
>$get(BESTARTIST)<
< – “>
$get(FORMATTEDTITLE)<”>
$if($get(NOTE),<< $get(NOTE)>>)

Playlist grouping schemes[edit]

Album artist and album title, with fallbacks[edit]

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>))