Documentation
¶
Overview ¶
Package pluginapi defines the constants and handshake line format of the Kryspal Media plugin handshake, shared by the host and the SDK.
See PROTOCOL.md for the full specification. The gRPC services are defined in the subpackage v1 (pluginv1); Go plugin authors use the subpackage sdk. This package depends only on the standard library.
Index ¶
Constants ¶
const ( // EnvCookie must equal CookieValue; otherwise the plugin should refuse to start, because it was not started by the host. EnvCookie = "KRYSPAL_PLUGIN_COOKIE" // EnvProtocols holds the protocol major versions the host supports, as comma-separated decimal numbers, e.g. "1" or "1,2". EnvProtocols = "KRYSPAL_PLUGIN_PROTOCOLS" // EnvSocketDir is the 0700 directory the host created for this plugin; the plugin creates its Unix socket in it. EnvSocketDir = "KRYSPAL_PLUGIN_SOCKET_DIR" // EnvDataDir is the plugin's own data directory (the same path as HOME): keep caches and other files here. It is // kept across upgrades and removed on uninstall. Hosts before SDK v0.2.0 do not set it; use DataDir, which falls // back to HOME. EnvDataDir = "KRYSPAL_PLUGIN_DATA_DIR" // EnvHostFeatures lists, comma-separated, the compatible protocol additions the host stores and uses (the // HostFeature* values). Older hosts do not set it; see HostFeatures. EnvHostFeatures = "KRYSPAL_HOST_FEATURES" // EnvHostSocket and EnvHostToken are the Unix socket path and one-time token of the service the host offers to plugins // (Host). They differ on every process start; older hosts do not set them, in which case the SDK's Host() // returns ErrHostUnavailable and the plugin should degrade gracefully. EnvHostSocket = "KRYSPAL_HOST_SOCKET" EnvHostToken = "KRYSPAL_HOST_TOKEN" )
Environment variables for the handshake. The host starts a plugin with a clean environment, passing only these three variables plus PATH, TMPDIR and HOME, and SSL_CERT_FILE and SSL_CERT_DIR when the host has them set.
const ( NetworkUnix = "unix" // NetworkTCP is reserved for future plugins that run over the network; the first host version does not accept it. NetworkTCP = "tcp" )
Network types in the handshake line.
const ( HostFeatureAttributes = "attributes" // ItemMetadata.attributes and PersonMetadata.attributes HostFeaturePhoto = "photo" // IMAGE_TYPE_PHOTO for people // HostFeatureStill: IMAGE_TYPE_STILL for items. Without it the host skips STILL images, so a plugin sends its stills // as BACKDROP images after the main backdrop instead. HostFeatureStill = "still" // HostFeatureConfigTypes: the setting types text, string_list and ordered_multiselect, and ConfigField.visible_when. HostFeatureConfigTypes = "config_types" // HostFeatureImageReferer: Manifest.image_fetch_rules. HostFeatureImageReferer = "image_referer" // HostFeatureTasks: the host schedules and runs Manifest.tasks (capability plugin.tasks). Without it, a plugin that // needs periodic work runs its own timer. HostFeatureTasks = "tasks" // HostFeatureImageCrop: Image.crop, Image.focus and Image.crop_hint. Without it the host uses the whole image, so a // plugin that needs a crop (for example a portrait poster cut from a wide cover) should send an uncropped image only // where it fits. HostFeatureImageCrop = "image_crop" // HostFeatureConfigItems: ConfigGroup.items and ConfigField.item. Without it the host shows an item's fields as // ordinary fields of the group, so a plugin with many items may fall back to a select plus visible_when. HostFeatureConfigItems = "config_items" // HostFeatureItemChecks: the host shows a per_item check (§7.9) next to every entry of the group's list and calls // RunCheck with RunCheckRequest.item. Without it the host runs the check once for the whole group with an empty // item, so a plugin should then test every entry the user configured. HostFeatureItemChecks = "item_checks" // HostFeatureScrapeNotices: the host shows Notice entries from metadata and image results to the user and fetches // again after retry_after_seconds when a result says incomplete. Without it notices are ignored and // an incomplete result is final. HostFeatureScrapeNotices = "scrape_notices" // HostFeatureFieldSources: the host stores ItemMetadata.field_sources, PersonMetadata.field_sources and // Image.source next to each field's provenance and shows them (§7.10). Without it they are ignored; sending them is // harmless. HostFeatureFieldSources = "field_sources" )
Values of EnvHostFeatures. Each names a compatible addition to protocol v1 that an older host ignores, so a plugin can tell whether the host will keep what it sends (for example, to put the same facts into the overview for hosts that drop attributes).
const CookieValue = "7f3a9c52-kryspal-plugin"
CookieValue is the fixed magic value of EnvCookie. It is not a secret; it only keeps users from running a plugin directly.
const MaxHandshakeLine = 1024
MaxHandshakeLine is the maximum length in bytes of the handshake line (excluding the newline). The host treats a longer line as a failed handshake.
const SocketName = "plugin.sock"
SocketName is the socket file name the SDK creates in EnvSocketDir. Plugins in other languages may choose their own name, but the full path must not exceed the Unix socket limit (107 bytes on Linux).
Variables ¶
var ErrHandshake = errors.New("plugin handshake")
ErrHandshake reports a malformed handshake line or handshake environment variable.
Functions ¶
func DataDir ¶ added in v0.2.0
DataDir returns the plugin's own data directory: EnvDataDir when the host sets it, otherwise HOME (older hosts give the plugin its own HOME with the same meaning). getenv is usually os.Getenv; an empty result means the plugin was not started by a host.
func FormatProtocols ¶
FormatProtocols formats a list of major versions as the value of EnvProtocols.
func HostFeatures ¶ added in v0.2.0
HostFeatures returns the features listed in EnvHostFeatures. The result is empty, not nil, when the variable is missing (a host older than SDK v0.2.0): such a host supports none of them. getenv is usually os.Getenv.
func NegotiateProtocol ¶
NegotiateProtocol returns the highest major version both sides support, or ErrHandshake when there is none.
func ParseProtocols ¶
ParseProtocols parses the value of EnvProtocols and returns the major versions sorted ascending without duplicates.
Types ¶
type Handshake ¶
type Handshake struct {
Protocol int // protocol major version chosen by the plugin
Network string // NetworkUnix or NetworkTCP
Address string // absolute socket path for unix; host:port for tcp
}
Handshake is the handshake line a plugin prints on stdout: <major version>|<network>|<address>.
func ParseHandshake ¶
ParseHandshake parses a handshake line (a trailing \n or \r\n is allowed). It checks only the format, not whether the host accepts the network and version.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
minimal
command
Command minimal is the smallest useful plugin: a movie metadata provider with no configuration that knows one title.
|
Command minimal is the smallest useful plugin: a movie metadata provider with no configuration that knows one title. |
|
people
command
Command people is an example of the person and recognition capabilities: GetPerson with a gallery (IMAGE_TYPE_PHOTO) and attributes, SearchPerson confirmed by works, GetImages for people, and a Recognizer that reads catalog codes such as "ABC-123" from file names.
|
Command people is an example of the person and recognition capabilities: GetPerson with a gallery (IMAGE_TYPE_PHOTO) and attributes, SearchPerson confirmed by works, GetImages for people, and a Recognizer that reads catalog codes such as "ABC-123" from file names. |
|
static
command
Command static is the minimal example plugin: a metadata provider that returns fixed data (plus three demo services for images, subtitles and user sync, see services.go).
|
Command static is the minimal example plugin: a metadata provider that returns fixed data (plus three demo services for images, subtitles and user sync, see services.go). |
|
Package hanconv converts text between Simplified and Traditional Chinese with the dictionaries of OpenCC (Open Chinese Convert, Apache License 2.0; see NOTICE).
|
Package hanconv converts text between Simplified and Traditional Chinese with the dictionaries of OpenCC (Open Chinese Convert, Apache License 2.0; see NOTICE). |
|
Package i18n is a localization helper for plugin authors: it picks a string table by the BCP 47 language tag the host sends, and when that language is missing it looks strings up along a fixed fallback chain that always ends in English.
|
Package i18n is a localization helper for plugin authors: it picks a string table by the BCP 47 language tag the host sends, and when that language is missing it looks strings up along a fixed fallback chain that always ends in English. |
|
Package plugintest is the conformance suite for Kryspal Media plugins.
|
Package plugintest is the conformance suite for Kryspal Media plugins. |
|
Package pluginv1 holds the gRPC definitions of the Kryspal Media Plugin protocol v1 (generated from plugin.proto, metadata.proto, image.proto, subtitle.proto, usersync.proto, recognize.proto, segments.proto, danmaku.proto and host.proto) and the protocol constants.
|
Package pluginv1 holds the gRPC definitions of the Kryspal Media Plugin protocol v1 (generated from plugin.proto, metadata.proto, image.proto, subtitle.proto, usersync.proto, recognize.proto, segments.proto, danmaku.proto and host.proto) and the protocol constants. |
|
Package sdk is the Kryspal Media Plugin SDK for Go plugin authors: it performs the handshake, creates the Unix socket, starts the gRPC server (including the standard health check), and shuts down gracefully on SIGTERM.
|
Package sdk is the Kryspal Media Plugin SDK for Go plugin authors: it performs the handshake, creates the Unix socket, starts the gRPC server (including the standard health check), and shuts down gracefully on SIGTERM. |