library

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: AGPL-3.0 Imports: 5 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 owns the movies table — the Phase 1 library (TV follows the same shape in Phase 2 per the `media_type` column in the schema).

Index

Constants

View Source
const (
	KindMovie = "movie"
	KindShow  = "tv"
)

Kinds of title a bulk change can name.

View Source
const (
	ImportPending = "pending"
	ImportDone    = "done"
	ImportProblem = "problem"
)

Import states of one title.

View Source
const (
	ImportAdded   = "added"
	ImportAlready = "already"
	ImportFailed  = "failed"
)

Import outcomes of one title at registration.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddedDateCandidate

type AddedDateCandidate struct {
	Kind    string // "movie" or "series"
	ID      int64
	AddedAt time.Time
	Paths   []string // files on disk
}

AddedDateCandidate is an imported title whose added date may still be the moment of the import instead of the age of its files.

type BulkField

type BulkField int

BulkField is a setting that can be changed on many titles at once.

const (
	BulkMonitored  BulkField = iota + 1 // value: bool
	BulkNoUpgrade                       // value: bool
	BulkProfile                         // value: int64, 0 = the default profile
	BulkSourcePref                      // value: string, "" = follow the default
)

type Episode

type Episode struct {
	ID        int64
	SeriesID  int64
	Season    int
	Episode   int
	Title     string
	Overview  string
	AirDate   string // "YYYY-MM-DD", empty if TMDB has no date yet
	Status    Status
	Quality   string
	FilePath  string
	Monitored bool
}

Episode is one episode of a Series, tracked individually with the same missing -> downloading -> downloaded lifecycle as a Movie.

type GenreGap

type GenreGap struct {
	Kind   string // "movie" or "series"
	ID     int64
	TMDBID int
	Title  string
}

GenreGap is a library title whose genres have not been fetched yet.

type ImportBatch

type ImportBatch struct {
	ID             int64
	Kind           string
	Root           string
	CreatedAt      string
	FinishedAt     string
	Dismissed      bool
	Monitor        bool
	NoUpgrade      bool
	MonitorMissing bool
	Added          int // titles added (they all need details)
	Already        int // titles that were in the library already
	Failed         int // titles that could not be added at all
	Pending        int // added titles still waiting for their details
	Problems       int // failed titles plus added titles whose details failed
	// Elapsed is how long the import has run (or ran), by the server's clock,
	// so an estimate of the time left does not depend on the browser's clock.
	Elapsed time.Duration
}

ImportBatch is one confirmed import, with its counts.

func (ImportBatch) Running

func (b ImportBatch) Running() bool

Running reports whether details are still being filled in.

type ImportEntry

type ImportEntry struct {
	Kind       string // "movie" or "series"
	TMDBID     int
	Title      string
	Year       int
	PosterPath string
	Quality    string       // movies: quality of the main file
	FilePath   string       // movies: the main file
	Files      []ImportFile // shows: the episode files found on disk
	AddedAt    time.Time    // zero means now
}

ImportEntry is one title the person confirmed.

type ImportFile

type ImportFile struct {
	Path     string `json:"path"`
	Quality  string `json:"quality"`
	Season   int    `json:"season"`
	Episodes []int  `json:"episodes"`
}

ImportFile is an episode file found on disk for a show.

type ImportItem

type ImportItem struct {
	ID       int64
	BatchID  int64
	Kind     string // "movie" or "series"
	TitleID  int64
	TMDBID   int
	Title    string
	Outcome  string
	State    string
	Note     string
	Attempts int
	NextTry  string
	Files    []ImportFile
	Imported int
	Skipped  int
}

ImportItem is one title of an import.

type ImportOptions

type ImportOptions struct {
	Kind           string // "movie" or "tv"
	Root           string
	Monitor        bool // watch the titles for new episodes and better versions
	NoUpgrade      bool // do not look for better versions of what is already there
	MonitorMissing bool // shows: look for the episodes that are missing
}

ImportOptions are the choices made for a whole import.

type ImportOutcome

type ImportOutcome struct {
	ItemID  int64 // the row in import_items
	TitleID int64 // the movie or series that was added (0 when nothing was)
	Outcome string
	Note    string
}

ImportOutcome says what registering one entry did.

type ImportWatchResult

type ImportWatchResult struct {
	Movies int
	Shows  int
}

ImportWatchResult counts the titles StartWatchingImport changed.

type Movie

type Movie struct {
	ID          int64
	TMDBID      int
	Title       string
	Year        int
	Overview    string
	PosterPath  string
	Status      Status
	Quality     string
	FilePath    string
	Monitored   bool
	ReleaseDate string // "YYYY-MM-DD" from TMDB, empty if unknown — powers the calendar
	ProfileID   int64  // quality profile; 0 = the default profile
	SourcePref  string // "" = follow Settings; else usenet, torrent or both
	AddedBy     int64  // account that added it; 0 = unknown
	// Genres are TMDB genre names. nil means not fetched yet (see
	// MissingGenres); an empty, non-nil slice means TMDB lists none.
	Genres []string
	// NoUpgrade leaves the movie out of the search for better versions
	// (set for titles that came in through an import).
	NoUpgrade bool
	// DetailsState is "pending" while an import is still fetching the
	// movie's details, "problem" when that failed (DetailsNote says why in
	// plain words) and empty otherwise.
	DetailsState string
	DetailsNote  string
}

type MovieDetails

type MovieDetails struct {
	Title       string
	Year        int
	Overview    string
	PosterPath  string
	ReleaseDate string
	Genres      []string
}

MovieDetails is what the movie database says about a movie.

type RecentItem

type RecentItem struct {
	Kind       string // "movie" or "series"
	ID         int64
	TMDBID     int
	Title      string
	Year       int
	PosterPath string
	AddedAt    string
}

RecentItem is a movie or series, for "recently added" lists.

type Ref

type Ref struct {
	Kind string // KindMovie or KindShow
	ID   int64
}

Ref names one title in the library: a movie or a show.

type Repo

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

func NewRepo

func NewRepo(db *sql.DB) *Repo

func (*Repo) ActiveImportBatches

func (r *Repo) ActiveImportBatches() ([]ImportBatch, error)

ActiveImportBatches returns the imports still filling in details, and the ones that finished within the last week and were not dismissed, newest first.

func (*Repo) Add

func (r *Repo) Add(m Movie) (Movie, error)

Add inserts a movie into the library as "missing" (added via search/Discover, not yet downloaded).

func (*Repo) AddSeries

func (r *Repo) AddSeries(s Series, episodes []Episode) (Series, error)

AddSeries inserts a series and its full episode list in one transaction, so a failure halfway through never leaves a series with a partial episode list.

func (*Repo) BulkSet

func (r *Repo) BulkSet(field BulkField, value any, refs []Ref) (missing []Ref, err error)

BulkSet changes one setting on every title in refs in a single transaction and returns the titles that are not in the library (any more). Those are skipped, not an error: the rest are still changed. A database error undoes the whole change.

func (*Repo) CompleteMovieImport

func (r *Repo) CompleteMovieImport(item ImportItem, d MovieDetails) error

CompleteMovieImport stores a movie's details and marks its import item done.

func (*Repo) CompleteSeriesImport

func (r *Repo) CompleteSeriesImport(item ImportItem, d SeriesDetails, episodes []Episode) (SeriesImportResult, error)

CompleteSeriesImport stores a show's details and full episode list and marks the episodes found on disk as downloaded, all in one transaction, so automation never sees the episodes as missing in between.

func (*Repo) Delete

func (r *Repo) Delete(id int64) error

Delete removes a movie and, via foreign keys, its queue items. The lines in the Activity feed are kept, detached; the detailed events that are shown only on the movie's own page go with it, since nothing could show them again.

func (*Repo) DeleteSeries

func (r *Repo) DeleteSeries(id int64) error

DeleteSeries removes a show with its episodes and blocklist entries (via foreign keys) and the detailed events shown only on its own page. Lines in the Activity feed are kept, detached.

func (*Repo) DismissImportBatch

func (r *Repo) DismissImportBatch(id int64) error

DismissImportBatch hides a finished import's banner.

func (*Repo) DueImportItems

func (r *Repo) DueImportItems(now time.Time, limit int) ([]ImportItem, error)

DueImportItems returns up to limit titles whose details still need fetching and whose next try has come, oldest first. Problems come back too, once their wait is over: nothing is ever given up on.

func (*Repo) EpisodesWithoutQuality

func (r *Repo) EpisodesWithoutQuality() ([]UnratedEpisode, error)

EpisodesWithoutQuality lists the downloaded episodes that have a file on record but whose quality is empty or Unknown.

func (*Repo) Get

func (r *Repo) Get(id int64) (Movie, error)

func (*Repo) GetByTMDBID

func (r *Repo) GetByTMDBID(tmdbID int) (Movie, bool, error)

GetByTMDBID looks up a movie by its TMDB id — used by the movie detail page to check whether a Discover title has already been added, without needing its own library id (which doesn't exist until it's added).

func (*Repo) GetEpisode

func (r *Repo) GetEpisode(seriesID int64, season, episode int) (Episode, error)

func (*Repo) GetEpisodeByID

func (r *Repo) GetEpisodeByID(id int64) (Episode, error)

GetEpisodeByID returns one episode by its own id.

func (*Repo) GetSeries

func (r *Repo) GetSeries(id int64) (Series, error)

func (*Repo) GetSeriesByTMDBID

func (r *Repo) GetSeriesByTMDBID(tmdbID int) (Series, bool, error)

GetSeriesByTMDBID reports whether a TMDB show is already in the library.

func (*Repo) ImportBatchByID

func (r *Repo) ImportBatchByID(id int64) (ImportBatch, error)

ImportBatchByID returns one import; sql.ErrNoRows (wrapped) when there is none.

func (*Repo) ImportBatchItems

func (r *Repo) ImportBatchItems(batchID int64) ([]ImportItem, error)

ImportBatchItems lists the titles of one import in the order they were confirmed.

func (*Repo) ImportedForAddedDates

func (r *Repo) ImportedForAddedDates() ([]AddedDateCandidate, error)

ImportedForAddedDates lists the titles that an import registered before the import recorded file dates, found by the activity entries the old import wrote. Titles that came in any other way are never listed.

func (*Repo) List

func (r *Repo) List() ([]Movie, error)

func (*Repo) ListEpisodes

func (r *Repo) ListEpisodes(seriesID int64) ([]Episode, error)

ListEpisodes returns every episode of a series ordered by season then episode number.

func (*Repo) ListSeries

func (r *Repo) ListSeries() ([]Series, error)

func (*Repo) MissingGenres

func (r *Repo) MissingGenres(limit int) ([]GenreGap, error)

MissingGenres lists up to limit titles (movies first, newest first) whose genres are still unknown.

func (*Repo) MonitorFromDate

func (r *Repo) MonitorFromDate(seriesID int64, date string) error

MonitorFromDate sets every episode of a series monitored when it airs on or after date (or has no date yet) and unmonitored when it aired earlier, so a newly added show can track only what is still to come.

func (*Repo) RecentlyAdded

func (r *Repo) RecentlyAdded(limit int) ([]RecentItem, error)

RecentlyAdded returns the newest movies and series together, newest first.

func (*Repo) RegisterImport

func (r *Repo) RegisterImport(opts ImportOptions, entries []ImportEntry) (int64, []ImportOutcome, error)

RegisterImport adds the entries to the library in one transaction and returns what happened to each, in order. Nothing here talks to the network. A title that cannot be added is reported as failed and does not stop the others.

func (*Repo) RunningImportKinds

func (r *Repo) RunningImportKinds() (map[string]bool, error)

RunningImportKinds returns the kinds ("movie" or "tv") that have an import still filling in details.

func (*Repo) SetAddedAt

func (r *Repo) SetAddedAt(kind string, id int64, at time.Time) error

SetAddedAt changes when a movie ("movie") or show ("series") counts as added.

func (*Repo) SetAllEpisodesMonitored

func (r *Repo) SetAllEpisodesMonitored(seriesID int64, monitored bool) error

SetAllEpisodesMonitored sets the monitored flag on every episode of a series.

func (*Repo) SetEpisodeMonitored

func (r *Repo) SetEpisodeMonitored(id int64, monitored bool) error

SetEpisodeMonitored turns automatic searching for one episode on or off.

func (*Repo) SetEpisodeQualities

func (r *Repo) SetEpisodeQualities(byID map[int64]string) error

SetEpisodeQualities stores a quality for each episode id in one transaction. An episode that has gained a quality in the meantime is left as it is.

func (*Repo) SetEpisodeStatus

func (r *Repo) SetEpisodeStatus(id int64, status Status, quality, filePath string) error

SetEpisodeStatus mirrors Repo.SetStatus for movies: empty quality/ filePath leave the existing values alone.

func (*Repo) SetImportItemState

func (r *Repo) SetImportItemState(item ImportItem, state, note string, attempts int, next time.Time) error

SetImportItemState records that a title's details are pending or hit a problem, with the reason in plain words and when to try again.

func (*Repo) SetMonitored

func (r *Repo) SetMonitored(id int64, monitored bool) error

SetMonitored turns automatic searching for a movie on or off.

func (*Repo) SetMovieGenres

func (r *Repo) SetMovieGenres(id int64, genres []string) error

SetMovieGenres stores a movie's genre names (nil is stored as an empty list, so the title is not fetched again).

func (*Repo) SetNoUpgrade

func (r *Repo) SetNoUpgrade(id int64, noUpgrade bool) error

SetNoUpgrade turns the search for better versions of a movie off (or back on).

func (*Repo) SetProfile

func (r *Repo) SetProfile(id, profileID int64) error

SetProfile assigns a quality profile to a movie (0 = use the default).

func (*Repo) SetSeasonMonitored

func (r *Repo) SetSeasonMonitored(seriesID int64, season int, monitored bool) error

SetSeasonMonitored sets the monitored flag on every episode of a season.

func (*Repo) SetSeriesGenres

func (r *Repo) SetSeriesGenres(id int64, genres []string) error

SetSeriesGenres is SetMovieGenres for a show.

func (*Repo) SetSeriesMonitored

func (r *Repo) SetSeriesMonitored(id int64, monitored bool) error

SetSeriesMonitored turns automatic searching for a whole series on or off.

func (*Repo) SetSeriesNoUpgrade

func (r *Repo) SetSeriesNoUpgrade(id int64, noUpgrade bool) error

SetSeriesNoUpgrade turns the search for better versions of a show's episodes off (or back on).

func (*Repo) SetSeriesProfile

func (r *Repo) SetSeriesProfile(id, profileID int64) error

SetSeriesProfile assigns a quality profile to a series (0 = use the default).

func (*Repo) SetSeriesSourcePref

func (r *Repo) SetSeriesSourcePref(id int64, pref string) error

SetSeriesSourcePref sets which downloaders a series may use ("" = the default).

func (*Repo) SetSourcePref

func (r *Repo) SetSourcePref(id int64, pref string) error

SetSourcePref sets which downloaders a movie may use ("" = the default).

func (*Repo) SetStatus

func (r *Repo) SetStatus(id int64, status Status, quality, filePath string) error

SetStatus updates a movie's lifecycle status (missing -> downloading -> downloaded), and optionally its resolved quality/file path once known.

func (*Repo) StartWatchingImport

func (r *Repo) StartWatchingImport(batchID int64, watch, missing bool) (ImportWatchResult, error)

StartWatchingImport switches monitoring on for the titles an import added itself, once it is done. Titles that were in the library before are left as they were, and so are titles removed since.

watch starts watching the titles for new episodes and better versions. missing (shows only) makes the episodes a show does not have wanted, which also puts the show under watch for those. The batch remembers both, so its report and banner say what is switched on now.

func (*Repo) UpsertEpisodes

func (r *Repo) UpsertEpisodes(seriesID int64, episodes []Episode, monitorNew bool) error

UpsertEpisodes inserts episodes that don't exist yet and refreshes the title/overview/air date of ones that do (new seasons appear and air dates get announced/moved over a show's life) — never touching an existing episode's status, quality, or file, which are download state.

type Series

type Series struct {
	ID           int64
	TMDBID       int
	Title        string
	Year         int
	Overview     string
	PosterPath   string
	FirstAirDate string
	Monitored    bool
	ProfileID    int64  // quality profile; 0 = the default profile
	SourcePref   string // "" = follow Settings; else usenet, torrent or both
	AddedBy      int64  // account that added it; 0 = unknown
	// Genres are TMDB genre names; nil means not fetched yet (as for Movie).
	Genres []string
	// NoUpgrade leaves every episode out of the search for better versions.
	NoUpgrade bool
	// DetailsState and DetailsNote work as on Movie.
	DetailsState string
	DetailsNote  string

	// Populated by GetSeries/ListSeries only, for the library views.
	EpisodeCount    int
	DownloadedCount int
}

Series is a TV show in the library. Metadata is keyed by TMDB id (TMDB covers movies and TV), not TVDB.

type SeriesDetails

type SeriesDetails struct {
	Title        string
	Year         int
	Overview     string
	PosterPath   string
	FirstAirDate string
	Genres       []string
}

SeriesDetails is what the movie database says about a show.

type SeriesImportResult

type SeriesImportResult struct {
	Imported int // episodes marked downloaded
	Skipped  int // episodes that already were
	Unknown  int // episodes on disk that the movie database does not list
}

SeriesImportResult counts what a show's import did with its files.

type Status

type Status string
const (
	StatusMissing     Status = "missing"
	StatusDownloading Status = "downloading"
	StatusDownloaded  Status = "downloaded"
)

type UnratedEpisode

type UnratedEpisode struct {
	ID       int64
	FilePath string
}

UnratedEpisode is a downloaded episode that has a file but no quality.

Jump to

Keyboard shortcuts

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