Metadata2 filter functions

Updated 1 month ago by Bryan Jones

Metadata2 Lua Functions

This document describes the Lua functions available in metadata2. The entries are in no particular order.

split

Split a string using a specified separator string.

items=split(sep,string)

Example:

items=split("~","a~bc")
print(items[1]) -- a
print(items[2]) -- bc

join

Combine multiple strings into one with an optional separator between them.

result=join(sep,string1,string2,...)

Example:

result=join("~","a","bc")
print(result) -- a~bc

WriteString

Write string parameters to the connected socket.

WriteString(item1,item2,...)

Example:

WriteString("abc",123) -- writes "abc123" to the socket

WriteByte

Write an ASCII byte to the connected socket.

WriteByte(number)

Example:

WriteByte(32) -- write a space character

LogInfo, console

Write a log message to the application log file. The message will be prefixed with "Lua: ".

LogInfo(item1,item2,...) -- or use console()
console(item1,item2,...)

SetField

Set the value of a metadata field. Any old values for the named field are replaced. The fields accumulate into a metadata packet. This packet is sent along when the SendMetadata() function is called.

SetField(fieldName,fieldValue) -- fieldName and fieldValue are strings

GetField

Get the value of a metadata field. A blank string is returned if the field doesn't exist.

fieldValue=GetField(fieldName)

FieldExists

Returns true if the specified field exists (i.e. has been previously set), or false otherwise.

boolean=FieldExists(fieldName)

SendMetadata

Sends the current metadata packet, with all the accumulated fields, for further processing.

SendMetadata()

SendMetaDataServer

This is here for backwards compatibility with metadata1. It sends a special metadata packet for further processing.

SendMetaDataServer(serverName,serverUrl,genre)

-- this has the same effect as:

SetField("metadataFunctionName","SendMetaDataServer")
SetField("metadataStreamServerName",serverName)
SetField("metadataStreamServerUrl",serverUrl)
SetField("metadataStreamGenre",genre)
SendMetadata()

SendMetaDataSong

This is here for backwards compatibility with metadata1. It sends a special metadata packet for further processing.

SendMetaDataSong(songTitle,songUrl)

-- this has the same effect as:

SetField("metadataFunctionName","SendMetaDataSong")
SetField("metadataTitleArtist",songTitle)
SetField("metadataSongUrl",songUrl)
SendMetadata()

SetCodePage

Sets the input code page for international character processing. Janis Timma has more information on this setting.

SetCodePage(numberOrString)

UseCharacterParser

Tells the upstream processor to use character-at-a-time parsing. This means that OnCharacter() function will be called for each character received.

UseCharacterParser()

UseLineParser

Tells the upstream processor to use line-at-a-time parsing. The OnLineReceived() function is called when a full line has been received.

UseXmlParser()

Enables the XML parser.

UseXmlParser()

OnCharacterData

This Lua function gets called when a character is received.

function OnCharacterReceived(asciiValueOfChar) 
-- code goes here
end

OnLineReceived

This Lua function gets called when a line of data is received. The function is only called if UseLineParser() was called at the start of the Lua filter.

function OnLineReceived(lineData,fullLine)
-- code goes here
end

The fullLine parameter will be true if an entire line was received. If fullLine is false, that means that the line is very long and that lineData contains only part of the line.

OnElementStart, OnElementEnd, OnCharacterData, OnComment, OnCdataStart, OnCdataEnd

These Lua functions are called when the XML parser is used.

GetDataTimeoutMinutes

This Lua function specifies how long to wait for data to arrive before a data timeout is triggered.

function GetDataTimeoutMinutes()
return 1 -- specify the number of minutes to wait for data
end

Once the data timeout timer expires, the application will call the OnDataTimeout() function. If this function returns true, then the application continues to wait for data. If OnDataTimeout() returns false, then the connection will be closed and reopened.

OnDataTimeout

This Lua function is called after the filter did not receive data for the interval specified by the GetDataTimeoutMinutes() function. If OnDataTimeout() returns true the application will continue to wait for data. If it returns false, the application will close and reopen the connection.


How did we do?


Knowledge Base

Powered by HelpDocs