Accessing and Storing Functions: Difference between revisions
(17 intermediate revisions by 4 users not shown) | |||
Line 9: | Line 9: | ||
{{function description box |
{{function description box |
||
| name=Field |
| name=Field |
||
| arguments=name, mode |
| arguments=name, mode, filekey |
||
| description= |
| description= |
||
⚫ | |||
⚫ | |||
The [[#Field|Field()]] function returns the value stored in field <i>name</i>. |
The [[#Field|Field()]] function returns the value stored in field <i>name</i>. |
||
The format of return is selected by <i>mode</i>. |
The format of return is selected by <i>mode</i>.<br> |
||
If the [[FileKey()|''FileKey'']] argument is specified, the value returned will be from the file referenced by that filekey. If not specified, values are returned from the current file. |
|||
{{argument table |
{{argument table |
||
Line 20: | Line 24: | ||
{{argument table row|1|Formatted data}} |
{{argument table row|1|Formatted data}} |
||
}} |
}} |
||
⚫ | |||
| examples= |
| examples= |
||
'''{{monospace|field(album)}}''' |
'''{{monospace|field(album)}}''' |
||
Line 26: | Line 29: | ||
'''{{monospace|field(date, 0)}}''' |
'''{{monospace|field(date, 0)}}''' |
||
: Returns the raw, unformatted value stored in the {{monospace|date}} field. Note that this is equivalent to {{monospace|[date,0]}}. |
: Returns the raw, unformatted value stored in the {{monospace|date}} field. Note that this is equivalent to {{monospace|[date,0]}}. |
||
}} |
|||
=== <span id="FieldQuery">FieldQuery(…)</span> === |
|||
: Return a list of matches based on a list of fields to search, from a selected scope of files. |
|||
{{function description box |
|||
| name=FieldQuery |
|||
| arguments=fieldlist, valuelist, return, mode, scope |
|||
| description= |
|||
The [[#FieldQuery|FieldQuery()]] function returns a list of matches based on a list of fields to search, from a selected scope of files.. |
|||
* Fieldlist: a semi-colon delimited list of fields to search, e.g. Director;Studio |
|||
* Valuelist: a value to search for in each field in fieldlist (could be an expression) |
|||
* Return: The single field that is returned when a match is found, values from files returned as a semi-colon delimited list |
|||
* {{argument table |
|||
| name=mode |
|||
| contents= |
|||
⚫ | |||
{{argument table row|1|Exact Match}} |
|||
}} |
|||
* {{argument table |
|||
| name=scope |
|||
| contents= |
|||
{{argument table row|0|Current View (faster results - only search files in the current view)}} |
|||
{{argument table row|1|Global (searches all files)}} |
|||
{{argument table row|2|Match files of the same media type ('''''the list is gathered one time, so you will need to restart to see newly imported files''''')}} |
|||
}} |
|||
'''<u>Important Notes</u>''' |
|||
* When providing the value(s) for '''Fieldlist''', library fields are referenced by their names only. i.e., <u>no square brackets.</u> |
|||
* If a library field is desired for use in '''Valuelist''', <u>square brackets are required.</u> |
|||
* When performing searches in list type fields, such as [Actors], each entry in the field list is tested for either 'contains' or 'exactness', as specified, rather than the raw field data. |
|||
* The current implementation returns matches in ANY of the given fields (OR). AND is not possible at this time. [[https://yabb.jriver.com/interact/index.php/topic,124543.msg899283.html#msg899283 Reference]] |
|||
| examples= |
|||
'''{{monospace|FieldQuery(Director,Ridley Scott,Name,1,1)}}''' |
|||
: This queries the [Director] field of ''all'' files for exactly "Ridley Scott", returning a list of names for all positive results: ''Alien;Blade Runner;Gladiator'' |
|||
'''{{monospace|FieldQuery(Actors,Al Pacino,Name,0,0)}}''' |
|||
: This queries the [Actors] field of the currently listed files for any containing "Al Pacino", returning a list of names for all positive results: ''The Godfather;Heat;Scarface;The Irishman'' |
|||
'''{{monospace|FieldQuery(Director;Actors, Sean Penn;Nicole Kidman, Name, 1, 0)}}''' |
|||
: this returns all files where Sean Penn OR Nicole Kidman is in the Director OR Actors field |
|||
}} |
|||
=== <span id="ItemCount">ItemCount(…)</span> === |
|||
:Counts the number of files that have the exact same value of the given expression as the file the expression runs in the context of. |
|||
{{function description box |
|||
| name=ItemCount |
|||
| arguments=field |
|||
| description= |
|||
The [[#ItemCount|ItemCount()]] function counts the number of ''files'' that have the exact same value of the given expression as the ''file'' the expression runs in the context of. |
|||
''{{monospace|field}}'' is the library field name, or names, with control characters escaped, for which a count is desired. |
|||
<u>'''Notes:'''</u><br> |
|||
: * ItemCount is special because it returns counts from the entire library, not just the currently filtered subset. This means ''all'' files and ''all'' media types. |
|||
: * ItemCount can only do what it does by using a cache of the library data. The cache is rebuilt every 60 seconds, so, when testing these, changes may not be immediately noticeable. |
|||
: * Special characters are required to be escaped, otherwise, they will break the expression. For example, use /[Album Artist /(Auto/)/] not [Album Artist (Auto)] |
|||
: * ItemCount counts '''''files'''''. This means that it cannot count, for example, the number of seasons in a series, or the number of discs in an album. |
|||
: * Pay particular attention to the first example shown below regarding list type fields. |
|||
The Interact forum has a [https://yabb.jriver.com/interact/index.php/topic,122319.0.html useful thread] that discusses the above notes in more detail. |
|||
| examples= |
|||
'''{{monospace|ItemCount(/[Artist/])}}''' |
|||
: Returns the number files tagged with the currently associated artist. |
|||
: ''It is important to note that a semi-colon delimited list of artists is treated as a unique value''. For any files where the [Artist] field contains {{monospace|Bob Dylan;Mark Knopfler}}, these tracks will be counted seperately, and '''''not''''' included in the counts where [Artist] is specifically {{monospace|Bob Dylan}} or {{monospace|Mark Knopfler}}. |
|||
'''{{monospace|ItemCount(/[Artist/]/[Genre/])}}''' |
|||
: Returns the number of files of a given {{monospace|artist}} in a given {{monospace|genre}} |
|||
}} |
}} |
||
Line 47: | Line 119: | ||
{{function description box |
{{function description box |
||
| name= |
| name=Note |
||
| arguments=field label, field type, occurrence |
| arguments=field label, field type, occurrence |
||
| description= |
| description= |
||
⚫ | |||
⚫ | |||
The [[#Note|Note()]] function retrieves information from a Media Center Note. |
The [[#Note|Note()]] function retrieves information from a Media Center Note. |
||
Specifically, it returns the contents associated with a <i>field label</i>, of a given <i>field type</i>. |
Specifically, it returns the contents associated with a <i>field label</i>, of a given <i>field type</i>. |
||
Line 59: | Line 133: | ||
The <i>field type</i> selects the specific sub-type for a given <i>field label</i>, and <i>occurrence</i> selects which instance of |
The <i>field type</i> selects the specific sub-type for a given <i>field label</i>, and <i>occurrence</i> selects which instance of |
||
several <i>field label</i> / <i>field type</i> pairs is returned. The <i>occurrence</i> value is zero-based. |
several <i>field label</i> / <i>field type</i> pairs is returned. The <i>occurrence</i> value is zero-based. |
||
⚫ | |||
⚫ | |||
| examples= |
| examples= |
||
'''{{monospace|note(phone)}}''' |
'''{{monospace|note(phone)}}''' |
||
Line 78: | Line 148: | ||
{{function description box |
{{function description box |
||
| name= |
| name=Save |
||
| arguments=value, variable, mode |
| arguments=value, variable, mode |
||
| description= |
| description= |
||
{{argument optional|mode|0}} |
|||
This [[#Save|Save()]] function saves the <i>value</i> into the specified global <i>variable</i>, and optionally will return that <i>value</i> if <i>mode</i> is set. |
This [[#Save|Save()]] function saves the <i>value</i> into the specified global <i>variable</i>, and optionally will return that <i>value</i> if <i>mode</i> is set. |
||
Once a global <i>variable</i> has been created using [[#Save|Save()]], that <i>variable</i>'s <i>value</i> is available for use with either [[#Load|Load()]] or the pseudo-field "[<i>variable</i>]". |
Once a global <i>variable</i> has been created using [[#Save|Save()]], that <i>variable</i>'s <i>value</i> is available for use with either [[#Load|Load()]] or the pseudo-field "[<i>variable</i>]". |
||
Line 90: | Line 161: | ||
{{argument table row|1|Output variables <i>value</i>}} |
{{argument table row|1|Output variables <i>value</i>}} |
||
}} |
}} |
||
⚫ | |||
| examples= |
| examples= |
||
'''{{monospace|save(Much Money, local_bank)}}''' |
'''{{monospace|save(Much Money, local_bank)}}''' |
||
Line 110: | Line 180: | ||
{{function description box |
{{function description box |
||
| name= |
| name=SaveAdd |
||
| arguments=variable, value, mode |
| arguments=variable, value, mode |
||
| description= |
| description= |
||
{{argument optional}} |
|||
The [[#SaveAdd|SaveAdd()]] function adds <i>value</i> to a global <i>variable</i> either numerically or as a list item. |
The [[#SaveAdd|SaveAdd()]] function adds <i>value</i> to a global <i>variable</i> either numerically or as a list item. |
||
The <i>mode</i> argument indicates how <i>variable</i> is modified. |
The <i>mode</i> argument indicates how <i>variable</i> is modified. |
||
Line 123: | Line 194: | ||
{{argument table row|2|Prepend string <i>value</i> as a list item to <i>variable</i>}} |
{{argument table row|2|Prepend string <i>value</i> as a list item to <i>variable</i>}} |
||
}} |
}} |
||
⚫ | |||
| examples= |
| examples= |
||
'''{{monospace|saveadd(v, 1)}}''' |
'''{{monospace|saveadd(v, 1)}}''' |
||
Line 129: | Line 199: | ||
'''{{monospace|saveadd(v, math(2 - 6))}}''' |
'''{{monospace|saveadd(v, math(2 - 6))}}''' |
||
: Numerically increments the global <i>variable</i> {{monospace|v}} by the outcome of the [[#Math|Math()]], which is {{monospace|-4}}. |
: Numerically increments the global <i>variable</i> {{monospace|v}} by the outcome of the [[#Math|Math()]], which is {{monospace|-4}}. |
||
'''{{monospace| |
'''{{monospace|save(foo, v)saveadd(v, bar, 1)load(v)}}''' |
||
: Loads <i>value</i> {{monospace|foo}} into <i>variable</i> {{monospace|v}}, then appends the <i>value</i> {{monospace|bar}} as a list item, and the final {{monospace|load(v)}} expression outputs the result of {{monospace|foo; bar}}. |
: Loads <i>value</i> {{monospace|foo}} into <i>variable</i> {{monospace|v}}, then appends the <i>value</i> {{monospace|bar}} as a list item, and the final {{monospace|load(v)}} expression outputs the result of {{monospace|foo; bar}}. |
||
'''{{monospace| |
'''{{monospace|save(That, v)saveadd(v, This, 2)load(v)}}''' |
||
: Similar to the previous example, but using the prepend <i>mode</i>, resulting in the output {{monospace|This; That}}. |
: Similar to the previous example, but using the prepend <i>mode</i>, resulting in the output {{monospace|This; That}}. |
||
}} |
|||
=== <span id="SetField">SetField(…)</span> === |
|||
:Sets a field's value. |
|||
{{function description box |
|||
| name=SetField |
|||
| arguments=name, value |
|||
| description= |
|||
The [[#SetField|SetField()]] function sets the value of <i>name</i> to <i>value</i>. |
|||
| examples= |
|||
'''{{monospace|setfield(album, Living in the Past)}}''' |
|||
: Sets the value of the {{monospace|album}} field to {{monospace|Living in the Past}}. |
|||
}} |
}} |
||
Line 139: | Line 223: | ||
{{function description box |
{{function description box |
||
| name= |
| name=Tag |
||
| arguments=tag name |
| arguments=tag name |
||
| description= |
| description= |
Latest revision as of 05:53, 15 December 2021
- See also: Expression Language and Function Index
The functions in this section access field values, store and load global variables, access file tags, and access note fields.
Field(…)
- Returns a field's value.
Description | Field(name, mode, filekey)
The Field() function returns the value stored in field name.
The format of return is selected by mode. If the FileKey argument is specified, the value returned will be from the file referenced by that filekey. If not specified, values are returned from the current file. Available mode values:
| ||||
---|---|---|---|---|---|
Examples | field(album)
field(date, 0)
|
FieldQuery(…)
- Return a list of matches based on a list of fields to search, from a selected scope of files.
Description | FieldQuery(fieldlist, valuelist, return, mode, scope)
The FieldQuery() function returns a list of matches based on a list of fields to search, from a selected scope of files..
Important Notes
| ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Examples | FieldQuery(Director,Ridley Scott,Name,1,1)
FieldQuery(Actors,Al Pacino,Name,0,0)
FieldQuery(Director;Actors, Sean Penn;Nicole Kidman, Name, 1, 0)
|
ItemCount(…)
- Counts the number of files that have the exact same value of the given expression as the file the expression runs in the context of.
Description | ItemCount(field)
The ItemCount() function counts the number of files that have the exact same value of the given expression as the file the expression runs in the context of. field is the library field name, or names, with control characters escaped, for which a count is desired. Notes:
The Interact forum has a useful thread that discusses the above notes in more detail. |
---|---|
Examples | ItemCount(/[Artist/])
ItemCount(/[Artist/]/[Genre/])
|
Load(…)
- Outputs the value of a global variable.
Description | Load(varname)
Loads and outputs the value of the specified global variable varname that has been previously stored with Save(). |
---|---|
Examples | load(var1)
save(math(1 + 2), sum)load(sum)
|
Note(…)
- Retrieve note fields.
Description | Note(field label, field type, occurrence)
The Note() function retrieves information from a Media Center Note. Specifically, it returns the contents associated with a field label, of a given field type. The Nth occurrence may be requested. Notes data may be simple text, or associated with defined a field label. Currently the only type of field label is contact information. The first line of a Note is associated with the omnipresent field label Name. The field type selects the specific sub-type for a given field label, and occurrence selects which instance of several field label / field type pairs is returned. The occurrence value is zero-based. |
---|---|
Examples | note(phone)
note(phone, home)
note(phone, home)
note(phone, home, 1))
|
Save(…)
- Saves a value to a global variable.
Description | Save(value, variable, mode)
This Save() function saves the value into the specified global variable, and optionally will return that value if mode is set. Once a global variable has been created using Save(), that variable's value is available for use with either Load() or the pseudo-field "[variable]". Available mode values:
| ||||
---|---|---|---|---|---|
Examples | save(Much Money, local_bank)
save(More Money, My Bank, 1)
save(math([duration,0] / 60), durmins)if(compare([durmins], >, 5.0), Long Track, Short Track)
Additional Examples |
SaveAdd(…)
- Adds to a global variable.
Description | SaveAdd(variable, value, mode)
The SaveAdd() function adds value to a global variable either numerically or as a list item. The mode argument indicates how variable is modified. Available mode values:
| ||||||
---|---|---|---|---|---|---|---|
Examples | saveadd(v, 1)
saveadd(v, math(2 - 6))
save(foo, v)saveadd(v, bar, 1)load(v)
save(That, v)saveadd(v, This, 2)load(v)
|
SetField(…)
- Sets a field's value.
Description | SetField(name, value)
The SetField() function sets the value of name to value. |
---|---|
Examples | setfield(album, Living in the Past)
|
Tag(…)
- Returns a file's physical tag.
Description | Tag(tag name)
The Tag() function reads and returns the value of tag name directly from a file. The Media Center Library database is not used with Tag(), and instead the specified file is read for the requested tag. The spelling and letter case of the tag name must match exactly those stored in the file. Performance note: This function must open and read the actual file, so its performance is significantly slower than other functions which operate on database fields. |
---|---|
Examples | tag(My Personal Tag)
tag(Gapless Header)
tag(exif: Date)
|