library

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 20 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 library manages Prism library records and their disk-level stats.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("library not found")

ErrNotFound is returned when a library does not exist.

Functions

func ParseQualityFromPath

func ParseQualityFromPath(path string) plugin.Quality

ParseQualityFromPath infers video quality metadata from a file path using simple pattern matching. It is best-effort; fields that cannot be determined default to the "unknown" / "none" plugin constants.

Types

type CreateRequest

type CreateRequest struct {
	Name                    string
	RootPath                string
	DefaultQualityProfileID string
	NamingFormat            *string
	MinFreeSpaceGB          int
	Tags                    []string
}

CreateRequest carries the fields needed to create a library.

type DiskFile

type DiskFile struct {
	Path        string
	SizeBytes   int64
	ParsedTitle string
	ParsedYear  int
	TMDBMatch   *DiskFileTMDBMatch // nil if not yet matched
}

DiskFile represents a video file found on disk during a library scan.

type DiskFileTMDBMatch

type DiskFileTMDBMatch struct {
	TMDBID        int
	Title         string
	OriginalTitle string
	Year          int
}

DiskFileTMDBMatch holds the pre-computed TMDB match for a DiskFile.

type Library

type Library struct {
	ID                      string
	Name                    string
	RootPath                string
	DefaultQualityProfileID string
	NamingFormat            *string
	MinFreeSpaceGB          int
	Tags                    []string
	CreatedAt               time.Time
	UpdatedAt               time.Time
}

Library is the domain representation of a library record.

type Service

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

Service manages library records.

func NewService

func NewService(q dbgen.Querier, bus *events.Bus, meta tmdbSearcher) *Service

NewService creates a new Service backed by the given querier, event bus, and optional TMDB searcher (pass nil to disable background candidate matching).

func (*Service) Create

func (s *Service) Create(ctx context.Context, req CreateRequest) (Library, error)

Create inserts a new library and returns the persisted domain type.

func (*Service) Delete

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

Delete removes a library by ID. Returns ErrNotFound if the library does not exist.

func (*Service) DeleteCandidate

func (s *Service) DeleteCandidate(ctx context.Context, libraryID, filePath string) error

DeleteCandidate removes a file from the candidate table after it has been imported. It is a best-effort call — errors are intentionally ignored.

func (*Service) Get

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

Get returns a library by ID. Returns ErrNotFound if no library with that ID exists.

func (*Service) List

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

List returns all libraries ordered by name.

func (*Service) ListCandidates

func (s *Service) ListCandidates(ctx context.Context, libraryID string) ([]DiskFile, error)

ListCandidates returns all file candidates for a library from the database without walking the disk. This is the fast path used by the import modal; callers that need a fresh disk walk should use ScanDisk instead.

func (*Service) Scan

func (s *Service) Scan(ctx context.Context, libraryID string) error

Scan walks a library's root path and reconciles tracked movie files against what is actually on disk:

  • Files that exist → indexed_at is updated.
  • Files that are missing → the owning movie is marked "missing".

Scan is idempotent and safe to run concurrently with normal operations.

func (*Service) ScanDisk

func (s *Service) ScanDisk(ctx context.Context, libraryID string) ([]DiskFile, error)

ScanDisk walks the library's root path and returns video files that are not yet tracked in the movie_files table. It is the read-only counterpart to Scan — callers may use the result to let users select files for import.

As a side-effect, newly discovered files are upserted into library_file_candidates and a background TMDB matching pass is triggered for any unmatched candidates.

func (*Service) Stats

func (s *Service) Stats(ctx context.Context, id string) (Stats, error)

Stats computes runtime metrics for the library: movie count, total file size, and available disk space at the library root.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id string, req UpdateRequest) (Library, error)

Update replaces the mutable fields of an existing library. Returns ErrNotFound if the library does not exist.

type Stats

type Stats struct {
	MovieCount     int64
	TotalSizeBytes int64
	FreeSpaceBytes int64
	HealthOK       bool
	HealthMessage  string
}

Stats holds runtime metrics about a library's disk usage and health.

type UpdateRequest

type UpdateRequest = CreateRequest

UpdateRequest carries the fields needed to update a library. It is identical in shape to CreateRequest.

Jump to

Keyboard shortcuts

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