libraries

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package libraries owns the library declarations. Movies (1) and TV Shows (2) are seeded once as ordinary, editable and deletable catalogue libraries.

Index

Constants

View Source
const MaxLibraryTabs = 50

MaxLibraryTabs bounds how many tabs an owner may configure on a single library.

Variables

View Source
var (
	// ErrDeleted means the owner must explicitly restore this plugin/kind.
	ErrDeleted = errors.New("libraries: library deleted by owner")
	// ErrBuiltinLibrary is retained for compatibility with older callers.
	// Delete no longer returns it.
	ErrBuiltinLibrary = errors.New("libraries: built-in library cannot be deleted")
	// ErrInvalid is a rejected declaration: empty name, an unslugifiable
	// name, or a plugin library without both ids.
	ErrInvalid = errors.New("libraries: invalid library")
)

Functions

func ApplyAppSwitches

ApplyAppSwitches applies an owner's per-app switch changes on top of a resolved presentation, updating overrides stickily and computing the fresh effective Presentations (carrying manifest/inferred HOW for every enabled app). Attempting to enable an unavailable app returns ErrInvalid with its plain-language explanation.

func LegacyConfigNames

func LegacyConfigNames(configJSON []byte) (movies, shows string, err error)

LegacyConfigNames extracts the pre-v0.3.8 library names from a raw config document (config.json bytes, or a cluster's shared server document): server.moviesLibraryName / server.tvShowsLibraryName. Missing keys come back empty; the config fields themselves are deleted, so this raw read is the only way the names survive (§1.3).

func OverridesFromLegacyPresent

OverridesFromLegacyPresent translates a legacy full Presentations payload (from older console or API callers that send `present` instead of `presentApps`) into sticky owner overrides for every app that fits.

func ResolveCataloguePresentations

func ResolveCataloguePresentations(mediaType core.MediaType, stored core.Presentations, overrides core.PresentationOverrides, isBuiltin bool) core.ResolvedPresentations

ResolveCataloguePresentations builds the same ResolvedPresentations view for built-in, catalogue, and collection libraries (always video: movie or show).

func ResolveKindPresentations

func ResolveKindPresentations(in KindPresentationInput, overrides core.PresentationOverrides) core.ResolvedPresentations

ResolveKindPresentations computes the complete presentation picture for a plugin content kind:

  • MediaClass and per-level MediaRole are inferred in strict priority: 1. explicit kind.media / level.role 2. declared present hints (mediaBrowser.collectionType/itemTypes, plex.base) 3. level shape (keys, depth, playability)
  • Available holds HOW each fitting app sees the library (manifest override when declared, otherwise inferred from the kind's class/roles/shape).
  • Effective holds ONLY the currently published apps, combining Available with manifest default hints and the owner's sticky PresentOverrides.

func ValidatePresentations

func ValidatePresentations(p core.Presentations) error

ValidatePresentations validates stored or API-supplied protocol presentations.

Types

type AppSwitchPatch

type AppSwitchPatch struct {
	AdapterOnly  *bool `json:"adapterOnly,omitempty"`
	Vela         *bool `json:"vela,omitempty"`
	Plex         *bool `json:"plex,omitempty"`
	MediaBrowser *bool `json:"mediaBrowser,omitempty"`
	Stremio      *bool `json:"stremio,omitempty"`
	Xtream       *bool `json:"xtream,omitempty"`
	Silo         *bool `json:"silo,omitempty"`
}

AppSwitchPatch carries per-app owner publish switch updates from the console.

type KindPresentationInput

type KindPresentationInput struct {
	Media   string // optional core.MediaClass
	Levels  []KindPresentationLevel
	Present core.Presentations
}

KindPresentationInput supplies the kind-level facts (class, levels, optional manifest presentation overrides/defaults) used by ResolveKindPresentations.

type KindPresentationLevel

type KindPresentationLevel struct {
	Key       string
	Role      string // optional core.MediaRole
	Playable  bool
	Container bool
}

KindPresentationLevel describes the shape facts of one hierarchy level needed to infer per-app library presentations.

type Options

type Options struct {
	CompileCataloguePolicy func([]core.LibraryExclusion, string) (*libraryfilter.Filter, error)
	CompilePluginPolicy    func(context.Context, core.LibraryID, []core.LibraryExclusion, string) (*libraryfilter.Filter, error)
	Logger                 *slog.Logger
	Now                    func() time.Time
}

Options configures the Service.

type PluginLibraryDecl

type PluginLibraryDecl struct {
	Name    string
	Present core.Presentations
}

PluginLibraryDecl is what a plugin kind asks for at install (§2.5): the default display name and presentation. Owner edits made after install win: an upsert of an existing (plugin, kind) never overwrites the stored name or presentation.

type PluginTabSchema

type PluginTabSchema struct {
	Levels           map[string]bool
	CollectionFacets map[string]bool
	PeopleFacets     map[string]bool
	Sorts            map[string]bool
}

PluginTabSchema describes the declared levels, facets and sorts of a plugin library kind when validating owner-defined tabs. Nil skips manifest-specific checks when a standalone libraries.Service runs without the plugin registry.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the libraries store. List/Get are plain indexed reads of a table that holds one row per library, never per item, so no call scales with library size.

func New

func New(ctx context.Context, db *sql.DB, o Options) (*Service, error)

New seeds the initial catalogue libraries once per database and returns the service. db must already be migrated (store.Migrate), which is how every component table is opened.

func (*Service) ByKey

func (s *Service) ByKey(ctx context.Context, key string) (core.Library, error)

ByKey returns one library by its immutable slug, or core.ErrNotFound.

func (*Service) CollectionMember

func (s *Service) CollectionMember(ctx context.Context, collectionID int64, key core.RatingKey) (bool, error)

CollectionMember reports whether key is a shared member of the owner collection collectionID: one indexed read of collections_members by (spec_id, key). A deleted collection has no members and reports false, never an error, so a collection library simply shows nothing.

func (*Service) Create

func (s *Service) Create(ctx context.Context, name string, mediaType core.MediaType, rules []core.LibraryExclusion, fallback string, p core.Presentations) (core.Library, error)

Create saves a library with sources and visible visibility rules.

func (*Service) CreateCollection

func (s *Service) CreateCollection(ctx context.Context, name string, collectionID int64, mediaType core.MediaType, p core.Presentations) (core.Library, error)

CreateCollection saves an owner collection-library (§1.5): a named library that shows exactly the titles of one owner collection (an MDBList list, a Trakt list, a smart rule, a hand-made list…). The collection id is stored as given; whether it still names a collection is checked when the library is browsed, so a deleted collection leaves the library empty rather than failing the read. mediaType pins movie|show like a filter library. The caller passes the zero Presentations for the console-only default (§15.3).

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id core.LibraryID) error

Delete withdraws publication and retains the declaration as a tombstone. Media, source membership and watch history survive removal. Retained rules are available only to already admitted playback and explicit restoration.

func (*Service) Generation

func (s *Service) Generation() uint64

Generation changes on every library mutation; it feeds frontend.PageFreshness (§6.4).

func (*Service) Get

func (s *Service) Get(ctx context.Context, id core.LibraryID) (core.Library, error)

Get returns one library by id, or core.ErrNotFound.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]core.Library, error)

List returns every library in display order. Clients list libraries on every section request, so reads come from an in-memory snapshot of the (one row per library) table, refreshed on local writes and every snapshotTTL.

func (*Service) ListCurrent

func (s *Service) ListCurrent(ctx context.Context) ([]core.Library, error)

ListCurrent bypasses the presentation cache for admission decisions.

func (*Service) ListRetained

func (s *Service) ListRetained(ctx context.Context) ([]core.Library, error)

ListRetained includes deleted declarations solely for already admitted media. Their original membership lets current viewer restrictions keep applying.

func (*Service) MigrateConfigNames

func (s *Service) MigrateConfigNames(ctx context.Context, moviesName, showsName string) error

MigrateConfigNames performs the one-time §1.3 migration: non-empty legacy names become the names of libraries 1 and 2. It runs at most once per database (libraries_state), so app wiring may call it on every open with whatever the config file still carries; once the config is rewritten without the old keys it becomes a no-op, and an owner rename in between is never overwritten.

func (*Service) MigrateConfigRules

func (s *Service) MigrateConfigRules(ctx context.Context, rules []core.LibraryExclusion, visibilityDefault string) error

MigrateConfigRules performs the one-time migration of global catalog.exclusions and catalog.visibilityDefault into built-in libraries 1 (Movies) and 2 (TV Shows): rules scoped to one media type move only to that library, while unscoped ("mixed"/"") rules move to both. Runs at most once per database so later owner edits on either library are never reverted.

func (*Service) Purge

func (s *Service) Purge(ctx context.Context, id core.LibraryID) error

Purge removes an automatically withdrawn declaration, but retains owner tombstones even across uninstall/reinstall of the same plugin identity.

func (*Service) Rename

func (s *Service) Rename(ctx context.Context, id core.LibraryID, name string) error

Rename changes a library's display name. The key never changes.

func (*Service) ResetTabs

func (s *Service) ResetTabs(ctx context.Context, id core.LibraryID) error

ResetTabs clears any owner-defined tabs on library id so it falls back to plugin-declared tabs or DefaultCatalogueTabs.

func (*Service) RestorePluginLibrary

func (s *Service) RestorePluginLibrary(ctx context.Context, plugin, kind string, decl PluginLibraryDecl) (core.Library, error)

RestorePluginLibrary is an explicit owner action. Keeping the original row preserves item references, owner settings and the exact plugin/kind identity.

func (*Service) Retained

func (s *Service) Retained(ctx context.Context, id core.LibraryID) (core.Library, error)

Retained returns declaration identity for plugin cleanup, including tombstones.

func (*Service) SetCardShape

func (s *Service) SetCardShape(ctx context.Context, id core.LibraryID, shape string) error

SetCardShape sets the owner-chosen card shape ("", "poster", "landscape", or "square") on library id.

func (*Service) SetCollection

func (s *Service) SetCollection(ctx context.Context, id core.LibraryID, collectionID int64) error

func (*Service) SetHidden

func (s *Service) SetHidden(ctx context.Context, id core.LibraryID, hidden bool) error

SetHidden hides or shows a library in all clients; it stays in the console either way.

func (*Service) SetPresent

func (s *Service) SetPresent(ctx context.Context, id core.LibraryID, p core.Presentations) error

SetPresent sets how protocols expose a library (§6.2).

func (*Service) SetPresentAndOverrides

func (s *Service) SetPresentAndOverrides(ctx context.Context, id core.LibraryID, p core.Presentations, overrides core.PresentationOverrides) error

SetPresentAndOverrides atomically saves the effective Presentations and sticky per-app owner overrides for library id.

func (*Service) SetQualityProfile

func (s *Service) SetQualityProfile(ctx context.Context, id core.LibraryID, name string) error

SetQualityProfile sets the quality profile name titles in this library rank with. An empty name means "Default" (today's Movies/Shows home/away defaults). The name is stored verbatim; whether it names a configured profile is checked at resolution time, so a profile rename or a guide sync never leaves a library pointing at a missing profile.

func (*Service) SetRules

func (s *Service) SetRules(ctx context.Context, id core.LibraryID, rules []core.LibraryExclusion, visibilityDefault string) error

SetRules validates and stores TMDB visibility rules and default visibility on a built-in or filter library. Rules on a single-type library are pinned to that library's media type.

func (*Service) SetSort

func (s *Service) SetSort(ctx context.Context, id core.LibraryID, sort int) error

SetSort sets a library's owner order in every client.

func (*Service) SetSources

func (s *Service) SetSources(ctx context.Context, id core.LibraryID, sources []string) error

SetSources records validated registry references. Validation against enabled declarations belongs to the application registry, outside the library store.

func (*Service) SetTabs

func (s *Service) SetTabs(ctx context.Context, id core.LibraryID, tabs []core.LibraryTab, pluginSchema *PluginTabSchema) ([]core.LibraryTab, error)

SetTabs validates and saves owner-defined tabs for library id.

func (*Service) SourceMember

func (s *Service) SourceMember(ctx context.Context, lib core.Library, key core.RatingKey) (bool, error)

SourceMember checks persisted membership without network work in playback.

func (*Service) UpsertPluginLibrary

func (s *Service) UpsertPluginLibrary(ctx context.Context, pluginID, kindKey string, decl PluginLibraryDecl) (core.Library, error)

UpsertPluginLibrary returns the library for one plugin media kind, creating it on first install (§2.5). An existing library is returned untouched: the stored name and presentation are owner-owned after install and a later manifest never overwrites them.

func (*Service) ValidateTabs

func (s *Service) ValidateTabs(ctx context.Context, lib core.Library, tabs []core.LibraryTab, pluginSchema *PluginTabSchema) ([]core.LibraryTab, error)

ValidateTabs normalizes and validates a library's owner-defined tabs, compiling any saved view or library tab filters against the library's media type or plugin schema.

Jump to

Keyboard shortcuts

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