controller

package module
v0.0.0-...-9b56d49 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("attempted operation on closed struct")

ErrClosed is used when a struct is closed but an operation was attempted anyway.

View Source
var ErrEmptyQueue error = errors.New("queue is empty")

ErrEmptyQueue represents when the operation cannot be completed because the queue is empty

Functions

func IsContextFinished

func IsContextFinished(ctx *context.Context) bool

IsContextFinished returns a boolean indicating whether or not a context.Context is finished. This replaces the need to use a select code block.

func Run

func Run(ctx *context.Context, logger Logger, hc HealthChecker, lm LibraryManager, rc RunnerCommunicator, ui UserInterfacer, setLogLvl func(), testMode bool)

Run is the "top-level" function for running the Encodarr Controller. It calls all of the injected dependencies in order to operate.

Types

type AudioTrack

type AudioTrack struct {
	Index    int `json:"index"`    // "StreamOrder" (MI), "index" (FF)
	Channels int `json:"channels"` // "Channels" (MI), "channels" (FF)
}

AudioTrack contains information about a singular audio stream in a media file.

type CompletedJob

type CompletedJob struct {
	UUID    UUID    `json:"uuid"`
	Failed  bool    `json:"failed"`
	History History `json:"history"`
	InFile  string  `json:"-"`
}

CompletedJob represents a job that has been completed by a Runner.

type DispatchedJob

type DispatchedJob struct {
	UUID        UUID      `json:"uuid"`
	Runner      string    `json:"runner"`
	Job         Job       `json:"job"`
	Status      JobStatus `json:"status"`
	LastUpdated time.Time `json:"last_updated"`
}

DispatchedJob represents a job that is currently being worked on by a Runner.

type File

type File struct {
	Path     string
	ModTime  time.Time
	Metadata FileMetadata
}

File represents a file for the purposes of metadata reading.

type FileCacheDataStorer

type FileCacheDataStorer interface {
	Modtime(path string) (time.Time, error)
	Metadata(path string) (FileMetadata, error)

	SaveModtime(path string, t time.Time) error
	SaveMetadata(path string, f FileMetadata) error
}

FileCacheDataStorer defines how the FileCache stores data.

type FileMetadata

type FileMetadata struct {
	General        General         `json:"general"`
	VideoTracks    []VideoTrack    `json:"video_tracks"`
	AudioTracks    []AudioTrack    `json:"audio_tracks"`
	SubtitleTracks []SubtitleTrack `json:"subtitle_tracks"`
}

FileMetadata contains information about a video file.

type General

type General struct {
	// It looks like any non-string field will have to be parsed
	Duration float32 `json:"duration"`
}

General contains the general information about a media file.

type HTTPServer

type HTTPServer interface {
	// Start starts the HTTPServer. If Start is called again, it is a no-op.
	Start(*context.Context, *sync.WaitGroup)

	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handlerFunc func(http.ResponseWriter, *http.Request))
}

HTTPServer defines how an HTTPServer should behave.

type HealthChecker

type HealthChecker interface {
	// Run loops through the provided slice of dispatched jobs and checks if any have
	// surpassed the allowed time between updates.
	Run() (uuidsToNull []UUID)

	Start(ctx *context.Context)
}

The HealthChecker interface describes how a struct wishing to decide if a job's last update was long enough ago to mark the Runner doing it as unresponsive should interact with the Run function.

type HealthCheckerDataStorer

type HealthCheckerDataStorer interface {
	DispatchedJobs() []DispatchedJob
	DeleteJob(uuid UUID) error
}

HealthCheckerDataStorer defines how a HealthChecker stores data.

type History

type History struct {
	Filename          string    `json:"file"`
	DateTimeCompleted time.Time `json:"datetime_completed"`
	Warnings          []string  `json:"warnings"`
	Errors            []string  `json:"errors"`
}

History represents a previously completed job.

type Job

type Job struct {
	UUID     UUID         `json:"uuid"`
	Path     string       `json:"path"`
	Command  []string     `json:"command"`
	Metadata FileMetadata `json:"metadata"`
}

Job represents a job to be carried out by a Runner.

func (Job) Equal

func (j Job) Equal(check Job) bool

Equal is a custom equality check for the Job type

func (Job) EqualPath

func (j Job) EqualPath(check Job) bool

EqualPath is a custom equality check for the Job type that only checks the Path parameter

type JobStatus

type JobStatus struct {
	Stage                       string `json:"stage"`
	Percentage                  string `json:"percentage"`
	JobElapsedTime              string `json:"job_elapsed_time"`
	FPS                         string `json:"fps"`
	StageElapsedTime            string `json:"stage_elapsed_time"`
	StageEstimatedTimeRemaining string `json:"stage_estimated_time_remaining"`
}

JobStatus represents the current status of a dispatched job.

type Library

type Library struct {
	ID                     int           `json:"id"`
	Folder                 string        `json:"folder"`
	Priority               int           `json:"priority"`
	FsCheckInterval        time.Duration `json:"fs_check_interval"`
	Queue                  LibraryQueue  `json:"queue"`
	PathMasks              []string      `json:"path_masks"`
	CommandDeciderSettings string        `json:"command_decider_settings"` // We are using a string for the CommandDecider settings because it is easier for the frontend to convert back and forth from when setting and reading values.
}

Library represents a single library.

type LibraryManager

type LibraryManager interface {
	// ImportCompletedJobs imports the provided jobs into the system.
	ImportCompletedJobs([]CompletedJob)

	// LibrarySettings returns the current settings of all libraries (including the queues).
	LibrarySettings() ([]Library, error)

	// PopNewJob returns a job that may be dispatched as well as deletes it from any
	// data stores.
	PopNewJob() (Job, error)

	// UpdateLibrarySettings loops through the provided map of new settings and applies
	// them to the appropriate libraries.
	UpdateLibrarySettings(map[int]Library)

	Start(ctx *context.Context, wg *sync.WaitGroup)
}

The LibraryManager interface describes how a struct wishing to deal with user's libraries should interact with the Run function.

type LibraryManagerDataStorer

type LibraryManagerDataStorer interface {
	Libraries() ([]Library, error)
	Library(id int) (Library, error)
	SaveLibrary(Library) error

	IsPathDispatched(path string) (bool, error)
	PopDispatchedJob(uuid UUID) (DispatchedJob, error)

	PushHistory(History) error
}

LibraryManagerDataStorer defines how a LibraryManager stores data.

type LibraryQueue

type LibraryQueue struct {
	Items []Job
}

LibraryQueue represents a singular queue belonging to one library.

func (*LibraryQueue) Dequeue

func (q *LibraryQueue) Dequeue() []Job

Dequeue returns a copy of the underlying slice in the Queue.

func (*LibraryQueue) Empty

func (q *LibraryQueue) Empty() bool

Empty returns a boolean representing whether or not the queue is empty

func (*LibraryQueue) InQueue

func (q *LibraryQueue) InQueue(item Job) bool

InQueue returns a boolean representing whether or not the provided item is in the queue

func (*LibraryQueue) InQueuePath

func (q *LibraryQueue) InQueuePath(item Job) bool

InQueuePath returns a boolean representing whether or not the provided item is in the queue based on only the Path field

func (*LibraryQueue) Pop

func (q *LibraryQueue) Pop() (Job, error)

Pop removes and returns the first item of a LibraryQueue.

func (*LibraryQueue) Push

func (q *LibraryQueue) Push(item Job)

Push appends an item to the end of a LibraryQueue.

type Logger

type Logger interface {
	Trace(s string, i ...interface{})
	Debug(s string, i ...interface{})
	Info(s string, i ...interface{})
	Warn(s string, i ...interface{})
	Error(s string, i ...interface{})
	Critical(s string, i ...interface{})
}

The Logger interface defines how a logger should behave.

type RunnerCommunicator

type RunnerCommunicator interface {
	// CompletedJobs returns a slice of jobs that are ready to be imported back into the
	// system.
	CompletedJobs() []CompletedJob

	// NewJob takes the provided job and sends it to a waiting Runner.
	NewJob(Job)

	// NeedNewJob returns a boolean indicating whether or not a new job is required.
	NeedNewJob() bool

	// NullifyUUIDs takes the provided slice of UUIDs and marks them
	// so that if a Runner sends a request with a nullified UUID, it gets notified
	// that it is considered unresponsive and should acquire a new job.
	NullifyUUIDs([]UUID)

	// WaitingRunners returns the names of all the Runners which are waiting for a job.
	WaitingRunners() (runnerNames []string)

	Start(ctx *context.Context, wg *sync.WaitGroup)
}

The RunnerCommunicator interface describes how a struct wishing to communicate with external Runners should interact with the Run function.

type RunnerCommunicatorDataStorer

type RunnerCommunicatorDataStorer interface {
	DispatchedJob(uuid UUID) (DispatchedJob, error)
	SaveDispatchedJob(DispatchedJob) error
}

RunnerCommunicatorDataStorer defines how a RunnerCommunicator stores data.

type SettingsStorer

type SettingsStorer interface {
	Load() error
	Save() error
	Close() error

	HealthCheckInterval() uint64
	SetHealthCheckInterval(uint64)

	HealthCheckTimeout() uint64
	SetHealthCheckTimeout(uint64)

	LogVerbosity() string
	SetLogVerbosity(string)
}

The SettingsStorer defines how a struct which stores the settings in some manner should interact with other components of the application.

type SubtitleTrack

type SubtitleTrack struct {
	Index    int    `json:"index"`    // "StreamOrder" (MI), "index" (FF)
	Language string `json:"language"` // "Language" (MI), "tags.language"
}

SubtitleTrack contains information about a singular text stream in a media file.

type UUID

type UUID string

The UUID type defines a Universally Unique Identifier

type UserInterfacer

type UserInterfacer interface {
	// NewLibrarySettings returns a map of all updated library settings as set by the user.
	NewLibrarySettings() map[int]Library

	// SetLibrarySettings takes the provided slice of LibrarySettings and stores it
	// for an incoming request.
	SetLibrarySettings([]Library)

	// SetWaitingRunners stores an updated value that should be sent if a request to view
	// the waiting Runner is received.
	SetWaitingRunners(runnerNames []string)

	Start(ctx *context.Context, wg *sync.WaitGroup)
}

The UserInterfacer interface describes how a struct wishing to interact with the user should interact with the Run function.

type UserInterfacerDataStorer

type UserInterfacerDataStorer interface {
	DispatchedJobs() ([]DispatchedJob, error)

	HistoryEntries() ([]History, error)

	DeleteLibrary(id int) error
}

UserInterfacerDataStorer defines how a UserInterfacer stores data.

type VideoTrack

type VideoTrack struct {
	Index int    `json:"index"` // "StreamOrder" (MI), "index" (FF)
	Codec string `json:"codec"` // Either "AVC", "HEVC", etc.
	// Bitrate        int    `json:"bitrate"`         // "BitRate" (MI), "bit_rate" (FF) // Not implemented for now because I want bitrate per stream, not overall file.
	Width          int    `json:"width"`           // "Width" (MI), "width" (FF)
	Height         int    `json:"height"`          // "Height" (MI), "height" (FF)
	ColorPrimaries string `json:"color_primaries"` // "colour_primaries" (MI), "color_primaries" (FF) Will be different based on which MetadataReader is being used (FF gives "bt2020" while MI gives "BT.2020")
}

VideoTrack contains information about a singular video stream in a media file.

Directories

Path Synopsis
cmd
options
Package options is a centralized location for all supported command-line/environment variable options for the Encodarr Controller
Package options is a centralized location for all supported command-line/environment variable options for the Encodarr Controller
Package globals is the location of read-only constants such as Version, which is set at build time for release binaries.
Package globals is the location of read-only constants such as Version, which is set at build time for release binaries.

Jump to

Keyboard shortcuts

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