media

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: AGPL-3.0 Imports: 16 Imported by: ? 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 media provides the Hatchet workflow definition for processing media files (movies and TV episodes) using a single parameterised workflow.

Index

Constants

View Source
const (

	// DefaultDetectCropTimeout is the default Hatchet execution timeout for the
	// detectcrop step, used when MediaWorkflowConfig.DetectCropTimeout is zero.
	DefaultDetectCropTimeout = 30 * time.Minute
	// DefaultTranscodeTimeout is the default Hatchet execution timeout for the
	// transcode step, used when MediaWorkflowConfig.TranscodeTimeout is zero.
	DefaultTranscodeTimeout = 4 * time.Hour
)
View Source
const MediaWorkflowName = mediatypes.MediaWorkflowName

MediaWorkflowName re-exports the constant from the types package for callers that import workflows/media directly.

Variables

This section is empty.

Functions

func NewMediaWorkflow

func NewMediaWorkflow(
	client *hatchet.Client,
	cfg MediaWorkflowConfig,
	radarrClient medialib.ArrLibrary,
	sonarrClient medialib.ArrLibrary,
	webhookClient *webhook.Client,
) *hatchet.Workflow

NewMediaWorkflow returns a Hatchet workflow that transcodes a media file (movie or TV episode) to the standard format, moves it to the output directory, and notifies the appropriate library service (Radarr for movies, Sonarr for TV episodes).

Steps (in order): probe → transcode → notify → cleanup → record_metrics. A parallel record_invalid step fires only when the file is not valid media. If the source file is not a valid media file with a video stream the file is deleted and all other steps are skipped without triggering the failure webhook.

Types

type MediaInput

type MediaInput = mediatypes.MediaInput

MediaInput is an alias for the shared input type so existing callers within this package do not need to be updated.

type MediaWorkflowConfig

type MediaWorkflowConfig struct {
	// OutputDir is the local directory where transcoded files are written.
	OutputDir string
	// WatcherRoot is the root directory monitored by the watcher. When set,
	// RunTranscode mirrors the subdirectory of the input file relative to
	// WatcherRoot under OutputDir, preserving the download client's directory
	// structure so that arr queue entries can be matched by path.
	WatcherRoot string
	// WebhookURL is the endpoint to notify on workflow failure.
	WebhookURL string
	// HardwareDevicePath is the device path passed to CreateHardwareDeviceContext
	// for hardware-accelerated transcoding. An empty string uses libav auto-select.
	HardwareDevicePath string
	// MeterProvider is the OTel MeterProvider used for per-run metrics. When nil,
	// a no-op provider is used and no metrics are emitted.
	MeterProvider otelmetric.MeterProvider
	// HighCardinalityLabels controls whether per-item labels (id, title, year, etc.)
	// are attached to metric observations. Corresponds to METRICS_HIGH_CARDINALITY_LABELS.
	HighCardinalityLabels bool
	// MinCropX is the minimum number of pixels that must be trimmed horizontally
	// for a crop to be applied. -1 disables the threshold (any crop is accepted).
	// 0 means no minimum (any detected crop is applied). Defaults are applied by
	// the caller (e.g. cmd/worker via parseCropThreshold) before constructing this config.
	MinCropX int
	// MinCropY is the minimum number of pixels that must be trimmed vertically
	// for a crop to be applied. -1 disables the threshold (any crop is accepted).
	// 0 means no minimum (any detected crop is applied). Defaults are applied by
	// the caller (e.g. cmd/worker via parseCropThreshold) before constructing this config.
	MinCropY int
	// DetectCropTimeout is the Hatchet execution timeout for the detectcrop step.
	// When zero, NewMediaWorkflow applies a default of 30 minutes. Set by the caller
	// (e.g. cmd/worker via parseTimeout from MEDIA_DETECT_CROP_TIMEOUT).
	DetectCropTimeout time.Duration
	// TranscodeTimeout is the Hatchet execution timeout for the transcode step.
	// When zero, NewMediaWorkflow applies a default of 4 hours. Set by the caller
	// (e.g. cmd/worker via parseTimeout from MEDIA_TRANSCODE_TIMEOUT).
	TranscodeTimeout time.Duration
	// H265CRF is the constant-quality value passed to H.265 encoders. 0 means
	// use the encoder's built-in default. For libx265 this is the CRF; for
	// hevc_nvenc it is the CQ value; for hevc_qsv and hevc_vaapi it is the
	// global_quality (ICQ) value. Set by the caller (e.g. cmd/worker via
	// MEDIA_H265_CRF).
	H265CRF int
	// ProgressLogInterval controls how often a progress log line is emitted
	// during transcoding. Zero disables progress logging. Set by the caller
	// (e.g. cmd/worker via MEDIA_PROGRESS_LOG_INTERVAL).
	ProgressLogInterval time.Duration
}

MediaWorkflowConfig holds the configuration for the media processing workflow.

type Recorder

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

Recorder holds OTel instruments for the media workflow and records per-run observations.

func NewRecorder

func NewRecorder(mp otelmetric.MeterProvider, highCardinality bool) (*Recorder, error)

NewRecorder creates a Recorder that registers all media workflow instruments against mp. When highCardinality is true, RecordRun attaches id/title/year (and episode-specific) labels to every observation.

func (*Recorder) RecordArtworkFetchSkipped

func (r *Recorder) RecordArtworkFetchSkipped(ctx context.Context)

RecordArtworkFetchSkipped increments the artwork_fetch_skipped_total counter.

func (*Recorder) RecordInvalidFile

func (r *Recorder) RecordInvalidFile(ctx context.Context, mediaType medialib.MediaType, mappingName string)

RecordInvalidFile increments the invalid_files_total counter. Only media_type and mapping_name labels are applied (no transcode data is available for invalid files).

func (*Recorder) RecordMetricsError

func (r *Recorder) RecordMetricsError(ctx context.Context, err error)

RecordMetricsError increments the metrics_errors_total counter and logs the error.

func (*Recorder) RecordRun

func (r *Recorder) RecordRun(
	ctx context.Context,
	input MediaInput,
	probe steps.ProbeOutput,
	transcode steps.TranscodeOutput,
	mediaInfo medialib.MediaInfo,
	hardwareAccelerated bool,
	totalElapsed time.Duration,
)

RecordRun records the full set of processing metrics for a completed valid-media workflow run. mediaInfo may be nil; when non-nil and highCardinality is enabled, per-item labels are added. hardwareAccelerated should be true when a hardware device path was configured. totalElapsed is the wall-clock time from probe start to cleanup finish.

Directories

Path Synopsis
Package types defines the shared workflow name and input payload for the media processing workflow.
Package types defines the shared workflow name and input payload for the media processing workflow.

Jump to

Keyboard shortcuts

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