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
- type AddedDateCandidate
- type BulkField
- type Episode
- type GenreGap
- type ImportBatch
- type ImportEntry
- type ImportFile
- type ImportItem
- type ImportOptions
- type ImportOutcome
- type ImportWatchResult
- type Movie
- type MovieDetails
- type RecentItem
- type Ref
- type Repo
- func (r *Repo) ActiveImportBatches() ([]ImportBatch, error)
- func (r *Repo) Add(m Movie) (Movie, error)
- func (r *Repo) AddSeries(s Series, episodes []Episode) (Series, error)
- func (r *Repo) BulkSet(field BulkField, value any, refs []Ref) (missing []Ref, err error)
- func (r *Repo) CompleteMovieImport(item ImportItem, d MovieDetails) error
- func (r *Repo) CompleteSeriesImport(item ImportItem, d SeriesDetails, episodes []Episode) (SeriesImportResult, error)
- func (r *Repo) Delete(id int64) error
- func (r *Repo) DeleteSeries(id int64) error
- func (r *Repo) DismissImportBatch(id int64) error
- func (r *Repo) DueImportItems(now time.Time, limit int) ([]ImportItem, error)
- func (r *Repo) EpisodesWithoutQuality() ([]UnratedEpisode, error)
- func (r *Repo) Get(id int64) (Movie, error)
- func (r *Repo) GetByTMDBID(tmdbID int) (Movie, bool, error)
- func (r *Repo) GetEpisode(seriesID int64, season, episode int) (Episode, error)
- func (r *Repo) GetEpisodeByID(id int64) (Episode, error)
- func (r *Repo) GetSeries(id int64) (Series, error)
- func (r *Repo) GetSeriesByTMDBID(tmdbID int) (Series, bool, error)
- func (r *Repo) ImportBatchByID(id int64) (ImportBatch, error)
- func (r *Repo) ImportBatchItems(batchID int64) ([]ImportItem, error)
- func (r *Repo) ImportedForAddedDates() ([]AddedDateCandidate, error)
- func (r *Repo) List() ([]Movie, error)
- func (r *Repo) ListEpisodes(seriesID int64) ([]Episode, error)
- func (r *Repo) ListSeries() ([]Series, error)
- func (r *Repo) MissingGenres(limit int) ([]GenreGap, error)
- func (r *Repo) MonitorFromDate(seriesID int64, date string) error
- func (r *Repo) MoveEpisodeFile(from, to string) error
- func (r *Repo) RecentlyAdded(limit int) ([]RecentItem, error)
- func (r *Repo) RegisterImport(opts ImportOptions, entries []ImportEntry) (int64, []ImportOutcome, error)
- func (r *Repo) RunningImportKinds() (map[string]bool, error)
- func (r *Repo) SetAddedAt(kind string, id int64, at time.Time) error
- func (r *Repo) SetAllEpisodesMonitored(seriesID int64, monitored bool) error
- func (r *Repo) SetEpisodeMonitored(id int64, monitored bool) error
- func (r *Repo) SetEpisodeQualities(byID map[int64]string) error
- func (r *Repo) SetEpisodeStatus(id int64, status Status, quality, filePath string) error
- func (r *Repo) SetImportItemState(item ImportItem, state, note string, attempts int, next time.Time) error
- func (r *Repo) SetMonitored(id int64, monitored bool) error
- func (r *Repo) SetMovieGenres(id int64, genres []string) error
- func (r *Repo) SetNoUpgrade(id int64, noUpgrade bool) error
- func (r *Repo) SetProfile(id, profileID int64) error
- func (r *Repo) SetRootPath(id int64, root string) error
- func (r *Repo) SetSeasonMonitored(seriesID int64, season int, monitored bool) error
- func (r *Repo) SetSeriesGenres(id int64, genres []string) error
- func (r *Repo) SetSeriesMonitored(id int64, monitored bool) error
- func (r *Repo) SetSeriesNoUpgrade(id int64, noUpgrade bool) error
- func (r *Repo) SetSeriesProfile(id, profileID int64) error
- func (r *Repo) SetSeriesRootPath(id int64, root string) error
- func (r *Repo) SetSeriesSourcePref(id int64, pref string) error
- func (r *Repo) SetSourcePref(id int64, pref string) error
- func (r *Repo) SetStatus(id int64, status Status, quality, filePath string) error
- func (r *Repo) StartWatchingImport(batchID int64, watch, missing bool) (ImportWatchResult, error)
- func (r *Repo) UpsertEpisodes(seriesID int64, episodes []Episode, monitorNew bool) error
- type Series
- type SeriesDetails
- type SeriesImportResult
- type Status
- type UnratedEpisode
Constants ¶
const ( KindMovie = "movie" KindShow = "tv" )
Kinds of title a bulk change can name.
const ( ImportPending = "pending" ImportDone = "done" ImportProblem = "problem" )
Import states of one title.
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.
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 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 ¶
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
// RootPath is the library folder the movie is kept in when it is not the
// main movies folder ("" = the main one).
RootPath 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
// State is where the title stands: "downloaded", "downloading",
// "partial" (a show with some episodes), "missing" (monitored, waiting
// for a release) or "unmonitored".
State string
}
RecentItem is a movie or series, for "recently added" lists.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
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 ¶
Add inserts a movie into the library as "missing" (added via search/Discover, not yet downloaded).
func (*Repo) AddSeries ¶
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 ¶
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 ¶
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 ¶
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 ¶
DismissImportBatch hides a finished import's banner.
func (*Repo) DueImportItems ¶
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) GetByTMDBID ¶
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 (*Repo) GetEpisodeByID ¶
GetEpisodeByID returns one episode by its own id.
func (*Repo) GetSeriesByTMDBID ¶
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) ListEpisodes ¶
ListEpisodes returns every episode of a series ordered by season then episode number.
func (*Repo) ListSeries ¶
func (*Repo) MissingGenres ¶
MissingGenres lists up to limit titles (movies first, newest first) whose genres are still unknown.
func (*Repo) MonitorFromDate ¶
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) MoveEpisodeFile ¶ added in v1.4.0
MoveEpisodeFile points every episode whose file is from at to instead (after the file was renamed on disk).
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 ¶
RunningImportKinds returns the kinds ("movie" or "tv") that have an import still filling in details.
func (*Repo) SetAddedAt ¶
SetAddedAt changes when a movie ("movie") or show ("series") counts as added.
func (*Repo) SetAllEpisodesMonitored ¶
SetAllEpisodesMonitored sets the monitored flag on every episode of a series.
func (*Repo) SetEpisodeMonitored ¶
SetEpisodeMonitored turns automatic searching for one episode on or off.
func (*Repo) SetEpisodeQualities ¶
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 ¶
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 ¶
SetMonitored turns automatic searching for a movie on or off.
func (*Repo) SetMovieGenres ¶
SetMovieGenres stores a movie's genre names (nil is stored as an empty list, so the title is not fetched again).
func (*Repo) SetNoUpgrade ¶
SetNoUpgrade turns the search for better versions of a movie off (or back on).
func (*Repo) SetProfile ¶
SetProfile assigns a quality profile to a movie (0 = use the default).
func (*Repo) SetRootPath ¶ added in v1.4.0
SetRootPath chooses the library folder a movie is kept in ("" = the main movies folder). It only affects where new files go.
func (*Repo) SetSeasonMonitored ¶
SetSeasonMonitored sets the monitored flag on every episode of a season.
func (*Repo) SetSeriesGenres ¶
SetSeriesGenres is SetMovieGenres for a show.
func (*Repo) SetSeriesMonitored ¶
SetSeriesMonitored turns automatic searching for a whole series on or off.
func (*Repo) SetSeriesNoUpgrade ¶
SetSeriesNoUpgrade turns the search for better versions of a show's episodes off (or back on).
func (*Repo) SetSeriesProfile ¶
SetSeriesProfile assigns a quality profile to a series (0 = use the default).
func (*Repo) SetSeriesRootPath ¶ added in v1.4.0
SetSeriesRootPath chooses the library folder a show is kept in ("" = the main TV folder). It only affects where new files go.
func (*Repo) SetSeriesSourcePref ¶
SetSeriesSourcePref sets which downloaders a series may use ("" = the default).
func (*Repo) SetSourcePref ¶
SetSourcePref sets which downloaders a movie may use ("" = the default).
func (*Repo) SetStatus ¶
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 ¶
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
// RootPath is the library folder the show is kept in ("" = the main TV folder).
RootPath 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 UnratedEpisode ¶
UnratedEpisode is a downloaded episode that has a file but no quality.