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
- Variables
- type Dev
- func (d *Dev) Close(ctx context.Context) error
- func (d *Dev) Event(ctx context.Context, e Event) error
- func (d *Dev) HostPath(guest string, roots ...string) (string, bool)
- func (d *Dev) Lookup(ctx context.Context, kind, title string, year int, data json.RawMessage) (DevLookup, error)
- func (d *Dev) Scan(ctx context.Context, kind, root string, fn func(DevFile)) error
- type DevFile
- type DevLookup
- type Event
- type EventItem
- type EventPlay
- type EventUser
- type LibraryKind
- type LibraryKindView
- type Manager
- func (m *Manager) Close(ctx context.Context) error
- func (m *Manager) Download(ctx context.Context, url string) ([]byte, error)
- func (m *Manager) Emit(e Event)
- func (m *Manager) File(id, name string) (string, bool)
- func (m *Manager) Get(id string) (View, error)
- func (m *Manager) Install(ctx context.Context, pkg []byte) (View, error)
- func (m *Manager) ItemAdded(ctx context.Context, itemID int64)
- func (m *Manager) LibraryKindPlugin(kind string) (string, bool)
- func (m *Manager) LibraryKinds() []LibraryKindView
- func (m *Manager) List() []View
- func (m *Manager) Played(user store.User, it store.Item, positionMs int64, finished bool)
- func (m *Manager) PlayerFor(itemKind string) (string, bool)
- func (m *Manager) Players() []PlayerView
- func (m *Manager) PluginKinds(id string) []string
- func (m *Manager) Progress(user EventUser, item EventItem, positionMs, durationMs int64, finished bool)
- func (m *Manager) Providers() []metadata.Provider
- func (m *Manager) Remove(ctx context.Context, id string) error
- func (m *Manager) SetConfig(ctx context.Context, id string, cfg map[string]string) (View, error)
- func (m *Manager) SetEnabled(ctx context.Context, id string, on bool) (View, error)
- type Manifest
- type Permissions
- type Player
- type PlayerView
- type Plugin
- type Setting
- type View
Constants ¶
const ( EventItemAdded = "item.added" EventLibraryScanned = "library.scanned" EventPlaybackStarted = "playback.started" EventPlaybackStopped = "playback.stopped" )
Events a plugin can hear about.
const (
MaxPackageSize = 1 << 30 // the .matinee-plugin file
)
Limits on a plugin package.
Variables ¶
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.
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.
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) Event ¶
Event sends the plugin an event, as a server does for the events its manifest lists.
func (*Dev) HostPath ¶
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.
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.
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 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 (*Manager) Emit ¶
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 ¶
File finds a file a running plugin serves to the web player: anything in its players' folders, and its icon.
func (*Manager) Install ¶
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) LibraryKindPlugin ¶
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) Players ¶
func (m *Manager) Players() []PlayerView
Players lists the players running plugins have.
func (*Manager) PluginKinds ¶
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) Remove ¶
Remove stops and deletes a plugin, its folder, its data and what its player kept for everyone.
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 ¶
ParseManifest reads and checks a plugin.json.
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.
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.