---
title: Use Plugins & Parsers
slug: author/use-plugins-and-parsers
docTags: 
createdAt: 2025-03-11T07:10:25.852Z
---

This page describes how to use two advanced BrightSign Author features: custom autorun plugins and parser scripts. These instructions assume a certain level of familiarity with [BrightScript](docId\:R7Xc0_ZE4u0BR662lI2Sj). This is not a comprehensive guide to writing custom scripts for BrightSign Author; it is meant to provide a general outline and best practices for writing those scripts.

# Plugins

Plugins allow you to add script extensions to a standard presentation autorun. For example, you can use plugins to change variable values, extract information from a *.txt*, *.csv*, *.xml*, or *.json* file to display it onscreen, change the contents of a playlist, or change how the presentation responds to external input.

Plugins have two primary benefits over custom autoruns:

- They can be easily inserted into multiple presentations, including newer and older versions of the same presentation.
- They are not dependent on a certain autorun or firmware version, greatly reducing the complexity involved in updating custom BrightScript deployments.

# Autorun Plugins

To designate one or more custom plugins in BrightSign Author:

1. If you are a BrightSign Author Plus user, upload your plugin to the server through the Content upload (see [Content > Scripts](docId\:gPjwF1LNjhau_EQZJMfUq)). If you are a BrightSign Author user, skip directly to step 2 to add a plugin to the presentation.
2. Attach it to your presentation (see [Presentation Settings > Script Plugin](docId\:a6Ali6u-szxHuansk6T3-)).
3. If needed, refer to [Plugin Message Event](docId\:J999ADmh_wDx3XWbbkZ0N) to trigger state changes.

See the [BrightSign GitHub page](https://github.com/brightsign/BrightAuthor-Plugins) for BrightSign Author and Author Plus plugin examples.

# Plugin Structure

Plug-in scripts must include an initialization function in the form of `<plugin_name>_Initialize()`. Actions that take a lot of time should not be done in the initialization routine, because actions in the routine are synchronous. Instead, start a timer that will be caught by the plugin event handler soon after the routine runs, and execute the longer code segment there. For example, instead of unzipping a file in the initialization routine, do it through the plugin event handler with a timer started in the routine.

The initialization function is passed three parameters:

- `msgPort As Object`
- `userVariables As Object`
- `o As Object`: This is the *.bsp* associative array from the autorun. It is required for the initialization function to return an associative array.

To process events, the plugin script must provide a `ProcessEvent()` function that is a member of the associative array returned by the initialization function described above. The `ProcessEvent()` function is passed a single event object. The function then returns a Boolean indicating whether or not the autorun should continue processing the event object: The function will return True if it handles the event and the standard autorun should not continue processing the event.

The associative array that defines the object must also include an `objectName` entry that defines the name of the object.

The following is an example of a script plugin file named *pizza.brs*:

:::CodeblockTabs
BrightScript

```text
Function pizza_Initialize(msgPort As Object, userVariables As Object, bsp As Object)
    
    print "pizza_Initialize - entry"
    print "type of msgPort is ";type(msgPort)
    print "type of userVariables is ";type(userVariables)
    
    PizzaBuilder = newPizzaBuilder(msgPort, userVariables, bsp)
    return PizzaBuilder
    
End Function

Function newPizzaBuilder(msgPort As Object, userVariables As Object, bsp as Object)

    PizzaBuilder = { }
    PizzaBuilder.msgPort = msgPort
    PizzaBuilder.bsp = bsp	
    PizzaBuilder.userVariables = userVariables
    PizzaBuilder.objectName = "PizzaBuilder_object"
    PizzaBuilder.ProcessEvent = pizza_ProcessEvent
    
    return PizzaBuilder
    
End Function

Function pizza_ProcessEvent(event As Object)

    print "pizza_ProcessEvent - entry"
    print "type of m is ";type(m)
    print "type of event is ";type(event)

' swallows timer events - telling the autorun not to process them
    if type(event)= "roTimerEvent" then
       return true
    else
       return false
    endif

End Function
```
:::

## Receive a Plugin Message

The following example code shows how to write a script that receives a [Send Plugin Message](docId\:lG8iLYdnIB0PL8tvxTKBo)  Command from the autorun. This code listens for a message sent to the plugin named “Pizza” and then prints the message. This example uses debug output instead of print statements. Print statements only show up in the serial console, while debug statements show up in the system log.

:::CodeblockTabs
BrightScript

```text
Function pizza_ProcessEvent(event As Object)

    m.bsp.diagnostics.printdebug("@@ pizza_ProcessEvent - entry")
    m.bsp.diagnostics.printdebug("@@  type of m is " +type(m))
    m.bsp.diagnostics.printdebug("@@  type of event is " +type(event))
    
    if type(event) = "roAssociativeArray" then
        if type(event["EventType"]) = "roString"
            if event["EventType"] = "SEND_PLUGIN_MESSAGE" then
                if lcase(event["PluginName"]) = "pizza" then 'the plugin name is case sensitive'
                    pluginMessage$ = event["PluginMessage"]
                    m.bsp.diagnostics.printdebug("@@ received pluginMessage " + pluginMessage$)
                    return true
                endif
            endif
        endif
    endif
    
    return false
    
End Function
```
:::

## Send a Plugin Message

The following example code shows how to write a script that sends a message string to trigger a [Plugin Message](docId\:afDHt43LrAH0tfu6hH_Tf) event.

:::CodeblockTabs
BrightScript

```text
print "pizza_ProcessEvent - entry"
    print "type of m is ";type(m)
    print "type of event is ";type(event)

    if type(event) = "roTimer" then

        pluginMessageCmd = CreateObject("roAssociativeArray")
        pluginMessageCmd["EventType"] = "EVENT_PLUGIN_MESSAGE"
        pluginMessageCmd["PluginName"] = "Pizza"
        pluginMessageCmd["PluginMessage"] = "toppings"
        m.msgPort.PostMessage(pluginMessageCmd)
        return true

    endif

    return false

End Function
```
:::

# Parsers

Parsers can perform many of the same custom functions as plugins (for example, extracting information from a *.txt*, *.csv*, *.xml*, or *.json* file to display it onscreen or changing the contents of a playlist); however, rather than being triggered by a command or being associated with an event, parsers are associated with a downloaded data feed or a file on the microSD card. This means that any function that is triggered by an event must be written as a plugin, not a parser.

A parser does not need to work exclusively with the data in the feed associated with it. Once the parser starts running, you can use it to delete a file on the storage, send a UDP command, or download another feed or file.

# Parser Scripts - RSS

Parser scripts allow you to manipulate data sets from incoming RSS feeds. You can create RSS parser scripts for a wide array of system and presentation functions. You can designate a parser for an RSS feed in BrightSign Author ([Support Content](docId\:a6Ali6u-szxHuansk6T3-)).

:::hint{type="danger"}
The parser file must have a *.brs* extension.
:::

The following parameters can be used with an RSS parser subroutine:

- `xmlFileName$`: The name of the XML file. This value is provided by the presentation autorun.
- `itemsByIndex`: An array of the descriptions. The script should fill in this array if the Live Text object is using the “item index” to display items from this feed.
- `itemsByTitle`: An associative array of titles, descriptions. The script should fill in this array if a Live Text object is using the “item title” to display items from this feed.
- `userVariables`: An associative array of current User Variables (which are provided by the autorun). This is provided in case you want to analyze or modify the User Variables.

The following piece of example code can be used to parse RSS text:

```text
        xml = CreateObject("roXMLElement")
        if not xml.Parse(ReadAsciiFile(xmlFileName$)) then
               print "xml read failed"
        else
               if type(xml.channel.item) = "roXMLList" then
                       index% = 0
                       for each itemXML in xml.channel.item
                               itemsByIndex.push(stri(index%) + " - " + itemXML.description.GetText())
                               index% = index% + 1
                       next
               endif
        endif

end Sub
```

## Parser Scripts - MRSS

You can use a script to parse non-MRSS feeds and provide the data in a format that can be used by [Media RSS Feeds](docId\:NwU8G3Cx7oSnce-82u6eC) in BrightSign Author.

To designate a parser for an MRSS feed in BrightSign Author, go to [Presentation Settings > Support Content > Data Feeds](docId\:a6Ali6u-szxHuansk6T3-).

:::hint{type="danger"}
The parser file must have a *.brs* extension.
:::

The following parameters can be used with an MRSS parser subroutine:

- `fileName$`: The name of the feed file to be parsed. This value is provided by the presentation autorun.
- `items`: An array of associative arrays representing MRSS items to be played by Media RSS Feed states. This array is empty upon entry to the parser subroutine and should be filled by the script. When the parser subroutine exits, the autorun will supply the data in the array to Media RSS Feed states for playback. See the **Item Array Specification** section below for a list of associative-array parameters.
- `metadata`: An associative array containing optional metadata items pertaining to the entire playlist/feed.

### Items Array Specification

The parser script should add associative arrays to the `items` array–each associative array represents a single media item to be played back. The order of items in the array specifies the order of playback.

Each associative array consists of one or more key-value pairs. All values must be strings–including numerical values. The following table outlines accepted key-value pairs:

| **Key**            | **Value**                                                   | **Example**                                     | **Notes**                                                                                                                            |
| ------------------ | ----------------------------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `url`              | A download URL for the file                                 | brightsign.biz/images/myfeedpic1.jpg            | Required – The item will be ignored if this value is not present.                                                                    |
| `medium`           | video \| image \| audio \| document                         | "video"                                         | Suggested – If the `medium` and `type` values are not present, the `medium` value will default to "image".                           |
| `type`             | video/\*, audio/\*, image/\*, text/html, application/widget | "video/\*"                                      | Suggested – If the `medium` and `type` values are not present, the `type` value will default to "image/\*".                          |
| `duration`         | The display duration in seconds                             | "30"                                            | Optional – This value applies to images only, and has no effect on other media types. If not specified, this value defaults to "15". |
| `title`            | The value for the MRSS Title field                          | "myfeedpic1"                                    | Optional                                                                                                                             |
| `description`      | The value for the MRSS Description field                    | "$5.99"                                         | Optional                                                                                                                             |
| `size`             | The size of the file in bytes                               | "942061"                                        | Optional                                                                                                                             |
| `guid`             | A unique value for the file                                 | "ab05caf"                                       | Optional – When this value changes, the player will re-download the file.                                                            |
| `mrssCustomFields` | An associative array of arbitrary key-value pairs           | \{key1:"custom field A", key2:"custom field B"} | Optional – Use this associative array to include custom MRSS fields.                                                                 |

### Metadata Specification

The `metadata` object is an empty associative array when the parser subroutine is entered. This associative array can accept optional key-value pairs that represent properties for the entire feed. All values must be strings–including numerical values. The following table outlines accepted key-value pairs:

| **Key** | **Value**                   | **Example** | **Notes**                                                                                                                                                                                                                                                                                                                                    |
| ------- | --------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `title` | A title for the feed        | "myfeed1"   |                                                                                                                                                                                                                                                                                                                                              |
| `ttl`   | The time-to-live in minutes | "5"         | Represents how long the feed will be stored (whether it's used by the presentation or not) before being refreshed. The user will also set an **Update Interval** when adding the data feed to the  presentation; if the `ttl` value is specified, the presentation will use the lesser of the two values to determine the refresh frequency. |

