libraries

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: GPL-3.0 Imports: 14 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

This section is empty.

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 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).

Types

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 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) 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) 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) 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) 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.

Jump to

Keyboard shortcuts

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