Documentation ¶
Overview ¶
Package db handles database queries for the metadata server
Index ¶
- Constants
- func AddLibrary(lib *Library) error
- func CollectMovieInfo(movie *Movie)
- func CreateEpisode(episode *Episode)
- func CreateSeries(series *Series)
- func CreateStream(stream *Stream)
- func DeleteEpisode(episodeID uint) error
- func DeleteLibraryByID(libraryID uint) error
- func DeleteMovieByID(movieID uint) error
- func DeletePlayState(mediaUUID string, userID uint) error
- func DeleteSeason(seasonID uint) error
- func DeleteSeries(seriesID uint) error
- func EpisodeFileExists(filePath string) bool
- func GetEpisodeCount() (int32, error)
- func GetMovieCount() (int32, error)
- func GetSeasonCount() (int32, error)
- func GetSeriesCount() (int32, error)
- func ItemsWithMissingMetadata() []string
- func MovieFileExists(filePath string) bool
- func NewDb(options DatabaseOptions) *gorm.DB
- func NewInMemoryDBForTests(logMode bool)
- func SaveEpisode(episode *Episode) error
- func SaveEpisodeFile(episodeFile *EpisodeFile) error
- func SaveLibrary(lib *Library)
- func SaveMovie(movie *Movie) error
- func SaveMovieFile(movieFile *MovieFile)
- func SavePlayState(playState *PlayState) error
- func SaveSeason(season *Season) error
- func SaveSeries(series *Series) error
- func UnwatchedEpisodesInSeasonCount(seasonID uint, userID uint) uint
- func UnwatchedEpisodesInSeriesCount(seriesID uint, userID uint) uint
- func UpdateAllStreams()
- func UpdateStreams(mediaUUID string) bool
- func UserCount() int
- type BackendType
- type BaseItem
- type CommonModelFields
- type DatabaseOptions
- type Episode
- func FindAllEpisodes() ([]*Episode, error)
- func FindEpisodeByID(id uint) (*Episode, error)
- func FindEpisodeByNumber(season *Season, episodeNum int) (*Episode, error)
- func FindEpisodeByUUID(uuid string) (*Episode, error)
- func FindEpisodesForSeason(seasonID uint) (episodes []Episode)
- func FindEpisodesInLibrary(libraryID uint) (episodes []Episode)
- func GetNextEpisodes(episodeUuid string, limit int32) ([]Episode, error)
- func GetPreviousEpisodes(episodeUuid string, limit int32) ([]Episode, error)
- func RecentlyAddedEpisodes(userID uint) (eps []*Episode)
- func UpNextEpisodes(userID uint) []*Episode
- type EpisodeFile
- func FindAllEpisodeFiles() (files []EpisodeFile)
- func FindAllUnidentifiedEpisodeFiles(qd *QueryDetails) ([]EpisodeFile, error)
- func FindAllUnidentifiedEpisodeFilesInLibrary(libraryID uint) ([]*EpisodeFile, error)
- func FindEpisodeFileByPath(filePath filesystem.Node) (*EpisodeFile, error)
- func FindEpisodeFileByUUID(uuid string) (*EpisodeFile, error)
- func FindEpisodeFilesInLibrary(libraryID uint) ([]EpisodeFile, error)
- func FindEpisodeFilesInLibraryByLocator(libraryID uint, locator filesystem.FileLocator) (episodes []EpisodeFile)
- type Invite
- type Library
- type MediaFile
- type MediaItem
- type MediaType
- type Movie
- func FindAllMovies(qd *QueryDetails) (movies []Movie)
- func FindMovieByID(id uint) (*Movie, error)
- func FindMovieByTmdbID(tmdbID int) (*Movie, error)
- func FindMovieByUUID(uuid string) (*Movie, error)
- func FindMovieForMovieFile(movieFile *MovieFile) (*Movie, error)
- func FindMoviesForMDRefresh() (movies []Movie)
- func FindMoviesInLibrary(libraryID uint) (movies []Movie)
- func FirstMovie() Movie
- func RecentlyAddedMovies(userID uint) (movies []*Movie)
- func SearchMovieByTitle(name string) (movies []Movie)
- func UpNextMovies(userID uint) (movies []*Movie)
- type MovieFile
- func FindAllMovieFiles() (movies []MovieFile)
- func FindAllUnidentifiedMovieFiles(qd QueryDetails) ([]MovieFile, error)
- func FindAllUnidentifiedMovieFilesInLibrary(libraryID uint) ([]*MovieFile, error)
- func FindFilesForMovieUUID(uuid string) (movieFiles []*MovieFile)
- func FindMovieFileByPath(filePath filesystem.Node) (*MovieFile, error)
- func FindMovieFileByUUID(uuid string) (*MovieFile, error)
- func FindMovieFilesByMovieID(movieID uint) ([]*MovieFile, error)
- func FindMovieFilesInLibrary(libraryID uint) ([]MovieFile, error)
- func FindMovieFilesInLibraryByLocator(libraryID uint, locator filesystem.FileLocator) (movies []MovieFile)
- type PlayState
- type QueryDetails
- type Season
- type Series
- func FindAllSeries(qd *QueryDetails) ([]*Series, error)
- func FindSeries(seriesID uint) (*Series, error)
- func FindSeriesByTmdbID(tmdbID int) (*Series, error)
- func FindSeriesByUUID(uuid string) (*Series, error)
- func FindSeriesForMDRefresh() (series []Series)
- func FindSeriesInLibrary(libraryID uint) (series []Series)
- func SearchSeriesByTitle(name string) (series []Series)
- type Stream
- type StreamKey
- type UUIDable
- type User
- func AllUsers() (users []User)
- func CreateUser(username string, password string, admin bool) (User, error)
- func CreateUserWithCode(username string, password string, code string) (User, error)
- func DeleteUser(id uint) (User, error)
- func FindUser(id uint) (*User, error)
- func FindUserByUsername(username string) (*User, error)
Constants ¶
const ( SQLite = "sqlite3" MySQL = "mysql" PostgresSQL = "postgres" CockroachDB = "cockroachdb" )
const ( // BackendLocal is used for local libraries BackendLocal = iota // BackendRclone is used for Rclone remotes BackendRclone )
const ( MediaTypeMovie = iota MediaTypeSeries MediaTypeOtherMovie )
Defines various mediatypes, only Movie and Series support atm.
const InMemory = "sqlite3://:memory:"
Variables ¶
This section is empty.
Functions ¶
func AddLibrary ¶
AddLibrary adds a filesystem folder and starts tracking media inside the folders.
func CollectMovieInfo ¶
func CollectMovieInfo(movie *Movie)
CollectMovieInfo ensures that all relevant information for a movie is loaded this can include stream information (audio/video/subtitle tracks) and personalized playstate information.
func CreateEpisode ¶ added in v0.3.0
func CreateEpisode(episode *Episode)
CreateEpisode writes an episode to the db.
func CreateSeries ¶
func CreateSeries(series *Series)
CreateSeries persists a series in the database.
func CreateStream ¶
func CreateStream(stream *Stream)
CreateStream persists a stream object in the database.
func DeleteEpisode ¶ added in v0.3.0
DeleteEpisode deletes an Episode
func DeleteLibraryByID ¶ added in v0.3.3
DeleteLibrary deletes a library from the database.
func DeleteMovieByID ¶ added in v0.3.3
DeleteMovieByID deletes the movie from the database
func DeletePlayState ¶ added in v0.3.0
func DeleteSeason ¶ added in v0.3.0
DeleteSeason deletes a Season
func DeleteSeries ¶ added in v0.3.0
DeleteSeries deletes a Series
func EpisodeFileExists ¶
EpisodeFileExists checks whether there already is a EpisodeFile present with the given path.
func GetEpisodeCount ¶ added in v0.4.0
GetEpisodeCount returns the number of episodes in the database
func GetMovieCount ¶ added in v0.4.0
GetMovieCount returns the number of movies in the database
func GetSeasonCount ¶ added in v0.4.0
GetSeasonCount returns the number of seasons in the database
func GetSeriesCount ¶ added in v0.4.0
GetSeriesCount returns the number of series in the database
func ItemsWithMissingMetadata ¶
func ItemsWithMissingMetadata() []string
ItemsWithMissingMetadata fetches series with missing metadata.
func MovieFileExists ¶
MovieFileExists checks whether there already is a EpisodeFile present with the given path.
func NewDb ¶
func NewDb(options DatabaseOptions) *gorm.DB
NewDb initializes a new database instance.
func NewInMemoryDBForTests ¶ added in v0.3.3
func NewInMemoryDBForTests(logMode bool)
func SaveEpisode ¶ added in v0.3.0
SaveEpisode updates an episode in the database.
func SaveEpisodeFile ¶ added in v0.3.0
func SaveEpisodeFile(episodeFile *EpisodeFile) error
SaveEpisodeFile updates an episodeFile in the database.
func SaveLibrary ¶ added in v0.3.0
func SaveLibrary(lib *Library)
SaveLibrary persists a library object in the database.
func SaveMovieFile ¶ added in v0.3.0
func SaveMovieFile(movieFile *MovieFile)
SaveMovieFile saves a MovieFile
func SavePlayState ¶ added in v0.3.0
func SaveSeason ¶ added in v0.3.0
SaveSeason updates a season in the database.
func SaveSeries ¶ added in v0.3.0
SaveSeries updates a series in the database.
func UnwatchedEpisodesInSeasonCount ¶
UnwatchedEpisodesInSeasonCount retrieves the amount of unwatched episodes in a given season.
func UnwatchedEpisodesInSeriesCount ¶
UnwatchedEpisodesInSeriesCount retrieves the amount of unwatched episodes in a given series.
func UpdateAllStreams ¶
func UpdateAllStreams()
UpdateAllStreams updates all streams for all mediaItems
func UpdateStreams ¶
UpdateStreams deletes stream information and rescans the file
Types ¶
type BackendType ¶ added in v0.2.0
type BackendType int
BackendType specifies what kind of Library backend is being used.
type CommonModelFields ¶
type CommonModelFields struct { ID uint `gorm:"primary_key" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at"` }
CommonModelFields is a list of all fields that should be present on all models.
type DatabaseOptions ¶ added in v0.3.3
DatabaseOptions holds information about how the database instance should be initialized
type Episode ¶
type Episode struct { gorm.Model BaseItem Name string SeasonNum int EpisodeNum int SeasonID uint AirDate string StillPath string Season *Season EpisodeFiles []EpisodeFile }
Episode holds metadata information about episodes.
func FindAllEpisodes ¶ added in v0.3.0
func FindEpisodeByID ¶ added in v0.3.0
FindEpisodeByID finds a episode based on its ID
func FindEpisodeByNumber ¶ added in v0.3.0
FindEpisodeByNumber finds an Episode by Season/episode number
func FindEpisodeByUUID ¶
FindEpisodeByUUID finds a episode based on it's UUID.
func FindEpisodesForSeason ¶
FindEpisodesForSeason finds all episodes for the given season ID.
func FindEpisodesInLibrary ¶
FindEpisodesInLibrary returns all episodes in the given library.
func GetNextEpisodes ¶ added in v0.4.0
GetNextEpisodes returns the next n episodes after the episode with the provided UUID
func GetPreviousEpisodes ¶ added in v0.4.0
GetPreviousEpisodes returns the next n episodes after the episode with the provided UUID
func RecentlyAddedEpisodes ¶
RecentlyAddedEpisodes returns a list of the latest 10 episodes added to the database.
func UpNextEpisodes ¶
UpNextEpisodes returns a list of episodes that are up for viewing next. If you recently finished episode 5 of series Y and episode 6 is unwatched it should return this episode.
func (*Episode) UpdatedAtTimeStamp ¶
UpdatedAtTimeStamp returns a unix timestamp for the given episode.
type EpisodeFile ¶
type EpisodeFile struct { gorm.Model MediaItem EpisodeID uint Episode *Episode Streams []Stream `gorm:"polymorphic:Owner;"` }
EpisodeFile holds filesystem information about a given episode file.
func FindAllEpisodeFiles ¶
func FindAllEpisodeFiles() (files []EpisodeFile)
FindAllEpisodeFiles retrieves all episodefiles from the db.
func FindAllUnidentifiedEpisodeFiles ¶ added in v0.3.0
func FindAllUnidentifiedEpisodeFiles(qd *QueryDetails) ([]EpisodeFile, error)
FindAllUnidentifiedEpisodeFiles find all EpisodeFiles without an associated Episode
func FindAllUnidentifiedEpisodeFilesInLibrary ¶ added in v0.3.0
func FindAllUnidentifiedEpisodeFilesInLibrary(libraryID uint) ([]*EpisodeFile, error)
FindAllUnidentifiedEpisodeFilesInLibrary find all EpisodeFiles without an associated Episode in a library
func FindEpisodeFileByPath ¶ added in v0.3.3
func FindEpisodeFileByPath(filePath filesystem.Node) (*EpisodeFile, error)
FindEpisodeFileByPath Returns the first EpisodeFile matching the provided filePath, regardless of whether the EpisodeFile is local or remote.
func FindEpisodeFileByUUID ¶ added in v0.3.0
func FindEpisodeFileByUUID(uuid string) (*EpisodeFile, error)
FindEpisodeFileByUUID finds an EpisodeFile by UUID
func FindEpisodeFilesInLibrary ¶ added in v0.3.0
func FindEpisodeFilesInLibrary(libraryID uint) ([]EpisodeFile, error)
FindEpisodeFilesInLibrary finds all episode files in the given library.
func FindEpisodeFilesInLibraryByLocator ¶ added in v0.3.3
func FindEpisodeFilesInLibraryByLocator(libraryID uint, locator filesystem.FileLocator) (episodes []EpisodeFile)
FindEpisodeFilesInLibraryByLocator finds all episode files in the given library under the given locator's path
func (EpisodeFile) DeleteWithStreams ¶ added in v0.3.3
func (file EpisodeFile) DeleteWithStreams()
DeleteWithStreams deletes the episode file and any stale metadata information that might have resulted.
func (EpisodeFile) GetFileName ¶ added in v0.2.0
func (file EpisodeFile) GetFileName() string
GetFileName is a wrapper for the MediaFile interface
func (EpisodeFile) GetFilePath ¶ added in v0.2.0
func (file EpisodeFile) GetFilePath() string
GetFilePath is a wrapper for the MediaFile interface
func (EpisodeFile) GetLibrary ¶ added in v0.2.0
func (file EpisodeFile) GetLibrary() *Library
GetLibrary is a wrapper for the MediaFile interface
func (EpisodeFile) GetStreams ¶ added in v0.2.0
func (file EpisodeFile) GetStreams() []Stream
GetStreams returns all streams for this file
func (*EpisodeFile) IsSingleFile ¶
func (file *EpisodeFile) IsSingleFile() bool
IsSingleFile returns true if this is the only file for the given episode.
type Invite ¶
Invite is a model used to invite users to your server.
func CreateInvite ¶
func CreateInvite() Invite
CreateInvite creates an invite code that can be redeemed by new users.
type Library ¶
type Library struct { gorm.Model Kind MediaType Backend int RcloneName string FilePath string `gorm:"unique_index:idx_file_path"` Name string Healthy bool `gorm:"default:'1'"` RefreshStartedAt time.Time RefreshCompletedAt time.Time }
Library is a struct containing information about filesystem folders.
func AllLibraries ¶
func AllLibraries() []Library
AllLibraries returns all libraries from the database.
func (*Library) IsLocal ¶ added in v0.2.0
IsLocal returns true when a library is based on a local filesystem
type MediaFile ¶ added in v0.2.0
type MediaFile interface { GetFilePath() string GetFileName() string GetLibrary() *Library GetStreams() []Stream }
MediaFile is an interface for various methods can be done on both episodes and movies
func FindContentByUUID ¶
FindContentByUUID can retrieve episode or movie data based on a UUID.
type MediaItem ¶
type MediaItem struct { UUIDable FileName string FilePath string Size int64 Library Library LibraryID uint }
MediaItem is an embeddeable struct that holds information about filesystem files (episode or movies).
type Movie ¶
type Movie struct { gorm.Model BaseItem Title string Year uint64 ReleaseDate string OriginalTitle string ImdbID string MovieFiles []MovieFile }
Movie is used to store movie metadata information.
func FindAllMovies ¶
func FindAllMovies(qd *QueryDetails) (movies []Movie)
FindAllMovies finds all identified movies including all associated information like streams and files.
func FindMovieByID ¶ added in v0.3.0
FindMovieByID finds the movie specified by the given ID.
func FindMovieByTmdbID ¶ added in v0.3.0
FindMovieByTmdbID finds the movie specified by the given TMDB ID
func FindMovieByUUID ¶
FindMovieByUUID finds the movie specified by the given uuid.
func FindMovieForMovieFile ¶ added in v0.3.0
FindMovieForMovieFile accepts a movieFile and returns the movie
func FindMoviesForMDRefresh ¶
func FindMoviesForMDRefresh() (movies []Movie)
FindMoviesForMDRefresh finds all movies, including unidentified ones.
func FindMoviesInLibrary ¶
FindMoviesInLibrary finds movies that have files in a certain library
func FirstMovie ¶
func FirstMovie() Movie
FirstMovie gets the first movie out of the database (used in tests).
func RecentlyAddedMovies ¶
RecentlyAddedMovies returns a list of the latest 10 movies added to the database.
func SearchMovieByTitle ¶
SearchMovieByTitle search movies by title.
func UpNextMovies ¶
UpNextMovies returns a list of movies that are recently added and not watched yet.
func (*Movie) UpdatedAtTimeStamp ¶
UpdatedAtTimeStamp returns a unix timestamp.
func (*Movie) YearAsString ¶
YearAsString returns the year, as a string....
type MovieFile ¶
type MovieFile struct { gorm.Model MediaItem Movie Movie MovieID uint Streams []Stream `gorm:"polymorphic:Owner;"` }
MovieFile is used to store fileinformation about a movie.
func FindAllMovieFiles ¶
func FindAllMovieFiles() (movies []MovieFile)
FindAllMovieFiles Returns all movies, even once that could not be identified.
func FindAllUnidentifiedMovieFiles ¶ added in v0.3.0
func FindAllUnidentifiedMovieFiles(qd QueryDetails) ([]MovieFile, error)
FindAllUnidentifiedMovieFiles find all MovieFiles without an associated Movie
func FindAllUnidentifiedMovieFilesInLibrary ¶ added in v0.3.0
FindAllUnidentifiedMovieFilesInLibrary retrieves all movies without an tmdb_id in the database.
func FindFilesForMovieUUID ¶ added in v0.3.3
FindFilesForMovieUUID finds all movieFiles for the associated movie UUIDs
func FindMovieFileByPath ¶ added in v0.3.3
func FindMovieFileByPath(filePath filesystem.Node) (*MovieFile, error)
FindMovieFileByPath Returns the first MovieFile matching the provided filePath, regardless of whether the MovieFile is local or remote.
func FindMovieFileByUUID ¶ added in v0.3.0
FindMovieFileByUUID finds a specific movie based on it's UUID
func FindMovieFilesByMovieID ¶ added in v0.3.3
func FindMovieFilesInLibrary ¶ added in v0.3.0
FindMovieFilesInLibrary finds all movie files in the given library.
func FindMovieFilesInLibraryByLocator ¶ added in v0.3.3
func FindMovieFilesInLibraryByLocator(libraryID uint, locator filesystem.FileLocator) (movies []MovieFile)
FindMovieFilesInLibraryByLocator finds all movie files in the provided library under the locator's path
func (MovieFile) DeleteWithStreams ¶ added in v0.3.3
func (file MovieFile) DeleteWithStreams()
DeleteWithStreams removes this file and any metadata involved for the movie.
func (MovieFile) GetFileName ¶ added in v0.2.0
GetFileName is a wrapper for the MediaFile interface
func (MovieFile) GetFilePath ¶ added in v0.2.0
GetFilePath is a wrapper for the MediaFile interface
func (MovieFile) GetLibrary ¶ added in v0.2.0
GetLibrary is a wrapper for the MediaFile interface
func (MovieFile) GetStreams ¶ added in v0.2.0
GetStreams returns all streams for this file
func (*MovieFile) IsSingleFile ¶
IsSingleFile returns true if this is the only file for this movie.
type PlayState ¶
type PlayState struct { gorm.Model UUIDable UserID uint `gorm:"unique_index:idx_unique_play_state_per_media"` Finished bool Playtime float64 MediaUUID string `gorm:"unique_index:idx_unique_play_state_per_media"` }
PlayState holds status information about media files, it keeps track of progress and whether or not the content has been viewed to completion.
func FindPlayState ¶ added in v0.3.0
FindPlayState finds a playstate
func LatestPlayStates ¶
LatestPlayStates returns playstates for content recently played for the given user.
type QueryDetails ¶ added in v0.2.0
type QueryDetails struct { UserID uint Offset int Limit int SortDirection string SortColumn string }
QueryDetails specify arguments for media queries
type Season ¶
type Season struct { BaseItem gorm.Model Name string AirDate string SeasonNumber int Series *Series SeriesID uint Episodes []*Episode }
Season holds metadata information about seasons.
func FindSeason ¶
FindSeason finds a season by it's ID
func FindSeasonBySeasonNumber ¶ added in v0.3.0
FindSeasonBySeasonNumber gets a season by Series/season number
func FindSeasonByUUID ¶
FindSeasonByUUID finds the season based on it's UUID.
func FindSeasonsForSeries ¶
FindSeasonsForSeries retrieves all season for the given series based on it's UUID.
type Series ¶
type Series struct { BaseItem gorm.Model Name string FirstAirDate string FirstAirYear uint64 OriginalName string Status string Type string Seasons []*Season }
Series holds metadata information about series.
func FindAllSeries ¶
func FindAllSeries(qd *QueryDetails) ([]*Series, error)
FindAllSeries retrieves all identified series from the db.
func FindSeries ¶
FindSeries finds a series by it's ID
func FindSeriesByTmdbID ¶ added in v0.3.0
FindSeriesByTmdbID retrives a serie based on its TMDB ID
func FindSeriesByUUID ¶
FindSeriesByUUID retrives a serie based on it's UUID.
func FindSeriesForMDRefresh ¶
func FindSeriesForMDRefresh() (series []Series)
FindSeriesForMDRefresh finds all series, including unidentified ones.
func FindSeriesInLibrary ¶ added in v0.3.0
FindSeriesInLibrary finds all series belonging to an EpisodeFile in a given library.
func SearchSeriesByTitle ¶
SearchSeriesByTitle searches for series based on their name.
type Stream ¶
type Stream struct { gorm.Model UUIDable OwnerID uint OwnerType string StreamKey TotalDuration time.Duration TimeBase *big.Rat TotalDurationDts int64 // codecs string ready for DASH/HLS serving Codecs string CodecName string Profile string BitRate int64 FrameRate *big.Rat Width int Height int // "audio", "video", "subtitle" StreamType string // Only relevant for audio and subtitles. Language code. Language string // User-visible string for this audio or subtitle track Title string EnabledByDefault bool }
func FindStreamsForMovieFileUUID ¶ added in v0.3.3
FindStreamsForMovieFileUUID finds all movieStreams for the associated movieFile UUIDs
type StreamKey ¶ added in v0.2.0
type StreamKey struct { FileLocator filesystem.FileLocator // StreamId from ffmpeg // StreamId is always 0 for transmuxing StreamId int64 }
These are copies of the same structs in the ffmpeg package to a) avoid a dependency of the db package on the ffmpeg package and b) allow the ffmpeg package to be advanced separately from the database.
type UUIDable ¶
type UUIDable struct {
UUID string `json:"uuid"`
}
UUIDable ensures a UUID is added to each model this is embedded in.
func (*UUIDable) BeforeCreate ¶
BeforeCreate ensures a UUID is set before model creation.
type User ¶
type User struct { UUIDable CommonModelFields Username string `gorm:"not null;unique" json:"username"` Admin bool `gorm:"not null" json:"admin"` PasswordHash string `gorm:"not null" json:"-"` Salt string `gorm:"not null" json:"-"` }
User defines a user model.
func CreateUser ¶
CreateUser creates a new (admin) user to allow access via the web-interface
func CreateUserWithCode ¶
CreateUserWithCode creates a new user. The invite code will be ignored if no other users exist yet.
func FindUserByUsername ¶ added in v0.3.0
FindUserByUsername returns a specific user.
func (*User) SetPassword ¶
SetPassword sets a (new) password for the given user.
func (*User) ValidPassword ¶
ValidPassword checks if the given password is valid for the user.