Documentation
¶
Overview ¶
Package media provides the Hatchet workflow definition for processing media files (movies and TV episodes) using a single parameterised workflow.
Index ¶
- Constants
- func NewMediaWorkflow(client *hatchet.Client, cfg MediaWorkflowConfig, ...) *hatchet.Workflow
- type MediaInput
- type MediaWorkflowConfig
- type Recorder
- func (r *Recorder) RecordArtworkFetchSkipped(ctx context.Context)
- func (r *Recorder) RecordInvalidFile(ctx context.Context, mediaType medialib.MediaType, mappingName string)
- func (r *Recorder) RecordMetricsError(ctx context.Context, err error)
- func (r *Recorder) RecordRun(ctx context.Context, input MediaInput, probe steps.ProbeOutput, ...)
Constants ¶
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 )
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 {
// 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 ¶
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 ¶
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.