models

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package models defines the core data structures used throughout the application.

Index

Constants

This section is empty.

Variables

View Source
var LogLevel = &slog.LevelVar{}

Functions

func SetupLogging

func SetupLogging(verbosity int)

SetupLogging configures logging level based on verbosity counter

Types

type AudioConfig

type AudioConfig struct {
	TargetAudioBitrate   int64
	MinSavingsAudio      float64
	TranscodingAudioRate float64
	SplitLongerThan      float64 // Parsed from string (seconds)
	MinSplitSegment      float64 // Parsed from string (seconds)
	AudioOnly            bool
	AlwaysSplit          bool
}

AudioConfig contains configuration for audio processing

type CommonConfig

type CommonConfig struct {
	MoveBroken         string
	SourceAudioBitrate int64
	SourceVideoBitrate int64
	MaxWidthBuffer     float64
	MaxHeightBuffer    float64
	DeleteUnplayable   bool
	DeleteLarger       bool
	Valid              bool
	Invalid            bool
	ForceShrink        bool
	VerboseFFmpeg      bool
	IncludeTimecode    bool
	// Memory monitoring via systemd-run (Linux only)
	MemoryLimit    int64 // Memory limit in bytes (0 = no limit)
	MemorySwapMax  int64 // Swap limit in bytes (0 = auto, -1 = disable swap)
	UseJournald    bool  // Use journald-compatible mode for systemd-run
	DisableSystemd bool  // Disable systemd-run wrapper even if available
	// Archive processing timeouts
	ArchiveAnalyzeTimeoutSec int64  // lsar analyze timeout in seconds
	ArchiveGlobTimeoutSec    int64  // glob operations timeout in seconds
	ArchiveGlobPath          string // path for glob timeout calculation
	ArchiveExtractTimeoutSec int64  // unar extraction timeout in seconds
}

CommonConfig contains general configuration for all processors

type ImageConfig

type ImageConfig struct {
	TargetImageSize      int64
	MinSavingsImage      float64
	TranscodingImageTime float64
	MaxImageWidth        int
	MaxImageHeight       int
}

ImageConfig contains configuration for image processing

type MediaProcessor

type MediaProcessor interface {
	// CanProcess returns true if this processor can handle the given media
	CanProcess(m *ShrinkMedia) bool

	// EstimateSize calculates the future file size and processing time
	EstimateSize(m *ShrinkMedia, cfg *ProcessorConfig) ProcessableInfo

	// Process executes the transcoding/conversion
	// Returns a single ProcessResult containing all outputs and cleanup tasks
	Process(ctx context.Context, m *ShrinkMedia, cfg *ProcessorConfig, registry ProcessorRegistry) ProcessResult

	// Category returns the type identifier for this processor
	Category() string

	// RequiredTool returns the name of the external tool required by this processor
	RequiredTool() string
}

MediaProcessor defines the interface for processing different media types

type PlainHandler

type PlainHandler struct {
	Level *slog.LevelVar
	Out   *os.File
	Attrs []slog.Attr
}

PlainHandler is a simple slog handler that outputs plain text

func (*PlainHandler) Enabled

func (h *PlainHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*PlainHandler) Handle

func (h *PlainHandler) Handle(ctx context.Context, record slog.Record) error

func (*PlainHandler) WithAttrs

func (h *PlainHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*PlainHandler) WithGroup

func (h *PlainHandler) WithGroup(name string) slog.Handler

type ProcessOutputFile

type ProcessOutputFile struct {
	Path string
	Size int64
}

ProcessOutputFile represents a new file created by a processor

type ProcessResult

type ProcessResult struct {
	SourcePath string              // Original file being processed
	Outputs    []ProcessOutputFile // New files created
	PartFiles  []string            // Multi-part archive part files (for cleanup)
	Success    bool                // Whether the overall operation succeeded
	Error      error               // Error if the operation failed
	Output     string              // Full command output (e.g. from ffmpeg)
	StopAll    bool                // Whether to stop all processing (e.g. environment error)
}

ProcessResult contains the comprehensive result of processing a media file

type ProcessableInfo added in v0.0.4

type ProcessableInfo struct {
	PartFiles      []string // Associated files (e.g. multi-part archive volumes)
	FutureSize     int64
	ActualSize     int64 // Used if the actual size differs from the reported size (e.g. multi-part archives)
	ProcessingTime int
	IsProcessable  bool
	IsBroken       bool // Whether the media item is broken/unreadable
	IsTimeout      bool // Whether the analysis timed out (don't cache this result)
}

ProcessableInfo contains information about whether and how a media item can be processed

type ProcessorConfig

type ProcessorConfig struct {
	Video  VideoConfig
	Audio  AudioConfig
	Image  ImageConfig
	Text   TextConfig
	Common CommonConfig
}

ProcessorConfig contains comprehensive configuration for all media processing

func (*ProcessorConfig) GetMinSavings added in v0.0.4

func (c *ProcessorConfig) GetMinSavings(category string) float64

GetMinSavings returns the minimum savings threshold for a media category

type ProcessorRegistry

type ProcessorRegistry interface {
	GetProcessor(m *ShrinkMedia) MediaProcessor
}

ProcessorRegistry interface defines how to retrieve a processor

type ShrinkMedia

type ShrinkMedia struct {
	PartFiles      []string // For multi-part archives: list of all part files
	Path           string
	MediaType      string
	Ext            string
	Category       string
	Size           int64
	Duration       float64
	FutureSize     int64
	Savings        int64
	CompressedSize int64
	VideoCount     int
	AudioCount     int
	Width          int
	Height         int
	ProcessingTime int
	IsBroken       bool // For archives: lsar failed to read contents
}

ShrinkMedia represents a media file to be processed

func (*ShrinkMedia) DisplayCategory

func (m *ShrinkMedia) DisplayCategory() string

DisplayCategory returns the category with the extension suffix (e.g. "Video: mp4")

func (*ShrinkMedia) ShouldShrink added in v0.0.4

func (m *ShrinkMedia) ShouldShrink(futureSize int64, cfg *ProcessorConfig) bool

ShouldShrink determines if a file should be shrinked based on savings threshold

type TextConfig

type TextConfig struct {
	SkipOCR  bool
	ForceOCR bool
	RedoOCR  bool
	NoOCR    bool
}

TextConfig contains configuration for text/ebook processing

type VideoConfig

type VideoConfig struct {
	Preset               string
	CRF                  string
	TargetVideoBitrate   int64
	MinSavingsVideo      float64
	TranscodingVideoRate float64
	MaxVideoWidth        int
	MaxVideoHeight       int
	VideoOnly            bool
	Keyframes            bool
	NoPreserveVideo      bool
}

VideoConfig contains configuration for video processing

Jump to

Keyboard shortcuts

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