movie

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: 24 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 movie manages movie records in the Prism library.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("movie not found")
	ErrAlreadyExists     = errors.New("movie already in library")
	ErrTMDBNotConfigured = errors.New("TMDB API key not configured")
	ErrFileNotFound      = errors.New("movie file not found")
)

Sentinel errors returned by Service methods.

Functions

This section is empty.

Types

type AddRequest

type AddRequest struct {
	TMDBID              int
	LibraryID           string
	QualityProfileID    string
	Monitored           bool
	MinimumAvailability string // defaults to "released" when empty
	PreferredEdition    string // empty = no preference
}

AddRequest carries the fields needed to add a movie to the library.

type AddUnmatchedRequest

type AddUnmatchedRequest struct {
	Title            string
	LibraryID        string
	QualityProfileID string
}

AddUnmatchedRequest carries the fields needed to add a file that has no TMDB match. The resulting movie record has tmdb_id = 0, monitored = false, and uses the caller-supplied title (typically the raw filename stem).

type FileInfo

type FileInfo struct {
	ID            string
	MovieID       string
	Path          string
	SizeBytes     int64
	Quality       plugin.Quality
	Edition       string
	ImportedAt    time.Time
	IndexedAt     time.Time
	MediainfoJSON string // raw JSON from ffprobe scan; empty if not yet scanned
}

FileInfo is the domain representation of a movie_files record.

type ListRequest

type ListRequest struct {
	LibraryID string // empty = all libraries
	Page      int    // 1-indexed; defaults to 1
	PerPage   int    // defaults to 50, max 250
}

ListRequest carries filter and pagination options for listing movies.

type ListResult

type ListResult struct {
	Movies  []Movie
	Total   int64
	Page    int
	PerPage int
}

ListResult is the paginated response from List.

type LookupRequest

type LookupRequest struct {
	Query  string
	TMDBID int // if set, fetch exact movie; Query is ignored
	Year   int // optional year filter for query search
}

LookupRequest carries parameters for searching TMDB without adding to the library.

type MetadataProvider

type MetadataProvider interface {
	SearchMovies(ctx context.Context, query string, year int) ([]tmdb.SearchResult, error)
	GetMovie(ctx context.Context, tmdbID int) (*tmdb.MovieDetail, error)
}

MetadataProvider fetches movie metadata from an external source.

type Movie

type Movie struct {
	ID                  string
	TMDBID              int
	IMDBID              string
	Title               string
	OriginalTitle       string
	Year                int
	Overview            string
	RuntimeMinutes      int
	Genres              []string
	PosterURL           string
	FanartURL           string
	Status              string
	Monitored           bool
	LibraryID           string
	QualityProfileID    string
	MinimumAvailability string
	PreferredEdition    string // empty = no preference
	ReleaseDate         string
	Path                string
	AddedAt             time.Time
	UpdatedAt           time.Time
	MetadataRefreshedAt *time.Time
}

Movie is the domain representation of a movie record.

type ParsedFilename

type ParsedFilename struct {
	Title string
	Year  int
}

ParsedFilename holds the result of parsing a release-style filename.

func ParseFilename

func ParseFilename(name string) ParsedFilename

ParseFilename extracts a clean title and year from a release-style filename.

Processing pipeline:

  1. Strip path prefix and video file extension.
  2. Remove disc-ripper noise labels (Title31, Chapter02, …).
  3. Normalise "Pt1" / "Pt.2" → "Part 1" / "Part 2".
  4. Replace dots and underscores with spaces; collapse whitespace.
  5. All-caps detection: if ≥60 % of letters are uppercase, lowercase first.
  6. Find the last 4-digit year at or before the first stop token → release year.
  7. Everything before that position is the title; trim and title-case.

type RenamePreviewItem

type RenamePreviewItem struct {
	FileID  string
	OldPath string
	NewPath string
}

RenamePreviewItem describes a single proposed or completed file rename.

type RenameSettings

type RenameSettings struct {
	Format           string
	ColonReplacement renamer.ColonReplacement
}

RenameSettings carries the naming format options used by RenameFiles.

type Service

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

Service manages movie records.

func NewService

func NewService(q dbgen.Querier, meta MetadataProvider, bus *events.Bus, logger *slog.Logger, opts ...ServiceOption) *Service

NewService creates a new Service backed by the given querier, metadata provider, event bus, and logger. meta may be nil when TMDB is not configured; methods that require it return ErrTMDBNotConfigured. sqlDB may be nil in tests; when non-nil, multi-step mutations run in a database transaction.

func (*Service) Add

func (s *Service) Add(ctx context.Context, req AddRequest) (Movie, error)

Add fetches movie details from TMDB and inserts the movie into the library. When no metadata provider is configured (TMDB key absent), the movie is still added as a stub record with a placeholder title so that it can be monitored and grabbed immediately. Calling RefreshMetadata later will populate the full metadata once a key is configured. Returns ErrAlreadyExists if a movie with the same TMDB ID is already present.

func (*Service) AddUnmatched

func (s *Service) AddUnmatched(ctx context.Context, req AddUnmatchedRequest) (Movie, error)

AddUnmatched inserts a placeholder movie record for a file that has no TMDB match. The movie is created with tmdb_id = 0 and monitored = false so it appears in the library but is not actively sought for download. Calling Update or RefreshMetadata later can associate it with a real TMDB entry.

func (*Service) AttachFile

func (s *Service) AttachFile(ctx context.Context, movieID, filePath string, sizeBytes int64, quality plugin.Quality) error

AttachFile links a file on disk to an existing movie record. It sets movies.path to the full file path, creates a movie_file record, and marks the movie status as "downloaded".

Callers are responsible for ensuring the file actually exists on disk before calling this method.

func (*Service) CountCutoffUnmet

func (s *Service) CountCutoffUnmet(ctx context.Context) (int64, error)

CountCutoffUnmet returns the number of monitored movies whose best file quality does not meet the quality profile cutoff. Unlike ListCutoffUnmet it skips the Movie conversion and sorting since only the count is needed.

func (*Service) Delete

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

Delete removes a movie by ID. It does not delete files from disk. Returns ErrNotFound if the movie does not exist.

func (*Service) DeleteFile

func (s *Service) DeleteFile(ctx context.Context, fileID string, deleteFromDisk bool) error

DeleteFile removes the movie_files record identified by fileID. If deleteFromDisk is true, the file at the stored path is also removed from disk (errors are logged but do not fail the operation). After the DB record is removed, if no files remain for the movie, the movie's path is cleared and its status is reset to "wanted".

func (*Service) Get

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

Get returns a single movie by its internal UUID. Returns ErrNotFound if no movie with that ID exists.

func (*Service) GetByFilePath

func (s *Service) GetByFilePath(ctx context.Context, filePath string) (Movie, error)

GetByFilePath returns the movie that owns the given file path, or ErrNotFound if no movie_files row exists for that path. If the movie_files row exists but the parent movie has been deleted (orphaned row), the orphan is cleaned up and ErrNotFound is returned.

func (*Service) GetByTMDBID

func (s *Service) GetByTMDBID(ctx context.Context, tmdbID int) (Movie, error)

GetByTMDBID returns a movie by its TMDB ID. Returns ErrNotFound if no movie with that TMDB ID exists.

func (*Service) GetFile

func (s *Service) GetFile(ctx context.Context, fileID string) (FileInfo, error)

GetFile returns the FileInfo for a single movie_file record.

func (*Service) HasMetadataProvider

func (s *Service) HasMetadataProvider() bool

HasMetadataProvider reports whether a metadata provider is currently wired up.

func (*Service) LibraryIDsByTMDBIDs

func (s *Service) LibraryIDsByTMDBIDs(ctx context.Context, tmdbIDs []int) (map[int]string, error)

LibraryIDsByTMDBIDs maps TMDB IDs to library movie IDs for the subset that exist in the library, in a single query. Used by Discover to flag already-added results without an N+1 of GetByTMDBID per result. TMDB IDs not in the library are simply absent from the returned map.

func (*Service) List

func (s *Service) List(ctx context.Context, req ListRequest) (ListResult, error)

List returns a paginated set of movies, optionally filtered by library.

func (*Service) ListCutoffUnmet

func (s *Service) ListCutoffUnmet(ctx context.Context) ([]Movie, error)

ListCutoffUnmet returns all monitored movies whose best file quality does not meet the quality profile cutoff. Filtering is done in Go to avoid complex SQL over JSON-encoded quality columns.

func (*Service) ListFiles

func (s *Service) ListFiles(ctx context.Context, movieID string) ([]FileInfo, error)

ListFiles returns all file records for a movie, newest import first.

func (*Service) ListMissing

func (s *Service) ListMissing(ctx context.Context, page, perPage int) ([]Movie, int64, error)

ListMissing returns paginated monitored movies that have no associated file.

func (*Service) Lookup

func (s *Service) Lookup(ctx context.Context, req LookupRequest) ([]tmdb.SearchResult, error)

Lookup searches TMDB without adding anything to the library. If req.TMDBID is non-zero, it fetches that specific movie by ID. Otherwise it performs a text search using req.Query and optional req.Year. Returns ErrTMDBNotConfigured if no metadata provider is wired up.

func (*Service) MatchToTMDB

func (s *Service) MatchToTMDB(ctx context.Context, movieID string, tmdbID int) (Movie, error)

MatchToTMDB associates an existing unmatched movie record with a TMDB entry. It updates the movie's tmdb_id and then refreshes all metadata fields from TMDB in a single step. Returns ErrAlreadyExists if another movie in the library already owns the supplied tmdbID. Returns ErrTMDBNotConfigured when no metadata provider is wired up.

func (*Service) RefreshMetadata

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

RefreshMetadata re-fetches TMDB data and updates the movie record in place. Returns ErrNotFound if the movie does not exist. Returns ErrTMDBNotConfigured if no metadata provider is wired up.

func (*Service) RenameFiles

func (s *Service) RenameFiles(ctx context.Context, movieID string, settings RenameSettings, dryRun bool) ([]RenamePreviewItem, error)

RenameFiles computes the standard-format destination filename for every file belonging to movieID using the supplied settings. Files whose current name already matches the computed name are skipped.

If dryRun is true, no disk or DB operations are performed; the returned slice describes what would happen. If dryRun is false, each file is renamed on disk and the DB record is updated. Errors for individual files are logged and skipped; a combined error is returned if any file could not be renamed.

Returns ErrNotFound if the movie does not exist.

func (*Service) SetMetadataProvider

func (s *Service) SetMetadataProvider(p MetadataProvider)

SetMetadataProvider replaces the metadata provider at runtime without restarting the server. Safe for concurrent use.

func (*Service) SetRenameFunc

func (s *Service) SetRenameFunc(fn func(oldPath, newPath string) error)

SetRenameFunc replaces the function used to rename files on disk. Intended for use in tests to inject a mock without touching the real filesystem.

func (*Service) SuggestMatches

func (s *Service) SuggestMatches(ctx context.Context, id string) ([]tmdb.SearchResult, ParsedFilename, error)

SuggestMatches parses the stored filename/title of an unmatched movie, searches TMDB with the extracted title and year, and returns ranked results. Returns ErrNotFound if the movie does not exist. Returns ErrTMDBNotConfigured if no metadata provider is wired up.

func (*Service) Update

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

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

type ServiceOption

type ServiceOption func(*Service)

ServiceOption configures optional Service dependencies.

func WithDB

func WithDB(sqlDB *sql.DB) ServiceOption

WithDB provides a *sql.DB for transaction support. When set, multi-step mutations (AttachFile, DeleteFile) run atomically.

type UpdateRequest

type UpdateRequest struct {
	Title               string
	Monitored           bool
	LibraryID           string
	QualityProfileID    string
	MinimumAvailability string  // preserved from existing when empty
	PreferredEdition    *string // nil = don't change; pointer to "" clears it
}

UpdateRequest carries the mutable fields for updating a movie.

Jump to

Keyboard shortcuts

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