MrC-temp
Note: The Smartlist and Search - Rules and Modifiers page is now at its permanent home: Smartlist and Search - Rules and Modifiers
Note: The Regex() page is now at its permanent home: MC expression language page
Note: The File Properties page is now at its permanent home: File Properties (tags) page
This is MrC's working space for work-in-progress Wiki pages.
Caution: Debris Ahead...
Functions
Conditional Functions
The functions in this section test one or more arguments to produce either a true or false outcome, and execute specific actions depending upon that result.
Although the expression language does not directly support AND, OR, and XOR, these can be easily emulated. See: Database_Expressions_AND_OR_And_XOR.
The NOT operator ! (exclamation point) may be used in a conditional to invert the sense of the conditional test. Inverting the sense of a test can make reading expressions easier, or support better IfElse() sequences.
If(…): Conditional if-else evaluator
If() | if(test expression, true expression, false expression)
The If() function is used to evaluate a test expression, and will output the result of the true expression or false expression, depending upon the evaluation result. The test expression is expected to return a 0 (false value) or a non-zero (true value). Nesting is allowed. If the test expression is preceded by the NOT operator (!, an exclamation point), the sense of the test is inverted. Non-zero values are inverted to 0, and 0 is inverted to 1. |
---|---|
Examples |
|
IfElse(…): Conditional if-elseif evaluator
IfElse() | ifelse(test1, action1, test2, action2, test3, action3, …)
The IfElse() conditional provides a convenient mechanism for shortening and more clearly expressing nested conditionals into an alternating sequence of tests and actions. Any number of test/action pairs may be specified. For example, consider a nested sequence of If() tests such as the following pseudo-code:
The IfElse() statement may be used to more cleanly express the flow of expression by removing the superfluous internal If() statements, converting the clumsy expression:
into the more elegant:
If any of the test expressions test1, etc. are preceded by the NOT operator (!, an exclamation point), the sense of that test is inverted. Non-zero values are inverted to 0, and 0 is inverted to 1. Argument test2 is optional. Argument action2 is optional. Argument test3 is optional. Argument action3 is optional. |
---|---|
Examples |
|
Test and Comparison Functions
The functions in this section return a Boolean value of either 1 (true) or 0 (false). They are generally used to drive an action specified in one of the Conditional Functions.
Compare(…): Compares two numbers
Compare() | compare(value1, operator, value2)
The Compare() function compares two numeric values value1 and value2 using any operator from the following list:
Outputs 1 if the comparison is true, and 0 otherwise. | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Examples |
|
IsEqual(…): Compares two values in one of nine specified modes
IsEqual() | isequal(value1, value2, mode)
The IsEqual() function compares value1 with value2 using any mode from the list of modes below. Outputs 1 when the comparison succeeds according to the mode, and 0 otherwise. Although the mode is specified as the last argument, the comparison should be mentally read as: value1 mode value2. Available Compare Modes:
Argument mode is optional (defaults to 0). | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Examples |
|
IsEmpty(…): Tests a value for emptiness
IsEmpty() | isempty(value, mode)
The IsEmpty() function tests the given value for emptiness. The value passed is typically an Media Center field, so that some action may be taken when the field is or is not empty. Returns 1 when the value is empty, otherwise 0. Select a mode from the following:
Note that Media Center does not discriminate between a 0 value and an empty value for fields of type Integer and Decimal - both 0 and empty are considered equivalent for these field types. This is useful for fields such as the integer field Disc #, where an empty or 0 value implies that Disc # contains no useful data, and should be generally ignored or absent in display output. Pay particular attention to the third example offered below, as it covers a caveat that comes with this particular function. Argument mode is optional (defaults to 0). | ||||
---|---|---|---|---|---|
Examples |
|
IsRange(…): Tests a value for inclusion within a given range
IsRange() | isrange(value, range)
The IsRange() function tests if a value falls within a given range of values. If the value falls within the given range, 1 is returned, otherwise 0 is returned. A range is specified in the form of low-high, where low and high are either letters or numbers. The lowest value comes first, the highest second. Both low and high must be the same kind (letters or numbers). The low and high values are inclusive. Example Ranges:
|
---|---|
Examples |
Additional Examples |
IsMissing(…): Tests to see if a file exists on the system
IsMissing() | ismissing(filepath)
The IsMissing() function tests for the existence of a file in the file system. If the file is missing, the function returns 1, otherwise 0 is returned if the file exists. This function is useful for checking for missing files in a Library. IsMissing() treats special entries such as ripped Blu-ray or DVDs as single files, even though they physically exist in the file system as several files and directories. Note: Any view or list that uses IsMissing() will be slow, is Media Center must interogate each referenced file in the file system. The larger the number of files being queried, the longer it will take to produce results. Use IsMissing() with care. Argument filepath is optional (defaults to [Filename]). |
---|---|
Examples |
|
IsRemovable(…): Tests to see if a file is stored on removable media
IsRemovable() | isremovable(filepath)
The IsRemovable() function tests if a file resides on removable media and if so, returns 1, and if not, returns 0. The Media Center field [Removable] also provides the same value for a given file. Argument filepath is optional (defaults to [Filename]). |
---|---|
Examples |
|
IsInPlayingNow(…): Tests to see if a file is in the Playing Now playlist
IsInPlayingNow() | isinplayingnow(filepath)
The IsInPlayingNow() function tests if a file is in any zone's Playing Now list. Used as an expression category, pane or file list column allows distinguishing files that are in the Playing Now list. Argument filepath is optional (defaults to [Filename]). |
---|---|
Examples |
Additional Examples |
IsPlaying(…): Tests to see if a file is in currently being played
IsPlaying() | isplaying(filepath)
The IsPlaying() function tests if a file is playing in any zone. Used as an expression category, pane or file list column allows distinguishing files that are playing now. Argument filepath is optional (defaults to [Filename]). |
---|---|
Examples |
Additional Examples |
Formatting Functions
The functions in this section format their arguments in specific ways. Some functions are used for formatting values for better presentation, or according to some format, while other functions work on Media Center internal "raw" data to convert to user-friendly formats.
Certain Media Center fields are used to store values in ways that are internally convenient or effecient. But these field values are not terribly useful or meaningful when used directly.
For example, the Duration field holds values as a number seconds of length, while various Date/Time fields such as Date or Last Played store values as floating point numbers specifying a number of days and fractions of a day since a particular epoch time.
Media Center will generally format fields using the "display" format where necessary, such as in panes, file list columns, or various tools such as the Rename, Move & Copy tool. When a function requires a raw field value, or you want to access a raw field value, by sure to use the raw field format. This is done by appending a ,0 to the field's name inside the brackets. Example: [Date Imported,0].
Delimit(…): Outputs a value with head/tail strings when value is non-empty
Delimit() | delimit(expression, tail, head)
The Delimit() function outputs the value of expression prepended with a head string and/or appended with a tail string, but only if the value of the expression is non-empty. Nothing is output when the expression evaluates to empty. Argument tail is optional (defaults to SPACE). Argument head is optional (defaults to EMPTY). |
---|---|
Examples |
|
FormatBoolean(…): Formats a boolean (true / false) value in a specified manner
FormatBoolean() | formatboolean(conditional, true string, false string)
The FormatBoolean() function outputs true string and false string values to represent the 0 or 1 Boolean output resulting from the conditional expression. When the conditional evalutes to 1, the true string will be output, otherwise the false string will be output. Argument true string is optional (defaults to True). Argument false string is optional (defaults to False). |
---|---|
Examples |
|
FormatDuration(…): Presents a duration of seconds in a reader friendly format
FormatDuration() | formatduration(duration value)
The FormatDuration() function formats a duration value into a friendly format. The duration value argument is expected to be a value representing a number of seconds, typically used for media file duration. Media Center internally stores duration values in seconds. |
---|---|
Examples |
|
FormatFileSize(…): Presents a number of bytes in a reader friendly format
FormatFileSize() | formatfilesize(bytes value)
The FormatFileSize() function formats a bytes value into a friendly format. The bytes value argument is expected to be a value representing a number of bytes, typically used for media file size. Media Center internally stores file size values in bytes. FormatFileSize() will convert those byte values into unitized friendly formats such as 50 bytes, 3.2 KB or 10.4 MB. |
---|---|
Examples |
|
FormatNumber(…): Formats and rounds a number to a specified number of decimal places
FormatNumber() | formatnumber(value, decimal places, label zero, label plural, label singular)
The FormatNumber() function formats a numeric value to a specified number of decimal places, rounding its value, and optionally outputs value-dependent labels, which can be used to construct more gramatically-correct output. The value can be any numeric value. The decimal places argument specifies the number of digits to be used after the decimal point. Use -1 to output as many decimal places as available. The label selected depends on the original value, not the resulting formatted value. The label zero argument is output instead of a formatted value when the original value is 0. When this label is specified as empty, label plural is used. The label plural argument is appended to the formatted value when the original value is more than 1. The label singular argument is appended to the formatted value when the original value is equal to 1. Note: FormatNumber() will not output additional zero's after the decimal point. In otherwords, FormatNumber() rounds fractional values, but does not zero fill. Argument decimal places is optional (defaults to 0). Argument label zero is optional (defaults to label plural). Argument label plural is optional (defaults to 0). Argument label singular is optional. |
---|---|
Examples |
|
FormatRange(…): Formats a value as a range
FormatRange() | formatrange(value, range size, mode)
The FormatRange() function creates numerical or alphabetic groupings of size range size, and returns the grouping where value falls. Only the first character of value is considered and used. The range size is a numerical value specifying how wide the range should be. Numeric ranges are 0-based. The mode specifies the type of range grouping, and can be one of the following values:
Argument range size is optional (defaults to 1). Argument mode is optional (defaults to 0). | ||||||
---|---|---|---|---|---|---|---|
Examples |
Additional Examples |
Orientation(…): Outputs the orientation of an image
Orientation() | orientation()
The Orientation() function outputs one of the following words indicating the orientation of an image file:
| ||||||
---|---|---|---|---|---|---|---|
Examples |
|
PadNumber(…): Adds leading zeros to any given number
PadNumber() | padnumber(value, number digits)
The PadNumber() function adds leading zeros to any given number value, producing a value of length number digits. |
---|---|
Examples |
|
RatingStars(…): Outputs the value of Rating as a number of star characters
RatingStars() | ratingstars()
The RatingStars() function outputs the Rating field's value as the equivalent number of black star characters. |
---|---|
Examples |
|
Watched(…): Outputs a formatted video bookmark
Watched() | watched(mode)
Outputs a video's bookmark position in a human-readable format, using any mode formats from the following:
Argument mode is optional (defaults to 0). | ||||||
---|---|---|---|---|---|---|---|
Examples |
|
String Manipulation
The functions in this section are used primarly to manipulate strings. Since the Media Center expression language is primarly string-oriented, these functions provide a means to manipulate field values or the output from other expressions.
Clean(…): Clean a string to be used for various operations
Clean() | clean(string, mode)
The Clean() function is generally used to sanitize a string by stripping empty brackets, remove superfluous dash characters, eliminate leading or trailing articles, or replace filesystem-illegal characters. It is typically employed before some operation such as Rename to clean the product of joining various fields, some of which may be empty, or to produce filesystem-safe filenames. It may be used for a variety of purposes, however. The Clean() function operates using a mode specified from the following choices:
Argument mode is optional (defaults to 0). | ||||||||
---|---|---|---|---|---|---|---|---|---|
Examples |
|
FixCase(…): Changes the case of a given string
FixCase() | fixcase(string, mode)
The FixCase() function will convert the supplied text string using one mode from the following:
Argument mode is optional (defaults to 0). | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Examples |
|
FixSpacing(…): Intelligently splits adjacent camel-cased words
FixSpacing() | fixspacing(string, mode)
The FixSpacing() function inserts spaces between adjacent camel-cased words in string. It is useful for helping to clean and convert metadata that favors compactness over standard sentence structure. Use one mode from the following:
Argument mode is optional (defaults to 1). | ||||
---|---|---|---|---|---|
Examples |
|
Hexify(…): Hexifies a string to make it suitable for web usage
Hexify() | hexify(string)
The Hexify() function URI encodes a string to make it useable by a browser or search engine. Hexify() is typically used by expressions generating or working on URLs in Media Center's Link Manager. |
---|---|
Examples |
|
Left(…): Retrieves a specified number of characters from the left of a string
Left() | left(string, quantity)
The Left() function retrieves no more than quantity characters from the left of the string. |
---|---|
Examples |
|
Length(…): Returns the number of characters in a string
Length() | length(string)
The Length() function returns the number of characters contained in string. |
---|---|
Examples |
|
Mid(…): Retrieves specified characters from a string
Mid() | mid(string, start position, quantity)
The Mid() function returns a specified quantity of characters from the start postion in string. The start postion is 0-based (i.e. the first character is considered position 0). A quantify of -1 returns all characters from the start postion to the end of string. Argument start position is optional (defaults to 0). Argument quantity is optional (defaults to 1). |
---|---|
Examples |
Additional Examples
|
Regex(…): Regular expression pattern matching and capture
Regex() | regex(string, regexp, run mode, case sensitivity)
This function performs regular expression (RE) pattern matching on a string. The string is evaluated against the regular expression regexp, and run mode dictates the values output by Regex(). The three modes allow for match testing, capture output, or silent operation. All match captures are placed into special variables referenced as [R1], [R2], ... [R9], which can be used in later in the expression. The contents of the captures [R1] ... [R9] are available until the end of the expression, or Regex() is run again, whereby they are replaced. The regular expression implementation used prior to Media Cener 19 is the Microsoft 2010 TR1 engine, and in Media Cener 19 it is the Boost engine. The run mode argument can be one the following:
The case sensitivity argument toggles the case-sensitivity of regular expression matching. Case insensitivity does not apply to characters inside a character class [ ]. Use both uppercase and lowercase characters when necessary to match either case (e.g. [aAbB] to match either uppercase or lowercase A or B).
The regular expression language assigns special meaning to many characters. A few of these meta-characters, such as forward slash /, comma , and both ( and ) are also reserved and used by the Media Center expression language. To force the Media Center expression engine to ignore the meta-characters in regexp, surround the entire regular expression with /# #/. This is one of Media Center's escapements, which tells the expression engine to ignore everything inside, so that the entire, uninterpreted regexp can be provided to the Regex() regular expression evaluator. Although surrounding regexp by /# #/ is not necessary or required when no conflicting characters are in use, and you may manually escape the expression languages meta-characters with a forward slash /, it is probably a safe practice to always encase every regexp within /# #/. Argument run mode is optional (defaults to 0). Argument case sensitivity is optional (defaults to 0). | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Examples |
|
... and more to come...