plugin

package
v0.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plugin installs and runs plugins: library kinds, details and event handlers in a sandboxed WebAssembly module (wazero), and players that the web player loads in a sandboxed frame. docs/guide/plugins describes the package format and the API.

Index

Constants

View Source
const (
	EventItemAdded       = "item.added"
	EventLibraryScanned  = "library.scanned"
	EventPlaybackStarted = "playback.started"
	EventPlaybackStopped = "playback.stopped"
)

Events a plugin can hear about.

View Source
const (
	MaxPackageSize = 1 << 30 // the .matinee-plugin file

)

Limits on a plugin package.

Variables

View Source
var (
	ErrNotFound      = errors.New("no such plugin")
	ErrNotSupported  = errors.New("this plugin was made for a different version of Matinee")
	ErrKindTaken     = errors.New("another plugin already adds a library kind with this name")
	ErrBadPackage    = errors.New("not a Matinee plugin")
	ErrPackageTooBig = errors.New("the plugin is too large")
)

Errors an admin can do something about.

View Source
var APIVersions = []int{1}

APIVersions are the plugin API versions this server runs. A plugin built for another one is listed but can't be turned on.

View Source
var Retired = map[string]string{
	"arcade": "Games libraries play arcade games themselves, on every device",
}

Retired are plugins whose work Matinee now does itself, by id, with why. They're removed when the server starts and can't be installed.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	Manifest Manifest
	// contains filtered or unexported fields
}

Dev runs a plugin's server part straight from the folder it's built in, the way a server runs it, for the matinee-plugin tool: what the plugin makes of each file in a folder, what it looks up, and how it takes events.

func OpenDev

func OpenDev(ctx context.Context, dir, data string, config map[string]string, log *slog.Logger) (*Dev, error)

OpenDev loads the plugin in dir. Its data folder is data, and config is what an admin would fill in for its settings.

func (*Dev) Close

func (d *Dev) Close(ctx context.Context) error

Close stops the plugin.

func (*Dev) Event

func (d *Dev) Event(ctx context.Context, e Event) error

Event sends the plugin an event, as a server does for the events its manifest lists.

func (*Dev) HostPath

func (d *Dev) HostPath(guest string, roots ...string) (string, bool)

HostPath finds the file behind a path the plugin gave, such as a poster: one in its package, its data folder, or one of the folders roots.

func (*Dev) Lookup

func (d *Dev) Lookup(ctx context.Context, kind, title string, year int, data json.RawMessage) (DevLookup, error)

Lookup asks the plugin for details of a title, as a server does after a scan. data is what the plugin kept with the item when scanning.

func (*Dev) Scan

func (d *Dev) Scan(ctx context.Context, kind, root string, fn func(DevFile)) error

Scan asks the plugin about every file in root that library kind would be asked about, in the order a server would, and hands each answer to fn. kind is one of the plugin's library kinds, or "" for its first.

type DevFile

type DevFile struct {
	// Path is the file, relative to the folder scanned.
	Path string `json:"path"`
	// Item is the plugin's answer as it gave it, or nil when it skipped the
	// file.
	Item json.RawMessage `json:"item,omitempty"`
	// Problems are why a server wouldn't keep the item, or parts of it.
	Problems []string `json:"problems,omitempty"`
	// Error is the plugin's error for the file, or a crash.
	Error string `json:"error,omitempty"`
}

DevFile is what the plugin made of one file.

type DevLookup

type DevLookup struct {
	// Details are the plugin's answer as it gave it, or nil for no match.
	Details  json.RawMessage `json:"details,omitempty"`
	Problems []string        `json:"problems,omitempty"`
}

DevLookup is what the plugin found for a title.

type Event

type Event struct {
	Type    string            `json:"type"`
	Time    int64             `json:"time"` // milliseconds
	Item    *EventItem        `json:"item,omitempty"`
	Library *libraryRef       `json:"library,omitempty"`
	User    *EventUser        `json:"user,omitempty"`
	Played  *EventPlay        `json:"played,omitempty"`
	Config  map[string]string `json:"config,omitempty"`
}

Event is something that happened on the server, as plugins hear of it.

func LibraryEvent

func LibraryEvent(typ string, id int64, name, kind string) Event

LibraryEvent makes an event about a library.

type EventItem

type EventItem struct {
	ID        int64  `json:"id"`
	LibraryID int64  `json:"libraryId"`
	Kind      string `json:"kind"`
	Title     string `json:"title"`
	Year      int    `json:"year,omitempty"`
	ShowTitle string `json:"showTitle,omitempty"`
	Season    int    `json:"season,omitempty"`
	Episode   int    `json:"episode,omitempty"`
	TMDBID    int64  `json:"tmdbId,omitempty"`
}

EventItem is the item an event is about.

type EventPlay

type EventPlay struct {
	PositionMs int64 `json:"positionMs"`
	DurationMs int64 `json:"durationMs,omitempty"`
	Finished   bool  `json:"finished,omitempty"`
}

EventPlay is how far someone got, for playback events.

type EventUser

type EventUser struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

EventUser is who an event is about: an account or a profile.

type LibraryKind

type LibraryKind struct {
	Name  string `json:"name"`  // such as arcade; must be unique on the server
	Label string `json:"label"` // shown when adding a library, such as Arcade
	// Description says what goes in such a library, under the kind's name
	// when adding one.
	Description string `json:"description,omitempty"`
	// Extensions are the file extensions the plugin is asked about, such as
	// .zip. Other files are skipped without asking.
	Extensions []string `json:"extensions"`
	// ItemKinds are the kinds of item the plugin files, playable ones first.
	ItemKinds []string `json:"itemKinds"`
}

LibraryKind is a kind of library a plugin adds.

type LibraryKindView

type LibraryKindView struct {
	Name        string `json:"name"`
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
	Plugin      string `json:"plugin"`
}

LibraryKind is a library kind as the add-library form shows it.

type Manager

type Manager struct {
	// Dir holds one folder per plugin, named by its id, and a <id>.data
	// folder for what the plugin keeps.
	Dir   string
	Store *store.Store
	Log   *slog.Logger
	// OnChange runs after a plugin starts or stops, so the server can pick
	// up its library kinds and metadata.
	OnChange func()
	// Client fetches packages and catalogs; plugins' own fetches use a copy
	// that keeps redirects on their allowed hosts.
	Client *http.Client
	// contains filtered or unexported fields
}

Manager keeps the installed plugins.

func Open

func Open(ctx context.Context, dir string, st *store.Store, log *slog.Logger) (*Manager, error)

Open loads the plugins in dir and starts the ones that are on.

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

Close stops every plugin.

func (*Manager) Download

func (m *Manager) Download(ctx context.Context, url string) ([]byte, error)

Download fetches a plugin package from a URL.

func (*Manager) Emit

func (m *Manager) Emit(e Event)

Emit tells every running plugin that listens for this kind of event. It never waits for a plugin: one that falls far behind misses events.

func (*Manager) File

func (m *Manager) File(id, name string) (string, bool)

File finds a file a running plugin serves to the web player: anything in its players' folders, and its icon.

func (*Manager) Get

func (m *Manager) Get(id string) (View, error)

Get returns one installed plugin.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, pkg []byte) (View, error)

Install unpacks a plugin package. A plugin that's already installed is replaced and stays on, unless the new version asks to reach more hosts. A new plugin starts off, so the admin can look at it first.

func (*Manager) ItemAdded

func (m *Manager) ItemAdded(ctx context.Context, itemID int64)

ItemAdded tells plugins that a scan added an item.

func (*Manager) LibraryKindPlugin

func (m *Manager) LibraryKindPlugin(kind string) (string, bool)

LibraryKindPlugin returns the plugin that adds a library kind.

func (*Manager) LibraryKinds

func (m *Manager) LibraryKinds() []LibraryKindView

LibraryKinds lists the library kinds running plugins add.

func (*Manager) List

func (m *Manager) List() []View

List returns the installed plugins by name.

func (*Manager) Played

func (m *Manager) Played(user store.User, it store.Item, positionMs int64, finished bool)

Played records a progress report from a player, for playback events.

func (*Manager) PlayerFor

func (m *Manager) PlayerFor(itemKind string) (string, bool)

PlayerFor returns the running plugin that plays items of a kind.

func (*Manager) Players

func (m *Manager) Players() []PlayerView

Players lists the players running plugins have.

func (*Manager) PluginKinds

func (m *Manager) PluginKinds(id string) []string

PluginKinds lists the item kinds a running plugin files.

func (*Manager) Progress

func (m *Manager) Progress(user EventUser, item EventItem, positionMs, durationMs int64, finished bool)

Progress records a progress report. Call it for every report.

func (*Manager) Providers

func (m *Manager) Providers() []metadata.Provider

Providers lists the metadata providers running plugins add.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, id string) error

Remove stops and deletes a plugin, its folder, its data and what its player kept for everyone.

func (*Manager) SetConfig

func (m *Manager) SetConfig(ctx context.Context, id string, cfg map[string]string) (View, error)

SetConfig changes a plugin's settings. Keys it doesn't have are ignored, and a secret left as it was shown ("••••••") keeps its value.

func (*Manager) SetEnabled

func (m *Manager) SetEnabled(ctx context.Context, id string, on bool) (View, error)

SetEnabled turns a plugin on, allowing the network hosts it asks for, or off.

type Manifest

type Manifest struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Version     string `json:"version"`
	API         int    `json:"api"`
	Description string `json:"description,omitempty"`
	Author      string `json:"author,omitempty"`
	License     string `json:"license,omitempty"`
	Homepage    string `json:"homepage,omitempty"`
	// Icon is an image in the package, shown in Settings.
	Icon string `json:"icon,omitempty"`

	// Server is the WebAssembly module in the package, if the plugin has one.
	Server string `json:"server,omitempty"`
	// LibraryKinds are the kinds of library the plugin adds. They need Server.
	LibraryKinds []LibraryKind `json:"libraryKinds,omitempty"`
	// Metadata lists item kinds the plugin looks up details for. They must
	// be kinds the plugin adds; it can't take over movies or music.
	Metadata []string `json:"metadata,omitempty"`
	// Events lists the events the plugin wants to hear about.
	Events []string `json:"events,omitempty"`
	// Players are pages the web player shows to play items of some kinds.
	Players []Player `json:"players,omitempty"`
	// Settings are what an admin can fill in for the plugin, such as an
	// API key. The plugin gets them with every call.
	Settings []Setting `json:"settings,omitempty"`

	Permissions Permissions `json:"permissions,omitempty"`
}

Manifest is a plugin's plugin.json.

func ParseManifest

func ParseManifest(b []byte) (Manifest, error)

ParseManifest reads and checks a plugin.json.

func (Manifest) ItemKinds

func (m Manifest) ItemKinds() []string

ItemKinds lists every item kind the plugin's library kinds file.

func (Manifest) Supported

func (m Manifest) Supported() bool

Supported reports whether this server runs the plugin's API version.

type Permissions

type Permissions struct {
	// Network lists the hosts the plugin's server part may fetch from, over
	// https. A leading "*." allows every subdomain.
	Network []string `json:"network,omitempty"`
}

Permissions are what a plugin may reach beyond its own package.

func (Permissions) AllowsHost

func (p Permissions) AllowsHost(host string) bool

AllowsHost reports whether the plugin may fetch from host.

type Player

type Player struct {
	ItemKinds []string `json:"itemKinds"`
	// Entry is the page in the package, such as player/index.html. Every
	// file under its folder is served to the web player.
	Entry string `json:"entry"`
}

Player is a page that plays items of some kinds.

type PlayerView

type PlayerView struct {
	Plugin    string   `json:"plugin"`
	ItemKinds []string `json:"itemKinds"`
	Entry     string   `json:"entry"` // its path under /plugins/{plugin}/files/
}

PlayerView is a player the web player can load.

type Plugin

type Plugin struct {
	Manifest
	// contains filtered or unexported fields
}

Plugin is an installed plugin.

func (*Plugin) Running

func (p *Plugin) Running() bool

Running reports whether the plugin is on and working.

type Setting

type Setting struct {
	Key         string `json:"key"`
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
	Secret      bool   `json:"secret,omitempty"` // shown as a password field and never sent back
}

Setting is one thing an admin can fill in for a plugin.

type View

type View struct {
	Manifest
	Enabled bool `json:"enabled"`
	Running bool `json:"running"`
	// Problem says why an enabled plugin isn't running.
	Problem   string `json:"problem,omitempty"`
	Supported bool   `json:"supported"`
	// Config holds the admin's settings, without secret ones' values.
	Config map[string]string `json:"config"`
	// HasIcon means /plugins/{id}/icon has an image.
	HasIcon bool `json:"hasIcon"`
}

View is a plugin as Settings shows it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL