Difference between revisions of "Foobar2000:Titleformat Examples"

From Hydrogenaudio Knowledgebase
Jump to: navigation, search
m (added template)
(Much-improved formatting, etc. and adding a new example by herojoker.)
Line 1: Line 1:
 
{{fb2k}}
 
{{fb2k}}
== Examples of general title format usage. Can be useful in Masstager or other components ==
+
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.
  
Please make sure you rejoin scripts that have been split into multiple lines, before pasting them into the masstagger window. The reason they are split is to keep this page's formatting readable in your browser.
+
==Shorter examples==
 
+
 
+
'''Returns corresponding tag field:'''
+
  
 +
===Return corresponding tag field===
 
  %tag%
 
  %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''.
  
'''Example:''' if artist field is blah %artist% will return blah. Note that you can insert any character (or space) in between two tags, in front or after, so if artist is blah and title is bleh 
+
===Trunctuate %tag% to a length of X characters===
%artist%X%title%
+
returns blahXbleh.
+
 
+
 
+
'''Trunctuates %tag% to a length of X characters:'''
+
 
+
 
  $cut(%tag%,X)
 
  $cut(%tag%,X)
 +
* Example: If artist field is ''blah'', $cut(%artist%,3) returns ''bla''
  
'''Example:''' if artist field is blah $cut(%artist%,3) returns bla
+
===Truncate %tag% by X characters, and add ... at the end of the cut===
 
+
 
+
'''Truncuates %tag% by X characters and adds ... at the end of the cut.'''
+
 
+
 
  $cut(%tag%,X)...
 
  $cut(%tag%,X)...
'''
+
* Example: If artist field is ''blah'', ''$cut(%artist%,3)...'' returns ''bla...''
Example:''' if artist field is blah $cut(%artist%,3)... returns bla...
+
 
+
 
+
'''Returns numerical value of %tag% and pads with 0s up to x characters'''
+
  
 +
===Return numerical value of %tag%, and pad with 0s to X characters===
 
  $num(%tag%,X)
 
  $num(%tag%,X)
 +
* Example: If %tracknumber% field is ''3'', ''$num(%tracknumber%,2)'' will return ''03''. If ''13'', it will return ''13''.
  
'''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===
 
+
 
+
'''Returns first two characters of a filename and displays as number (if present) padded with 0s up to X characters:'''
+
 
+
 
  $num($left(%_filename%),2)
 
  $num($left(%_filename%),2)
 +
* Example: A filename of ''03_artist_title.mpc'' will return ''03''.
  
'''Example:''' if filename is 03_artist_title.mpc will return 03.
+
===Find first occurrence of character X in %tag%, and return everything in front of X===
 
+
 
+
'''Finds first occurence of character X in %tag% and returns everything in front of X:'''
+
 
+
 
  $puts(spacer,$strchr(%tag%,X))
 
  $puts(spacer,$strchr(%tag%,X))
 
  $trim($left(%tag%,$sub($get(spacer),1)))
 
  $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 _ )
  
'''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).
  
'''NOTE:'''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 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 exactly want them to do at the very 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===
 
+
 
+
'''Finds first occurence of character X in %tag% and returns everything in front of X:'''
+
 
+
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strchr($get(tag),$get(char)))
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strchr($get(tag),$get(char)))
 
  $trim($left($get(tag),$sub($get(spacer),1)))
 
  $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).
  
'''Example:''' blah X bleh or blah X bleh X bluh returns blah (ie.: artist_album_title -----> title, in case X is _ )
+
===Find last occurence of character X in %tag%, and return everything in front of X===
 
+
'''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
+
 
+
 
+
'''Finds last occurence of character X in %tag% and returns everything in front of X:'''
+
 
+
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strrchr($get(tag),$get(char)))
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strrchr($get(tag),$get(char)))
 
  $trim($left($get(tag),$sub($get(spacer),1)))
 
  $trim($left($get(tag),$sub($get(spacer),1)))
'''
+
* Example: ''blah X bleh'' returns ''blah'', and ''blah X bleh X bluh'' returns ''blah X bleh''
Example:''' blah X bleh returns blah and blah X bleh X bluh returns blah X bleh
+
 
+
 
+
'''Finds first occurence of character X in %tag% field and returns everything after X:'''
+
  
 +
===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)))
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strchr($get(tag),$get(char)))
 
  $trim($right($get(tag),
 
  $trim($right($get(tag),
 
  $sub($len($get(tag)),$get(spacer))))
 
  $sub($len($get(tag)),$get(spacer))))
 +
* Example: ''blah X bleh'' returns ''bleh'', and ''blah X bleh X bluh'' returns ''bleh X bluh''
  
'''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===
 
+
 
+
'''Finds last occurence of character X in %tag% field and returns everything after X:'''
+
 
+
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strrchr($get(tag),$get(char)))
 
  $puts(char,X)$puts(tag,%tag%)$puts(spacer,$strrchr($get(tag),$get(char)))
 
  $trim($right($get(tag),
 
  $trim($right($get(tag),
 
  $sub($len($get(tag)),$get(spacer))))
 
  $sub($len($get(tag)),$get(spacer))))
 +
* Example: ''blah X bleh'' returns ''bleh'', and ''blah X bleh X bluh'' returns ''bluh''
  
'''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===
 
+
 
+
'''Finds first occurence of character X and last occurence of character Y and returns everything in between:'''
+
 
+
 
  $puts(char1,X)$puts(char2,Y)$puts(tag,%tag%)
 
  $puts(char1,X)$puts(char2,Y)$puts(tag,%tag%)
 
  $puts(spacer1,$strchr($get(tag),$get(char1)))
 
  $puts(spacer1,$strchr($get(tag),$get(char1)))
 
  $puts(spacer2,$strrchr($get(tag),$get(char2)))
 
  $puts(spacer2,$strrchr($get(tag),$get(char2)))
 
  $trim($substr($get(tag),$add($get(spacer1),1),$sub($get(spacer2),1)))
 
  $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.
  
'''Example:''' blah X bleh Y bluh returns bleh
+
===Find first occurence of string XYZ, and return everything in front of string XYZ===
 
+
'''Note:''' that in most cases X will probably be equal to y here.
+
 
+
 
+
'''Finds first occurence of string XYZ and returns everything in front of string XYZ:'''
+
 
+
 
  $puts(string,XYZ)$puts(tag,%tag%)$puts(spacer,$strstr($get(tag),
 
  $puts(string,XYZ)$puts(tag,%tag%)$puts(spacer,$strstr($get(tag),
 
  $get(string)))
 
  $get(string)))
 
  $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.
 
+
'''Note:''' that string XYZ can basically be any combination of characters or words.
+
 
+
  
'''Finds first occurence of string XYZ in %tag% field and returns everything after XYZ:'''
 
  
 +
===Find first occurence of string XYZ in %tag% field, and return everything after XYZ:===
 
  $puts(string,XYZ)$puts(tag,%tag%)
 
  $puts(string,XYZ)$puts(tag,%tag%)
 
  $puts(spacer,$strstr($get(tag),$get(string)))
 
  $puts(spacer,$strstr($get(tag),$get(string)))
 
  $trim($right($get(tag),$sub($len($get(tag)),
 
  $trim($right($get(tag),$sub($len($get(tag)),
 
  $add($get(spacer),$len($get(string))))))
 
  $add($get(spacer),$len($get(string))))))
 +
* Example: ''blah XYZ bleh'' returns ''bleh''
  
'''Example:''' blah XYZ bleh returns bleh
+
===Get everything between two strings of your choice===
 +
<!-- Credit: herojoker in hydrogenaudio.org/forums/index.php?showtopic=89453 -->
 +
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.

Revision as of 02:37, 4 July 2011

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

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
  • Note: String XYZ can basically be any combination of characters or words.


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.