store

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 22 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 store keeps all server state in a single SQLite database.

Index

Constants

View Source
const (
	CollectionSmart  = "smart"
	CollectionManual = "manual"
)
View Source
const (
	DownloadQueued    = "queued"    // waiting for the converter
	DownloadPreparing = "preparing" // being converted or checksummed
	DownloadReady     = "ready"     // File can be fetched
	DownloadFailed    = "failed"    // see Error; asking again retries
	DownloadExpired   = "expired"   // the device has it and the server's copy was cleaned up
)

Download states.

View Source
const (
	LibraryAll   = "all"   // everything in it, rated or not
	LibraryRated = "rated" // titles rated up to the profile's level
)

Library modes for kids profiles. A library without one is hidden.

View Source
const (
	RequestPending  = "pending"  // waiting for an admin
	RequestApproved = "approved" // added to Radarr or Sonarr
	RequestDeclined = "declined"
	RequestFailed   = "failed" // adding it failed; see Error. Approving again retries.
)

Request states.

View Source
const QualityOriginal = "original"

QualityOriginal downloads the file as it is, unconverted.

Variables

View Source
var (
	ErrCodeExpired = errors.New("code expired")
	ErrCodeDenied  = errors.New("sign-in was declined")
	ErrCodePending = errors.New("waiting for approval")
)
View Source
var CollectionSorts = map[string]bool{
	"title": true, "added": true, "released": true, "year": true, "rating": true,
	"runtime": true, "lastPlayed": true, "shuffle": true,
}

CollectionSorts are the orders a collection can have besides its own: a smart collection's filter order or a manual one's hand-kept order. "shuffle" is a different order each day.

View Source
var ErrLastAdmin = errors.New("the server needs at least one admin")

ErrLastAdmin means a change would leave the server with no admin.

View Source
var ErrNotFound = errors.New("not found")
View Source
var IssueKinds = []string{"video", "audio", "subtitles", "wrong", "other"}

Issue kinds.

View Source
var SortFields = []string{"title", "added", "released", "year", "rating", "runtime", "lastPlayed", "series"}

SortFields are the orders a filter can list titles in.

View Source
var WatchListKinds = map[string]bool{"movie": true, "show": true}

WatchListKinds are what can go on a watch list: things you sit down to watch, not their seasons, episodes or music.

View Source
var WatchedStates = []string{"unwatched", "inProgress", "watched", "notStarted", "started"}

WatchedStates are the values ItemFilter.Watched takes.

Functions

func FormatUserCode

func FormatUserCode(code string) string

FormatUserCode shows a user code as ABCD-EFGH.

func LanguageFrom added in v0.1.1

func LanguageFrom(ctx context.Context) string

LanguageFrom returns the language WithLanguage set, or "".

func MediaKey

func MediaKey(version int, size, mtime int64) string

MediaKey identifies one version of a file, as analyzed by one version of the analysis. The scanner updates size and mtime when a file changes.

func NormalizeUserCode

func NormalizeUserCode(code string) string

NormalizeUserCode accepts a typed code in any case, with or without the dash or spaces.

func SessionID

func SessionID(token string) string

SessionID is the public id of a session token.

func SortTitle

func SortTitle(title string) string

SortTitle drops a leading article so "The Matrix" sorts under M.

func WithLanguage added in v0.1.1

func WithLanguage(ctx context.Context, language string) context.Context

WithLanguage makes items read with ctx come in a language, one of the i18n languages. "" or English shows them as they are.

Types

type AnalysisFile

type AnalysisFile struct {
	ID    int64
	Title string
	Path  string
	Size  int64
	Mtime int64
	Key   string // media_key as stored, "" when never analyzed
}

AnalysisFile is a file the background analysis may need to look at.

type Award

type Award struct {
	Name  string   `json:"name"` // e.g. Academy Award for Best Picture
	Year  int      `json:"year,omitempty"`
	Won   bool     `json:"won"`
	Names []string `json:"names,omitempty"` // the people it went to, when not the title itself
}

type Book added in v0.1.2

type Book struct {
	Item
	Parts    []BookPart    `json:"parts"`
	Chapters []BookChapter `json:"chapters"`
}

Book is a book with its parts in order and its chapters.

type BookChapter added in v0.1.2

type BookChapter struct {
	Title   string `json:"title"`
	StartMs int64  `json:"startMs"`
	EndMs   int64  `json:"endMs"`
	PartID  int64  `json:"partId"`
}

BookChapter is a chapter on the book's own clock, which runs across its parts.

type BookGroup added in v0.1.2

type BookGroup struct {
	Name  string  `json:"name"`
	Books int     `json:"books"`
	Items []int64 `json:"itemIds"` // up to four books, first in reading order
}

BookGroup is a series or a narrator, with how many books it has and a few of them for artwork.

type BookInfo added in v0.1.2

type BookInfo struct {
	Narrators   []string
	Series      string
	SeriesIndex *float64 // its place in the series, such as 2 or 2.5
	Overview    string
}

BookInfo is what a book's files say about it.

type BookPart added in v0.1.2

type BookPart struct {
	Item
	StartMs int64 `json:"startMs"`
}

BookPart is one file of a book, and where on the book's clock it starts.

type BoxSet

type BoxSet struct {
	ID    int64  `json:"id"` // TMDB collection id
	Name  string `json:"name"`
	Count int    `json:"count"`
	// ItemIDs are its titles in the library, oldest first, for artwork.
	ItemIDs []int64 `json:"itemIds"`
}

BoxSet is one of TMDB's collections, such as a trilogy, with at least two of its titles in the library. Box sets fill themselves from metadata.

type Collection

type Collection struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

Collection is a series of movies, such as a franchise's films.

type Credit

type Credit struct {
	PersonID int64  `json:"personId"`
	Name     string `json:"name"`
	Role     string `json:"role,omitempty"` // character, or job such as Director
	// Department groups crew: Directing, Writing, Sound, Camera, Production…
	Department string `json:"department,omitempty"`
	Episodes   int    `json:"episodes,omitempty"` // for a show's cast: how many episodes they're in
	HasPhoto   bool   `json:"hasPhoto"`

	Photo string `json:"-"` // URL
}

Credit is one person's part in a title: a character they play, or a job.

type Credits

type Credits struct {
	Cast []Credit `json:"cast"`
	// Guests are an episode's guest stars.
	Guests []Credit `json:"guests,omitempty"`
	Crew   []Credit `json:"crew"`
}

Credits are the people in a title, in billing order.

type Details

type Details struct {
	Tagline          string      `json:"tagline,omitempty"`
	OriginalTitle    string      `json:"originalTitle,omitempty"`
	OriginalLanguage string      `json:"originalLanguage,omitempty"` // a language name, e.g. Japanese
	ReleaseDate      string      `json:"releaseDate,omitempty"`      // YYYY-MM-DD; first air date for shows
	EndDate          string      `json:"endDate,omitempty"`          // last air date of a show that ended
	Status           string      `json:"status,omitempty"`           // e.g. Released, Returning Series, Ended
	Certification    string      `json:"certification,omitempty"`    // e.g. PG-13 or TV-MA
	Genres           []string    `json:"genres,omitempty"`
	Studios          []string    `json:"studios,omitempty"`
	Networks         []string    `json:"networks,omitempty"`
	Countries        []string    `json:"countries,omitempty"`
	Languages        []string    `json:"languages,omitempty"` // spoken languages
	Budget           int64       `json:"budget,omitempty"`    // US dollars
	Revenue          int64       `json:"revenue,omitempty"`   // worldwide box office, US dollars
	Collection       *Collection `json:"collection,omitempty"`
	Seasons          int         `json:"seasons,omitempty"`
	Episodes         int         `json:"episodes,omitempty"`
	IMDbID           string      `json:"imdbId,omitempty"`
	WikidataID       string      `json:"wikidataId,omitempty"`
	// Awards are the wins and nominations Wikidata knows of, wins first.
	Awards []Award `json:"awards,omitempty"`
	// AwardSummary is one line for the main details pane, e.g. "Won 4
	// Academy Awards" or "12 wins and 30 nominations".
	AwardSummary string `json:"awardSummary,omitempty"`
}

Details is the longer description of a movie, show or episode that the details pages show: everything beyond the title, overview and artwork.

type DetailsUpdate

type DetailsUpdate struct {
	Details Details
	Cast    []Credit
	Guests  []Credit
	Crew    []Credit
	Terms   []Term
	// RatingLevel is the level of Details.Certification (see the rating package).
	RatingLevel int
}

DetailsUpdate is what a provider knows about a title beyond Metadata.

type Device

type Device struct {
	Name     string
	Platform string // ios, android, web, tv…
}

Device names the app or browser a session belongs to.

type DeviceCode

type DeviceCode struct {
	DeviceCode string // secret; only the device has it
	UserCode   string // what the person types, without the dash
	Device     Device
	ExpiresAt  time.Time
}

type Download

type Download struct {
	ID       string `json:"id"`
	ItemID   int64  `json:"itemId"`
	DeviceID string `json:"deviceId"`
	Quality  string `json:"quality"`
	Subtitle string `json:"subtitle,omitempty"` // a picture subtitle track drawn into the video
	State    string `json:"state"`
	Progress int    `json:"progress"` // thousandths, while preparing
	Error    string `json:"error,omitempty"`
	Size     int64  `json:"size,omitempty"`
	SHA256   string `json:"sha256,omitempty"`
	// MD5 is there for devices that can hash a file natively only with MD5;
	// it guards against a broken transfer, not tampering.
	MD5        string `json:"md5,omitempty"`
	MimeType   string `json:"mimeType,omitempty"`
	CreatedAt  int64  `json:"createdAt"`
	UpdatedAt  int64  `json:"updatedAt"`
	FinishedAt int64  `json:"finishedAt,omitempty"` // when the device said it has the whole file

	UserID   int64  `json:"-"`
	Attempts int    `json:"-"`
	File     string `json:"-"` // the prepared file's path: the original, or one in the download cache
	// The original's size and mtime when File was named, to notice it changing.
	SourceSize  int64 `json:"-"`
	SourceMtime int64 `json:"-"`
}

type Fact added in v0.1.1

type Fact struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

Fact is one labelled line about an item.

type FilterOptions

type FilterOptions struct {
	Genres         []FilterValue  `json:"genres"`
	Tags           []FilterValue  `json:"tags"`
	Studios        []FilterValue  `json:"studios"`
	Countries      []FilterValue  `json:"countries"`
	Languages      []FilterValue  `json:"languages"`
	Certifications []FilterValue  `json:"certifications"`
	Collections    []FilterValue  `json:"collections"`
	Directors      []FilterPerson `json:"directors"` // the most frequent
	Cast           []FilterPerson `json:"cast"`      // the most frequent
	YearMin        int            `json:"yearMin,omitempty"`
	YearMax        int            `json:"yearMax,omitempty"`
	HasRatings     bool           `json:"hasRatings"`
	HasRuntimes    bool           `json:"hasRuntimes"`
	HasReleased    bool           `json:"hasReleased"`
}

FilterOptions says what a library's titles can be filtered by: the values present, most common first, and the range of years, ratings and runtimes.

type FilterPerson

type FilterPerson struct {
	ID       int64  `json:"id"`
	Name     string `json:"name"`
	HasPhoto bool   `json:"hasPhoto"`
	Count    int    `json:"count"` // titles they're in
}

FilterPerson is someone credited in a library.

type FilterValue

type FilterValue struct {
	Value string `json:"value"`
	Label string `json:"label,omitempty"` // when the value is an id
	Count int    `json:"count"`
}

FilterValue is one value a filter field can take in a library, and how many titles have it.

type HolidayMatch added in v0.1.1

type HolidayMatch struct {
	Words    []string
	Keywords []string // TMDB keyword ids, as kept in item_terms
}

HolidayMatch says which movies and shows suit a holiday. A title matches when it has one of the TMDB keywords, or one of the words is in its title, its overview or (for a show) one of its episodes' titles. Words are matched without regard to case.

type Issue

type Issue struct {
	ID         string `json:"id"`
	ItemID     int64  `json:"itemId"`
	Kind       string `json:"kind"` // one of IssueKinds
	Note       string `json:"note,omitempty"`
	Resolved   bool   `json:"resolved"`
	Resolution string `json:"resolution,omitempty"` // replaced, or empty when an admin just closed it
	UserID     int64  `json:"userId"`
	Username   string `json:"username"`
	CreatedAt  int64  `json:"createdAt"`
	ResolvedAt int64  `json:"resolvedAt,omitempty"`
}

type Item

type Item struct {
	ID          int64    `json:"id"`
	LibraryID   int64    `json:"libraryId"`
	ParentID    *int64   `json:"parentId,omitempty"`
	Kind        string   `json:"kind"`
	Title       string   `json:"title"`
	Year        *int     `json:"year,omitempty"`
	IndexNumber *int     `json:"index,omitempty"`
	DiscNumber  *int     `json:"disc,omitempty"`
	DurationMs  *int64   `json:"durationMs,omitempty"`
	Container   string   `json:"container,omitempty"`
	VideoCodec  string   `json:"videoCodec,omitempty"`
	AudioCodec  string   `json:"audioCodec,omitempty"`
	Width       *int     `json:"width,omitempty"`
	Height      *int     `json:"height,omitempty"`
	AddedAt     int64    `json:"addedAt"`
	Playable    bool     `json:"playable"`
	ChildCount  int      `json:"childCount,omitempty"`
	PositionMs  int64    `json:"positionMs,omitempty"`
	Played      bool     `json:"played,omitempty"`
	Overview    string   `json:"overview,omitempty"`
	Rating      *float64 `json:"rating,omitempty"`
	HasPoster   bool     `json:"hasPoster"`
	HasBackdrop bool     `json:"hasBackdrop"`
	// For episodes: the show's title and season number, for cards outside the show's pages.
	ShowTitle   string `json:"showTitle,omitempty"`
	SeasonIndex *int   `json:"seasonIndex,omitempty"`

	// For albums and tracks: who made it, and for tracks the album it's
	// on (the album's id is ParentID), so a player can say what's playing.
	Artist   string `json:"artist,omitempty"`
	ArtistID *int64 `json:"artistId,omitempty"`
	Album    string `json:"album,omitempty"`
	// For books and their parts: who wrote it, and for a part the book's
	// title (the book's id is ParentID). Books also name their narrators
	// and their place in a series, such as 2 or 2.5.
	Author      string   `json:"author,omitempty"`
	AuthorID    *int64   `json:"authorId,omitempty"`
	Book        string   `json:"book,omitempty"`
	Narrators   []string `json:"narrators,omitempty"`
	Series      string   `json:"series,omitempty"`
	SeriesIndex *float64 `json:"seriesIndex,omitempty"`
	OnWatchList bool     `json:"onWatchList,omitempty"`
	// Genres of a movie or show, from its online match.
	Genres []string `json:"genres,omitempty"`
	// MediaTags sums up what the background analysis found, such as 4k,
	// hdr, dolby-vision, atmos or 5.1 (see probe.MediaInfo.Tags). Shows get
	// every tag any of their episodes has. Empty until analyzed.
	MediaTags []string `json:"mediaTags,omitempty"`

	Poster   string `json:"-"`
	Backdrop string `json:"-"`
	TMDBID   *int64 `json:"-"`
	MetaAt   int64  `json:"-"` // 0 until online metadata was looked up
	// Pending is true while an online lookup for the item is still to come.
	Pending bool   `json:"pending,omitempty"`
	Path    string `json:"-"`
	Size    int64  `json:"-"`
	Mtime   int64  `json:"-"`
	// SubtitleStreams is the probed embedded subtitle streams as JSON, only
	// set when upserting a file. See Store.SubtitleStreams.
	SubtitleStreams string `json:"-"`
	// Chapters are a file's own marked chapters, only set when upserting a
	// file. See Store.Book.
	Chapters []probe.Chapter `json:"-"`

	// Facts are labelled lines a plugin found for an item of a kind it
	// adds, such as Manufacturer: Namco, shown on its page.
	Facts []Fact `json:"facts,omitempty"`
	// PluginData is what a plugin keeps with an item of a kind it adds, as
	// JSON, for the plugin's player.
	PluginData json.RawMessage `json:"pluginData,omitempty"`
	// Details are applied with ApplyMetadata after a scan files the item,
	// when the library kind already knows them (a plugin's kinds can).
	Details *Metadata `json:"-"`
	// contains filtered or unexported fields
}

Item is anything browsable: a playable file or a container of other items.

type ItemFilter

type ItemFilter struct {
	Library []int64 `json:"library,omitempty"` // none: every library
	// Kind limits results to movie, show, artist, album, episode, track,
	// author, book or part. Without it, a library's top level is listed:
	// movies, shows, artists or authors.
	Kind []string `json:"kind,omitempty"`
	Q    string   `json:"q,omitempty"` // words in the title

	Genre    []string `json:"genre,omitempty"`
	NotGenre []string `json:"notGenre,omitempty"`

	YearMin int `json:"yearMin,omitempty"`
	YearMax int `json:"yearMax,omitempty"`
	// Release dates are YYYY-MM-DD; shows use their first air date. Titles
	// without one count as released on January 1st of their year.
	ReleasedAfter  string `json:"releasedAfter,omitempty"`
	ReleasedBefore string `json:"releasedBefore,omitempty"`
	ReleasedWithin int    `json:"releasedWithin,omitempty"` // days

	// When a title was added to the library; a show counts as added when
	// its newest episode was.
	AddedAfter  string `json:"addedAfter,omitempty"`  // YYYY-MM-DD
	AddedBefore string `json:"addedBefore,omitempty"` // YYYY-MM-DD
	AddedWithin int    `json:"addedWithin,omitempty"` // days

	RatingMin float64 `json:"ratingMin,omitempty"` // 0–10
	RatingMax float64 `json:"ratingMax,omitempty"`
	// Runtime in minutes; a show's is its average episode's.
	RuntimeMin int `json:"runtimeMin,omitempty"`
	RuntimeMax int `json:"runtimeMax,omitempty"`

	// Watched is unwatched (something left to play), inProgress (started,
	// not finished), watched (all played), notStarted (none played) or
	// started (any of it played or begun, such as albums listened to), for
	// the person asking.
	Watched string `json:"watched,omitempty"`

	Tag    []string `json:"tag,omitempty"` // media tags, such as 4k or atmos (see Item.MediaTags)
	NotTag []string `json:"notTag,omitempty"`

	Person   []int64 `json:"person,omitempty"`   // TMDB person ids credited in any role
	Director []int64 `json:"director,omitempty"` // directed or created it (or one of its episodes)

	Studio        []string `json:"studio,omitempty"`        // studios, and networks for shows
	Country       []string `json:"country,omitempty"`       // production countries
	Language      []string `json:"language,omitempty"`      // original language, e.g. Japanese
	Certification []string `json:"certification,omitempty"` // e.g. PG-13 or TV-MA
	Collection    []int64  `json:"collection,omitempty"`    // TMDB collection ids

	WatchList bool `json:"watchList,omitempty"` // only titles on the person's watch list

	Series   []string `json:"series,omitempty"`   // books in these series
	Narrator []string `json:"narrator,omitempty"` // books any of these people narrate

	Sort  string `json:"sort,omitempty"`  // see SortFields; title by default
	Order string `json:"order,omitempty"` // asc or desc; each sort has its own default
	Limit int    `json:"limit,omitempty"`
}

ItemFilter picks titles by their metadata. The same filter travels as URL query parameters (?genre=Comedy&yearMin=1980&sort=year) and as JSON, with the same names, so a library page's filter can be saved as it is, such as for a smart collection. Within one field any value matches, except tag and person, where every value must. Fields that are relative to today, such as addedWithin, are worked out each time the filter runs.

func ParseItemFilter

func ParseItemFilter(q url.Values) (ItemFilter, error)

ParseItemFilter reads a filter from URL query parameters. Parameters it doesn't know are left alone; a known one with a bad value is an error.

func (ItemFilter) Validate

func (f ItemFilter) Validate() error

Validate checks the values that must be one of a few, and the dates.

func (ItemFilter) Values

func (f ItemFilter) Values() url.Values

Values is the filter as URL query parameters, the reverse of ParseItemFilter.

type Library

type Library struct {
	ID    int64    `json:"id"`
	Name  string   `json:"name"`
	Kind  string   `json:"kind"` // movies, tv or music
	Paths []string `json:"paths"`
}

type LibraryCount added in v0.1.1

type LibraryCount struct{ Titles, Files int }

LibraryCount is how big a library is: its titles (movies, shows, artists) and its files.

type Metadata

type Metadata struct {
	TMDBID   int64
	MBID     string // MusicBrainz id, for artists and albums
	Title    string // only applied to episodes, whose file names rarely carry one
	Overview string
	Year     int
	Rating   float64
	Poster   string // URL
	Backdrop string // URL
	// Genres of a movie or show; nil when the provider doesn't say.
	Genres []string
	// Facts are labelled lines from a plugin; nil keeps what the item has.
	Facts []Fact
}

Metadata is what an online provider knows about an item.

type Person

type Person struct {
	ID         int64  `json:"id"`
	Name       string `json:"name"`
	HasPhoto   bool   `json:"hasPhoto"`
	Biography  string `json:"biography,omitempty"`
	Birthday   string `json:"birthday,omitempty"` // YYYY-MM-DD
	Deathday   string `json:"deathday,omitempty"`
	Birthplace string `json:"birthplace,omitempty"`
	KnownFor   string `json:"knownFor,omitempty"` // a department, e.g. Acting or Directing

	Photo  string `json:"-"`
	InfoAt int64  `json:"-"` // when the biography was last looked up; 0 if never
}

Person is someone in the cast or crew of titles in the library.

type PersonInfo

type PersonInfo struct {
	Biography, Birthday, Deathday, Birthplace, KnownFor string
	Photo                                               string // URL
}

PersonInfo is a person's biography from a provider.

type PersonTitle

type PersonTitle struct {
	Item  Item     `json:"item"`
	Roles []string `json:"roles"`
}

PersonTitle is a title in the library someone is in, with their parts in it.

type PluginKey added in v0.1.1

type PluginKey struct {
	Key       string `json:"key"`
	Size      int64  `json:"size"`
	UpdatedAt int64  `json:"updatedAt"` // milliseconds
}

PluginKey is one thing a plugin's player keeps for a person, such as a saved game.

type Profile

type Profile struct {
	User
	// Libraries maps library ids to LibraryAll or LibraryRated; only
	// meaningful for kids profiles.
	Libraries map[int64]string `json:"libraries"`
}

Profile is a profile as admins manage it.

type ProfileChanges

type ProfileChanges struct {
	Name      *string
	Avatar    *string
	KidsLevel *int
	// PINHash replaces the PIN; "" removes it.
	PINHash   *string
	Libraries map[int64]string
}

ProfileChanges are what an admin sets on a profile. Nil fields stay as they are.

type ProgressEvent

type ProgressEvent struct {
	ItemID     int64 `json:"itemId"`
	PositionMs int64 `json:"positionMs"`
	Played     bool  `json:"played"`
	At         int64 `json:"at"`
}

ProgressEvent is a change to watch progress that a device made, possibly while offline, at the time At (unix seconds).

type Request

type Request struct {
	ID               string `json:"id"`
	Kind             string `json:"kind"` // movie or show
	TMDBID           int    `json:"tmdbId,omitempty"`
	TVDBID           int    `json:"tvdbId,omitempty"`
	Title            string `json:"title"`
	Year             int    `json:"year,omitempty"`
	Poster           string `json:"poster,omitempty"`
	QualityProfileID int    `json:"qualityProfileId,omitempty"` // 0 uses the admin's default
	State            string `json:"state"`
	Error            string `json:"error,omitempty"`
	UserID           int64  `json:"userId"`
	Username         string `json:"username"`
	CreatedAt        int64  `json:"createdAt"`
	UpdatedAt        int64  `json:"updatedAt"`
}

type SavedCollection

type SavedCollection struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Kind string `json:"kind"` // smart or manual
	// OwnerID is who made it; nil for a shared collection.
	OwnerID *int64 `json:"ownerId,omitempty"`
	Shared  bool   `json:"shared"`
	// Filter picks a smart collection's titles; nil for a manual one.
	Filter *ItemFilter `json:"filter,omitempty"`
	// Sort is one of CollectionSorts, or empty for the collection's own order.
	Sort  string `json:"sort,omitempty"`
	Order string `json:"order,omitempty"` // asc or desc; empty is the sort's natural one
	// PinHome shows the collection as a row on Home, PinLibrary as a row on
	// that library's page.
	PinHome    bool   `json:"pinHome"`
	PinLibrary *int64 `json:"pinLibrary,omitempty"`
	// Starter names a built-in collection, such as "recent".
	Starter   string `json:"starter,omitempty"`
	CreatedAt int64  `json:"createdAt"` // milliseconds
	UpdatedAt int64  `json:"updatedAt"` // milliseconds
}

type Session

type Session struct {
	ID         string `json:"id"`
	DeviceName string `json:"deviceName"`
	Platform   string `json:"platform"`
	CreatedAt  int64  `json:"createdAt"`
	LastSeenAt int64  `json:"lastSeenAt"`
	Current    bool   `json:"current"`
}

Session is a signed-in device as its owner sees it. ID is derived from the token, so the token itself never leaves the device that holds it.

type Store

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

func Open

func Open(dsn string) (*Store, error)

Open connects to the database. A postgres:// URL uses PostgreSQL, which suits Kubernetes and network storage; anything else is a SQLite file path (":memory:" in tests).

func (*Store) AddStarterCollections

func (s *Store) AddStarterCollections(ctx context.Context) error

AddStarterCollections adds the built-in collections the first time it runs.

func (*Store) AddToCollection

func (s *Store) AddToCollection(ctx context.Context, collectionID string, itemID int64) error

AddToCollection puts an item at the end of a manual collection. Adding it again keeps its place.

func (*Store) AddToWatchList

func (s *Store) AddToWatchList(ctx context.Context, userID, itemID int64) error

AddToWatchList saves an item to a user's watch list. Adding it again keeps its place.

func (*Store) AllDownloads

func (s *Store) AllDownloads(ctx context.Context) ([]Download, error)

AllDownloads lists every user's downloads, for admins.

func (*Store) AnalysisCounts

func (s *Store) AnalysisCounts(ctx context.Context, version int) (total, done, unreadable int, err error)

AnalysisCounts says how many files there are, how many are analyzed as they are now by this version, and how many of those couldn't be read.

func (*Store) AnalysisFiles

func (s *Store) AnalysisFiles(ctx context.Context, afterID int64, limit int) ([]AnalysisFile, error)

AnalysisFiles lists files with ids above afterID, in id order, so a pass over the library can stop and pick up where it was.

func (*Store) ApplyDetails

func (s *Store) ApplyDetails(ctx context.Context, id int64, u DetailsUpdate) error

ApplyDetails replaces an item's details, credits and terms.

func (*Store) ApplyEpisodeDetails

func (s *Store) ApplyEpisodeDetails(ctx context.Context, id int64, u DetailsUpdate) error

ApplyEpisodeDetails stores an episode's air date, guest stars and crew, which arrive with its season's.

func (*Store) ApplyMetadata

func (s *Store) ApplyMetadata(ctx context.Context, id int64, m *Metadata) error

ApplyMetadata stores a provider match (nil for no match) without overwriting local artwork or the year from the file name.

func (*Store) BackfillRatingLevels

func (s *Store) BackfillRatingLevels(ctx context.Context, level func(cert string) int) (int, error)

BackfillRatingLevels fills in rating levels for titles whose details were looked up before levels were kept. level turns a certification into one.

func (*Store) Book added in v0.1.2

func (s *Store) Book(ctx context.Context, userID, id int64) (Book, error)

Book returns a book with its parts and chapters, for the given person. A part's id finds its book.

func (*Store) BoxSet

func (s *Store) BoxSet(ctx context.Context, userID, id int64) (BoxSet, error)

BoxSet returns one box set, or ErrNotFound when the library has none of it.

func (*Store) BoxSets

func (s *Store) BoxSets(ctx context.Context, userID int64) ([]BoxSet, error)

BoxSets lists the box sets with two or more titles in the library the user can see, by name.

func (*Store) Children

func (s *Store) Children(ctx context.Context, userID, parentID int64) ([]Item, error)

Children lists seasons of a show, episodes of a season, albums of an artist, tracks of an album, books of an author or parts of a book.

func (*Store) ClearMediaKey

func (s *Store) ClearMediaKey(ctx context.Context, id int64) error

ClearMediaKey has a file analyzed again soon.

func (*Store) Close

func (s *Store) Close() error

func (*Store) Collection

func (s *Store) Collection(ctx context.Context, id string) (SavedCollection, error)

Collection returns one collection, whoever it belongs to.

func (*Store) CollectionItems

func (s *Store) CollectionItems(ctx context.Context, userID, collectionID int64) ([]Item, error)

CollectionItems lists the library's titles in a collection, oldest first.

func (*Store) Collections

func (s *Store) Collections(ctx context.Context, userID int64) ([]SavedCollection, error)

Collections lists the shared collections and the user's own, shared first.

func (*Store) ContinueListening added in v0.1.2

func (s *Store) ContinueListening(ctx context.Context, userID int64, limit int) ([]Item, error)

ContinueListening lists books someone started and didn't finish, the latest first, leaving out the ones they took off the row.

func (*Store) ContinueWatching

func (s *Store) ContinueWatching(ctx context.Context, userID int64, limit int) ([]Item, error)

ContinueWatching lists videos the user started but didn't finish, leaving out the ones they took off the row.

func (*Store) CountUsers

func (s *Store) CountUsers(ctx context.Context) (int, error)

func (*Store) CreateCollection

func (s *Store) CreateCollection(ctx context.Context, c SavedCollection) (SavedCollection, error)

CreateCollection saves a new collection; ID and times are filled in.

func (*Store) CreateHomeSession

func (s *Store) CreateHomeSession(ctx context.Context, guestID, profileID int64, ttl time.Duration, dev Device) (string, error)

CreateHomeSession starts a session for a device at home that picked one of the guest account's profiles. It only works from the home network.

func (*Store) CreateIssue

func (s *Store) CreateIssue(ctx context.Context, x Issue) (Issue, error)

func (*Store) CreateLibrary

func (s *Store) CreateLibrary(ctx context.Context, name, kind string, paths []string) (Library, error)

func (*Store) CreateProfile

func (s *Store) CreateProfile(ctx context.Context, accountID int64, c ProfileChanges) (Profile, error)

CreateProfile adds a profile to an account.

func (*Store) CreateRequest

func (s *Store) CreateRequest(ctx context.Context, r Request) (Request, error)

CreateRequest saves a new request, pending.

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, userID int64, ttl time.Duration, dev Device) (string, error)

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, username, passwordHash string, admin bool) (User, error)

func (*Store) DecideDeviceCode

func (s *Store) DecideDeviceCode(ctx context.Context, userCode string, userID int64, approve bool) error

DecideDeviceCode approves a code for a user, or declines it.

func (*Store) DeleteCollection

func (s *Store) DeleteCollection(ctx context.Context, id string) error

func (*Store) DeleteDownload

func (s *Store) DeleteDownload(ctx context.Context, userID int64, id string) (Download, error)

DeleteDownload removes a download and returns it, so its file can be cleaned up if nothing else uses it. Admins (userID 0) can remove anyone's.

func (*Store) DeleteLibrary

func (s *Store) DeleteLibrary(ctx context.Context, id int64) error

func (*Store) DeleteOtherSessions

func (s *Store) DeleteOtherSessions(ctx context.Context, userID int64, keep string) error

DeleteOtherSessions signs a user out everywhere but the session keep ("" signs them out everywhere). Those devices' downloads go with them.

func (*Store) DeletePluginStorage added in v0.1.1

func (s *Store) DeletePluginStorage(ctx context.Context, pluginID string) error

DeletePluginStorage forgets everything a plugin kept, when it's removed.

func (*Store) DeletePluginValue added in v0.1.1

func (s *Store) DeletePluginValue(ctx context.Context, pluginID string, userID int64, key string) error

DeletePluginValue forgets one key.

func (*Store) DeleteProfile

func (s *Store) DeleteProfile(ctx context.Context, id int64) error

DeleteProfile removes a profile with its progress and watch list.

func (*Store) DeleteRequest

func (s *Store) DeleteRequest(ctx context.Context, id string) error

func (*Store) DeleteSession

func (s *Store) DeleteSession(ctx context.Context, token string) error

DeleteSession signs a device out. Its downloads go with it.

func (*Store) DeleteSessionByID

func (s *Store) DeleteSessionByID(ctx context.Context, userID int64, id string) error

DeleteSessionByID signs one of a user's devices out.

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, userID int64) error

DeleteUser removes an account and everything that belongs to it: sessions, watch history, watch list, downloads, requests and settings. The last admin can't be removed.

func (*Store) DownloadFailed

func (s *Store) DownloadFailed(ctx context.Context, file, msg string, maxAttempts int) error

DownloadFailed records a failed attempt for every download being prepared from file. Until maxAttempts it queues them again after a growing wait.

func (*Store) DownloadFiles

func (s *Store) DownloadFiles(ctx context.Context) (map[string]bool, error)

DownloadFiles lists every prepared file a download refers to.

func (*Store) DownloadPrepared

func (s *Store) DownloadPrepared(ctx context.Context, file string, size int64, sha256, md5 string, sourceMtime int64) error

DownloadPrepared marks every download being prepared from file as ready. For an original, sourceMtime is the mtime the checksum is for (0 otherwise).

func (*Store) Downloads

func (s *Store) Downloads(ctx context.Context, userID int64, deviceID string) ([]Download, error)

Downloads lists a user's downloads, for one device or (deviceID "") all of them.

func (*Store) EnsureContainer

func (s *Store) EnsureContainer(ctx context.Context, libraryID int64, parentID *int64, kind, title string, index, year *int) (int64, error)

EnsureContainer finds or creates a show, season, artist or album and returns its id.

func (*Store) ExpireFinishedDownloads

func (s *Store) ExpireFinishedDownloads(ctx context.Context, age time.Duration) ([]string, error)

ExpireFinishedDownloads finds converted files that every device using them has had for longer than age, and marks those downloads expired so the files can be deleted. Originals are never deleted, so they're left alone.

func (*Store) FileInUse

func (s *Store) FileInUse(ctx context.Context, file string) (bool, error)

FileInUse says whether any download still needs a prepared file.

func (*Store) FileStat

func (s *Store) FileStat(ctx context.Context, path string) (id, size, mtime int64, err error)

FileStat returns the stored size and mtime for a file path, or ErrNotFound.

func (*Store) FileUnder

func (s *Store) FileUnder(ctx context.Context, id int64) (string, error)

FileUnder returns the path of one file under a show or season, so callers can find the folder it lives in. It returns "" when there's none.

func (*Store) FilterItems

func (s *Store) FilterItems(ctx context.Context, userID int64, f ItemFilter) ([]Item, error)

FilterItems lists the titles the filter picks, for the given person.

func (*Store) FilterOptions

func (s *Store) FilterOptions(ctx context.Context, libraryID int64) (FilterOptions, error)

FilterOptions lists what a library's top level can be filtered by.

func (*Store) FilterPeople

func (s *Store) FilterPeople(ctx context.Context, libraryID int64, role, q string, limit int) ([]FilterPerson, error)

FilterPeople lists people credited in a library's titles (or their episodes), in the most titles first. role is cast, director or empty for any; q, when given, matches the start of any word of their name.

func (*Store) FinishDownload

func (s *Store) FinishDownload(ctx context.Context, userID int64, id string) error

FinishDownload records that the device has the whole file and checked it.

func (*Store) GenreCounts

func (s *Store) GenreCounts(ctx context.Context, userID int64) (map[string]int, error)

GenreCounts says how many movies and shows the user can see in each genre.

func (*Store) HideFromContinueWatching

func (s *Store) HideFromContinueWatching(ctx context.Context, userID, itemID int64) error

HideFromContinueWatching takes an item off the user's Continue Watching row. Its place is kept, so its page still offers to resume, and playing it again brings it back.

func (*Store) HolidayItems added in v0.1.1

func (s *Store) HolidayItems(ctx context.Context, userID int64, m HolidayMatch, limit int) ([]Item, error)

HolidayItems lists the movies and shows the user can see that match, best rated first.

func (*Store) HomeGuest

func (s *Store) HomeGuest(ctx context.Context) (User, error)

HomeGuest is the account devices on the home network use when they haven't signed in, created the first time one does. Everyone at home shares it, so they share its watch progress and watch list too. It can't sign in, isn't listed with the other accounts, and isn't an admin.

func (*Store) InGenre

func (s *Store) InGenre(ctx context.Context, userID int64, genre string, limit int) ([]Item, error)

InGenre lists movies and shows in a genre, best rated first.

func (*Store) InGenreExcept added in v0.1.1

func (s *Store) InGenreExcept(ctx context.Context, userID int64, genre string, m HolidayMatch, limit int) ([]Item, error)

InGenreExcept lists movies and shows in a genre that don't match m, best rated first, to fill out a holiday's row.

func (*Store) Issue

func (s *Store) Issue(ctx context.Context, id string) (Issue, error)

func (*Store) Issues

func (s *Store) Issues(ctx context.Context, userID int64, limit int) ([]Issue, error)

Issues lists reported problems, open ones first, then the newest. userID 0 lists everyone's.

func (*Store) Item

func (s *Store) Item(ctx context.Context, userID, id int64) (Item, error)

Item returns one item with the user's progress, or ErrNotFound when it's not for them (see visibleToMe). User 0 sees everything.

func (*Store) ItemCollections

func (s *Store) ItemCollections(ctx context.Context, itemID int64) ([]string, error)

ItemCollections lists the IDs of the manual collections holding an item.

func (*Store) ItemCredits

func (s *Store) ItemCredits(ctx context.Context, id int64) (Credits, error)

ItemCredits returns an item's cast, guest stars and crew in billing order.

func (*Store) ItemDetails

func (s *Store) ItemDetails(ctx context.Context, id int64) (*Details, error)

ItemDetails returns what ApplyDetails stored for an item, or nil.

func (*Store) Libraries

func (s *Store) Libraries(ctx context.Context) ([]Library, error)

func (*Store) Library

func (s *Store) Library(ctx context.Context, id int64) (Library, error)

func (*Store) LibraryCounts added in v0.1.1

func (s *Store) LibraryCounts(ctx context.Context) (map[int64]LibraryCount, error)

LibraryCounts counts every library's titles and files.

func (*Store) LibraryMatch

func (s *Store) LibraryMatch(ctx context.Context, kind string, tmdbID int, title string, year int) (int64, error)

LibraryMatch finds a movie or show in the libraries, by TMDB id or, for items looked up without TMDB, by title and year. It returns 0 when there's none.

func (*Store) LibraryVisible

func (s *Store) LibraryVisible(ctx context.Context, u User, libraryID int64) (bool, error)

LibraryVisible reports whether a user may see a library at all.

func (*Store) ManualItems

func (s *Store) ManualItems(ctx context.Context, userID int64, collectionID string) ([]Item, error)

ManualItems lists a manual collection's titles in the order they were added.

func (*Store) MarkDetails

func (s *Store) MarkDetails(ctx context.Context, id int64) error

MarkDetails records that an item's details were looked up and nothing was found, so it isn't asked for again until the next refresh.

func (*Store) MediaInfo

func (s *Store) MediaInfo(ctx context.Context, id int64, version int) (info string, current, ok bool, err error)

MediaInfo returns a file's analysis as JSON, and whether it still matches the file. ok is false when it was never analyzed.

func (*Store) MergeProgress

func (s *Store) MergeProgress(ctx context.Context, userID int64, e ProgressEvent) (bool, error)

MergeProgress applies a change unless the item's progress changed more recently, so watching on another device in the meantime isn't undone. It reports whether the change was applied.

func (*Store) MetadataLanguages added in v0.1.1

func (s *Store) MetadataLanguages(ctx context.Context) ([]string, error)

MetadataLanguages lists the languages besides English that people use: picked by a profile or asked for by a device.

func (*Store) Narrators added in v0.1.2

func (s *Store) Narrators(ctx context.Context, userID, libraryID int64) ([]BookGroup, error)

Narrators lists everyone who narrates a book of the library, by name.

func (*Store) NeedsDetails

func (s *Store) NeedsDetails(ctx context.Context, libraryID, olderThan int64) ([]Item, error)

NeedsDetails lists a library's matched movies, shows and seasons whose details were never fetched or were fetched before olderThan (Unix seconds).

func (*Store) NeedsGenres

func (s *Store) NeedsGenres(ctx context.Context, libraryID int64) ([]Item, error)

NeedsGenres lists a library's matched movies and shows whose genres weren't looked up, such as ones matched before Matinee kept genres.

func (*Store) NeedsMetadata

func (s *Store) NeedsMetadata(ctx context.Context, libraryID int64, kinds []string) ([]Item, error)

NeedsMetadata lists a library's items of the given kinds not yet looked up online, shows before seasons and episodes so those can use the show's match.

func (*Store) NeedsSeasonTranslations added in v0.1.1

func (s *Store) NeedsSeasonTranslations(ctx context.Context, libraryID int64, lang string) ([]Item, error)

NeedsSeasonTranslations lists a library's seasons of matched shows that, or one of whose episodes, have no row in a language yet. Seasons are looked up one language at a time, with their episodes, so only in the languages people use.

func (*Store) NeedsTranslations added in v0.1.1

func (s *Store) NeedsTranslations(ctx context.Context, libraryID, olderThan int64) ([]Item, error)

NeedsTranslations lists a library's matched movies and shows whose translations were never fetched or were fetched before olderThan (Unix seconds).

func (*Store) NewReleases

func (s *Store) NewReleases(ctx context.Context, userID int64, sinceYear, limit int) ([]Item, error)

NewReleases lists movies and shows from the given year on, newest first.

func (*Store) NextDownload

func (s *Store) NextDownload(ctx context.Context) (Download, error)

NextDownload claims the oldest queued download whose retry time has come, marking it and every other download of the same file as preparing.

func (*Store) NextEpisode

func (s *Store) NextEpisode(ctx context.Context, userID int64, ep Item) (Item, error)

NextEpisode is the episode after the given one: the next in its season, else the first of the following season. Specials (season 0) only lead to other specials, and regular seasons never lead into specials. It returns ErrNotFound after a show's last episode, or for anything that isn't an episode. Only episodes the user may see count (see visibleToMe). An audiobook's part leads to the book's next part, for players that play a book a part at a time.

func (*Store) NoteLanguageSeen added in v0.1.1

func (s *Store) NoteLanguageSeen(ctx context.Context, lang string) (bool, error)

NoteLanguageSeen records that a device asked for a language, and reports whether it was new.

func (*Store) OpenRequest

func (s *Store) OpenRequest(ctx context.Context, kind string, id int) (Request, error)

OpenRequest finds a pending or approved request for a title, by TMDB id for movies or TVDB id for shows, so it isn't asked for twice.

func (*Store) PendingDeviceCode

func (s *Store) PendingDeviceCode(ctx context.Context, userCode string) (DeviceCode, error)

PendingDeviceCode looks up a code someone typed, for the "sign in this device?" screen.

func (*Store) Person

func (s *Store) Person(ctx context.Context, id int64) (Person, error)

func (*Store) PersonTitles

func (s *Store) PersonTitles(ctx context.Context, userID, personID int64) ([]PersonTitle, error)

PersonTitles lists the movies and shows in the library a person is in, newest first. Parts in single episodes count toward their show.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks the database is reachable, for readiness probes.

func (*Store) PluginKeys added in v0.1.1

func (s *Store) PluginKeys(ctx context.Context, pluginID string, userID int64, prefix string) (keys []PluginKey, total int64, err error)

PluginKeys lists a user's keys that start with prefix, newest first, and how much the plugin keeps for them in all.

func (*Store) PluginValue added in v0.1.1

func (s *Store) PluginValue(ctx context.Context, pluginID string, userID int64, key string) ([]byte, error)

PluginValue returns what a plugin keeps under key for a user.

func (*Store) Profile

func (s *Store) Profile(ctx context.Context, id int64) (Profile, error)

Profile returns one profile.

func (*Store) Profiles

func (s *Store) Profiles(ctx context.Context, accountID int64) ([]Profile, error)

Profiles lists an account's profiles, in the order they were made.

func (*Store) PutDownload

func (s *Store) PutDownload(ctx context.Context, d Download) (Download, error)

PutDownload asks for an item on a device. A device has at most one download per item, so asking again is safe: the same request returns the existing download (and retries it if it failed or expired), and a different quality replaces it.

func (*Store) RecentlyAdded

func (s *Store) RecentlyAdded(ctx context.Context, userID int64, limit int) ([]Item, error)

RecentlyAdded lists the newest movies, albums, books and shows. A show counts as new when an episode is, so a fresh season doesn't fill the row with episodes.

func (*Store) RecentlyWatched added in v0.1.1

func (s *Store) RecentlyWatched(ctx context.Context, userID int64, limit int) ([]Watched, error)

RecentlyWatched lists the movies and shows with a TMDB id that the user played lately, newest first. Watching an episode counts for its show.

func (*Store) RedeemDeviceCode

func (s *Store) RedeemDeviceCode(ctx context.Context, deviceCode string) (int64, Device, error)

RedeemDeviceCode is the device's poll. Once the code is approved it returns the user and device, exactly once; the caller starts the session. Otherwise it returns ErrCodePending, ErrCodeDenied or ErrCodeExpired.

func (*Store) Related

func (s *Store) Related(ctx context.Context, userID int64, it Item) ([]Item, error)

Related lists titles in the library like the given movie or show, best first: ones TMDB recommends, ones by the same director or creator, with the same leads, keywords and genres. Members of its collection are left out; see CollectionItems.

func (*Store) RelatedN added in v0.1.1

func (s *Store) RelatedN(ctx context.Context, userID int64, it Item, limit int) ([]Item, error)

RelatedN is Related with up to limit titles.

func (*Store) RemoveFromCollection

func (s *Store) RemoveFromCollection(ctx context.Context, collectionID string, itemID int64) error

func (*Store) RemoveFromWatchList

func (s *Store) RemoveFromWatchList(ctx context.Context, userID, itemID int64) error

func (*Store) RemoveMissing

func (s *Store) RemoveMissing(ctx context.Context, libraryID int64, seen func(path string) bool) (int, error)

RemoveMissing deletes a library's files that the last scan didn't see, then any containers left empty.

func (*Store) Request

func (s *Store) Request(ctx context.Context, id string) (Request, error)

func (*Store) Requests

func (s *Store) Requests(ctx context.Context, userID int64, limit int) ([]Request, error)

Requests lists requests, pending ones first, then the newest. userID 0 lists everyone's.

func (*Store) RequeueDownload

func (s *Store) RequeueDownload(ctx context.Context, d Download) error

RequeueDownload prepares a ready download again, as when its file went missing or changed.

func (*Store) RequeueInterrupted

func (s *Store) RequeueInterrupted(ctx context.Context) error

RequeueInterrupted puts downloads that were being prepared when the server stopped back in the queue.

func (*Store) ResolveIssue

func (s *Store) ResolveIssue(ctx context.Context, id, resolution string) error

func (*Store) Search

func (s *Store) Search(ctx context.Context, userID int64, q string, limit int) ([]Item, error)

Search matches titles by word prefix, e.g. "star wa" finds "Star Wars".

func (*Store) Series added in v0.1.2

func (s *Store) Series(ctx context.Context, userID, libraryID int64) ([]BookGroup, error)

Series lists a library's series by name.

func (*Store) SessionDeviceName added in v0.1.1

func (s *Store) SessionDeviceName(ctx context.Context, token string) (string, error)

SessionDeviceName is the name of the device a session token belongs to.

func (*Store) SessionUser

func (s *Store) SessionUser(ctx context.Context, token string) (u User, homeOnly bool, err error)

SessionUser returns who a session watches as: the profile it picked, or else its account. homeOnly is true for sessions that only work at home.

func (*Store) Sessions

func (s *Store) Sessions(ctx context.Context, userID int64, current string) ([]Session, error)

Sessions lists a user's signed-in devices, most recently used first. current is the token of the request asking, which is marked.

func (*Store) SetAdmin

func (s *Store) SetAdmin(ctx context.Context, userID int64, admin bool) error

SetAdmin makes an account an admin or not. The last admin stays one.

func (*Store) SetArt

func (s *Store) SetArt(ctx context.Context, id int64, poster, backdrop string) error

SetArt records artwork found on disk. Local art wins over anything fetched online, since a file next to the media is the user's own choice.

func (*Store) SetBookInfo added in v0.1.2

func (s *Store) SetBookInfo(ctx context.Context, id int64, b BookInfo) error

SetBookInfo records what a book's files say about it. What a file leaves out keeps what the book had.

func (*Store) SetBookProgress added in v0.1.2

func (s *Store) SetBookProgress(ctx context.Context, userID, bookID, positionMs int64, played bool) error

SetBookProgress saves where someone is in a book. Its parts count as played when the book is finished, and as not played again when it isn't, so filters such as unwatched treat books like albums.

func (*Store) SetDownloadProgress

func (s *Store) SetDownloadProgress(ctx context.Context, file string, permille int) error

SetDownloadProgress updates every download being prepared from file.

func (*Store) SetGenres

func (s *Store) SetGenres(ctx context.Context, id int64, genres []string) error

SetGenres records a movie's or show's genres (none is an empty list).

func (*Store) SetMediaInfo

func (s *Store) SetMediaInfo(ctx context.Context, id int64, size, mtime int64, info string, tags []string, key string) (bool, error)

SetMediaInfo stores a file's analysis, unless the file changed since it was looked at (the scanner got there first), in which case it reports false.

func (*Store) SetMetadataKinds

func (s *Store) SetMetadataKinds(kinds ...string)

SetMetadataKinds says which item kinds an online provider looks up, so those items can show as pending until their lookup is done.

func (*Store) SetPassword

func (s *Store) SetPassword(ctx context.Context, userID int64, passwordHash string) error

func (*Store) SetPersonInfo

func (s *Store) SetPersonInfo(ctx context.Context, id int64, in PersonInfo) error

func (*Store) SetPluginValue added in v0.1.1

func (s *Store) SetPluginValue(ctx context.Context, pluginID string, userID int64, key string, value []byte) error

SetPluginValue keeps value under key for a user.

func (*Store) SetProgress

func (s *Store) SetProgress(ctx context.Context, userID, itemID, positionMs int64, played bool) error

SetProgress saves where the user is in an item. Any progress brings an item back to Continue Watching.

func (*Store) SetSeasonTranslations added in v0.1.1

func (s *Store) SetSeasonTranslations(ctx context.Context, seasonID int64, lang string, season Translation, episodes map[int64]Translation) error

SetSeasonTranslations keeps a season's and its episodes' text in one language. Each gets a row even without a translation, so it isn't looked up again.

func (*Store) SetSessionProfile

func (s *Store) SetSessionProfile(ctx context.Context, token string, profileID int64) error

SetSessionProfile switches the profile a session watches as; 0 goes back to the account itself.

func (*Store) SetSetting

func (s *Store) SetSetting(ctx context.Context, key, value string) error

func (*Store) SetSubtitleStreams

func (s *Store) SetSubtitleStreams(ctx context.Context, id int64, streams string) error

SetSubtitleStreams records a file's embedded subtitle streams as JSON.

func (*Store) SetTranslations added in v0.1.1

func (s *Store) SetTranslations(ctx context.Context, id int64, tr map[string]Translation) error

SetTranslations replaces a movie's or show's translations, by language.

func (*Store) SetUserLanguage added in v0.1.1

func (s *Store) SetUserLanguage(ctx context.Context, userID int64, lang string) error

SetUserLanguage keeps the language a profile picked; "" follows the device.

func (*Store) Setting

func (s *Store) Setting(ctx context.Context, key string) (string, error)

Setting returns a server-wide setting, or "" when it was never set.

func (*Store) Similar

func (s *Store) Similar(ctx context.Context, userID int64, show Item) (Item, error)

Similar picks a title to suggest after a show's last episode: the most related show the user hasn't finished, else the most related title.

func (*Store) StartDeviceCode

func (s *Store) StartDeviceCode(ctx context.Context, dev Device, ttl time.Duration) (DeviceCode, error)

StartDeviceCode makes a code for a device to show.

func (*Store) SubtitleStreams

func (s *Store) SubtitleStreams(ctx context.Context, id int64) (streams string, ok bool, err error)

SubtitleStreams returns a file's embedded subtitle streams as stored by the scanner, as JSON. ok is false for files scanned before Matinee looked for them.

func (*Store) SumBookLengths added in v0.1.2

func (s *Store) SumBookLengths(ctx context.Context, libraryID int64) error

SumBookLengths gives each book of a library the length of all its parts.

func (*Store) TopLevel

func (s *Store) TopLevel(ctx context.Context, userID, libraryID int64) ([]Item, error)

TopLevel lists a library's root items: movies, shows or artists.

func (*Store) Tracks added in v0.1.1

func (s *Store) Tracks(ctx context.Context, userID, id int64) ([]Item, error)

Tracks lists every track under an artist or album, in order: albums oldest first, then by disc and track. For a track, it's its album's.

func (*Store) TranslatedTagline added in v0.1.1

func (s *Store) TranslatedTagline(ctx context.Context, id int64) (string, error)

TranslatedTagline returns an item's tagline in the context's language, or "" when it has none.

func (*Store) UpdateCollection

func (s *Store) UpdateCollection(ctx context.Context, c SavedCollection) (SavedCollection, error)

UpdateCollection saves a collection's name, filter, order and pins. Its kind and owner stay as they are.

func (*Store) UpdateProfile

func (s *Store) UpdateProfile(ctx context.Context, id int64, c ProfileChanges) error

UpdateProfile changes a profile, or the PIN and avatar of an account.

func (*Store) UpdateRequest

func (s *Store) UpdateRequest(ctx context.Context, id, state, errMsg string, qualityProfileID int) error

UpdateRequest records a decision on a request.

func (*Store) UpsertFile

func (s *Store) UpsertFile(ctx context.Context, it Item) (int64, error)

UpsertFile inserts or updates a playable item keyed by its path. The scanner only calls it for new or changed files, so an update drops what the background analysis knew about the old file.

func (*Store) UserByID

func (s *Store) UserByID(ctx context.Context, id int64) (User, error)

UserByID returns an account people sign in to: not the guest account, and not a profile.

func (*Store) UserByName

func (s *Store) UserByName(ctx context.Context, username string) (User, error)

func (*Store) UserDownload

func (s *Store) UserDownload(ctx context.Context, userID int64, id string) (Download, error)

UserDownload finds one of a user's downloads.

func (*Store) UserLanguage added in v0.1.1

func (s *Store) UserLanguage(ctx context.Context, userID int64) (string, error)

UserLanguage returns the language a profile picked, or "" to follow the device.

func (*Store) Users

func (s *Store) Users(ctx context.Context) ([]User, error)

Users lists the accounts people sign in with, leaving out the home network's guest account and profiles.

func (*Store) Viewer

func (s *Store) Viewer(ctx context.Context, id int64) (User, error)

Viewer returns anyone who can watch: an account, the guest account or a profile.

func (*Store) Waiting

func (s *Store) Waiting(ctx context.Context) (requests, issues int, err error)

Waiting counts pending requests and open issues, for admins' badge.

func (*Store) WatchList

func (s *Store) WatchList(ctx context.Context, userID int64, limit int) ([]Item, error)

WatchList lists the items a user saved to watch later, newest first.

type Term

type Term struct {
	Kind string // genre, keyword, collection or rec
	Term string
}

Term is something titles have in common, for finding related titles: a genre, keyword, collection or recommendation.

type Translation added in v0.1.1

type Translation struct {
	Title    string
	Overview string
	Tagline  string
}

Translation is an item's text in one language. Empty fields have no translation.

type User

type User struct {
	ID       int64  `json:"id"`
	Username string `json:"username"` // a profile's name, for profiles
	IsAdmin  bool   `json:"isAdmin"`
	// Guest is the home network's shared account (see HomeGuest), or one of its profiles.
	Guest bool `json:"guest,omitempty"`
	// AccountID is the account a profile belongs to; 0 for accounts.
	AccountID int64 `json:"accountId,omitempty"`
	// KidsLevel limits a kids profile to titles rated up to it (see the
	// rating package); 0 for everyone else.
	KidsLevel int    `json:"kidsLevel,omitempty"`
	Avatar    string `json:"avatar,omitempty"` // a colour name the apps know, such as coral
	HasPIN    bool   `json:"hasPin,omitempty"`
	// contains filtered or unexported fields
}

func (User) Account

func (u User) Account() int64

Account is the id of the account a user is, or belongs to as a profile.

func (User) PINHash

func (u User) PINHash() string

func (User) PasswordHash

func (u User) PasswordHash() string

type Watched added in v0.1.1

type Watched struct {
	ItemID int64
	Kind   string // movie or show
	Title  string
	TMDBID int
}

Watched is a movie or show someone played lately, for recommendations.

Directories

Path Synopsis
Package storetest opens a throwaway database for tests: in-memory SQLite by default, or a fresh PostgreSQL database when MATINEE_TEST_DATABASE_URL is set.
Package storetest opens a throwaway database for tests: in-memory SQLite by default, or a fresh PostgreSQL database when MATINEE_TEST_DATABASE_URL is set.

Jump to

Keyboard shortcuts

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