repo

package
v0.0.0-...-0805d90 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeID

func SanitizeID(s string) string

SanitizeID sanitizes a string to be usable as a repository ID. Example: "My Shows" -> "my-shows"

func ValidID

func ValidID(s string) bool

ValidID checks whether the supplied string is a valid repository ID.

Types

type Capability

type Capability uint

Capability is a collection of option flags (integers ORed together).

const (
	// CapabilityWatch is a flag of a repository that is able to watch for filesystem changes.
	CapabilityWatch Capability = 1 << iota
	// CapabilityIndex is a flag of a repository that is able to persist its contents.
	CapabilityIndex
	// CapabilityRemux is a flag of a repository that is able to remux media.
	CapabilityRemux
	// CapabilityTranscode is a flag of a repository that is able to transcode media.
	CapabilityTranscode
)

func Capabilities

func Capabilities(caps []config.Capability) Capability

Capabilities translates capabilities from the configuration.

func (Capability) Has

func (c Capability) Has(flag Capability) bool

Has checks whether a Capability can be addressed from this one.

type ErrDuplicateID

type ErrDuplicateID struct {
	// ID is the offending ID.
	ID string
	// Repo is the repository name.
	Repo string
}

ErrDuplicateID is an error about a duplicate media ID in a repository.

func (*ErrDuplicateID) Error

func (edi *ErrDuplicateID) Error() string

Error returns the string representation of the error.

type ErrDuplicatePath

type ErrDuplicatePath struct {
	// Path is the offending path.
	Path string
	// Repo is the repository name.
	Repo string
}

ErrDuplicatePath is an error about a duplicate media path in a repository.

func (*ErrDuplicatePath) Error

func (edp *ErrDuplicatePath) Error() string

Error returns the string representation of the error.

type ErrInvalidID

type ErrInvalidID struct {
	// ID is the offending id.
	ID string
	// Expected is the expected name form, a regular expression or a simple description.
	Expected string
}

ErrInvalidID is an error about an invalid ID, either of a repository or media.

func (*ErrInvalidID) Error

func (ein *ErrInvalidID) Error() string

Error returns the string representation of the error.

type ErrInvalidMediaPath

type ErrInvalidMediaPath struct {
	// Path is the offending path.
	Path string
	// Root is the root directory of the repository.
	Root string
}

ErrInvalidMediaPath is an error about an unexpected media path, expected a path within the repository's root directory (could not relativize the media path).

func (*ErrInvalidMediaPath) Error

func (eimp *ErrInvalidMediaPath) Error() string

Error returns the string representation of the error.

type ErrInvalidMediaType

type ErrInvalidMediaType struct {
	// Path is the offending media path.
	Path string
	// Type is the offending MIME type.
	Type string
}

ErrInvalidMediaType is an error about an unexpected media MIME type.

func (*ErrInvalidMediaType) Error

func (eimt *ErrInvalidMediaType) Error() string

Error returns the string representation of the error.

type ErrUnsupportedFormat

type ErrUnsupportedFormat struct {
	// Format is the offending format name.
	Format string
	// Operation is the unsupported operation.
	Operation string
}

ErrUnsupportedFormat is an error about a format unsupported for de/muxing or transcoding.

func (*ErrUnsupportedFormat) Error

func (euf *ErrUnsupportedFormat) Error() string

Error returns the string representation of the error.

func (*ErrUnsupportedFormat) Unwrap

func (euf *ErrUnsupportedFormat) Unwrap() error

Unwrap returns the parent error (errors.ErrUnsupported).

type ErrUnsupportedOperation

type ErrUnsupportedOperation struct {
	// Operation is the unsupported operation.
	Operation string
	// Repo is the repository name.
	Repo string
}

ErrUnsupportedOperation is an error about an operation unsupported in a repository.

func (*ErrUnsupportedOperation) Error

func (euo *ErrUnsupportedOperation) Error() string

Error returns the string representation of the error.

func (*ErrUnsupportedOperation) Unwrap

func (euo *ErrUnsupportedOperation) Unwrap() error

Unwrap returns the parent error (errors.ErrUnsupported).

type MutableRepository

type MutableRepository interface {
	Repository

	// Scan tries to recursively discover missing media from the repository root directory.
	Scan() error
	// Add adds media to the repository.
	Add(m media.Media) error
	// AddPath adds media at the supplied path to the repository.
	AddPath(path string) error
	// Remove removes media from the repository.
	Remove(m media.Media) error
	// RemovePath removes media with the supplied absolute path from the repository.
	RemovePath(path string) error
}

MutableRepository is a mutable media repository.

func NewRepository

func NewRepository(id, name, path string, metaSource meta.Source, logger *zap.Logger) (MutableRepository, error)

NewRepository creates a file-based CRUD repository.

func NopMutable

func NopMutable(r Repository) MutableRepository

NopMutable wraps a Repository and no-ops unimplemented mutation functions.

type Repository

type Repository interface {
	// ID returns the repository ID, alphanumeric, lowercase, non-blank ([a-z0-9-_]).
	ID() string
	// Name returns the repository name.
	Name() string
	// Path returns the path to the root directory of this repository, absolute.
	Path() string
	// Capabilities returns the capabilities of this repository.
	Capabilities() Capability

	// Get tries to get media by its ID in this repository, returns nil if not found.
	Get(id string) media.Media
	// Find tries to find media of an absolute or relative path in this repository, returns nil if not found.
	Find(path string) media.Media
	// Items returns the pieces of media in this repository.
	Items() []media.Media

	// Remux remuxes media to the desired container format and returns the remuxed media or nil, if the ID wasn't found.
	// ErrUnsupportedOperation may be returned if the repository does not have the CapabilityRemux capability.
	Remux(id string, format *media.Format) (media.Media, error)

	// Source returns the metadata source for this repository.
	Source() meta.Source

	// Close cleans up residual data after the repository.
	// The repository should not be used any further after calling Close.
	Close() error

	// Mutable tries to assert this repository view to a MutableRepository, returns nil if not possible.
	Mutable() MutableRepository
}

Repository is an immutable media repository or an immutable view of one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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