Media Server
← Plugins & Automation

Write your first plugin: a home row in about 30 lines

Started by brent 21d ago in Plugins & Automation

brentstaff

A plugin is a folder with a plugin.json and up to two scripts. Here's the smallest useful one: a home page row.

plugin.json

{
  "id": "on-this-day",
  "name": "On This Day",
  "version": "1.0.0",
  "author": "you",
  "description": "Films released on this day in an earlier year.",
  "permissions": ["library:read", "ui:home", "storage"],
  "server": "server.js"
}

The id has to be lowercase letters, numbers and dashes, and has to match the folder name.

server.js

module.exports = {
  async setup(plugin) {
    plugin.homeRow('on-this-day', () => {
      const items = plugin.library.search('', 200)
        .filter(i => i.year && i.year < new Date().getFullYear())
        .slice(0, 20);
      return items.length ? { title: 'On this day', items } : null;
    });
  },
  async teardown() {}
};

Home rows have a four second budget, and returning null renders nothing.

Try it

Drop the folder into the server's data\plugins\. It shows up in Settings, Plugins, turned off. Turn it on. Saving its settings reloads it, which is faster than restarting the server.

Share it

Zip it so plugin.json sits at the root, host the zip at an HTTPS address, and submit it on the plugins page. Every submission and every new version is reviewed before it's listed.

The full API (playback events, routes, schedules, storage, detail panels) is in the docs. Post what you build here.

Sign in to join the conversation.