template

package
v0.2.9-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxTemplateBytes    = 64 * 1024
	DefaultMaxOutputBytes      = 10 * 1024 * 1024
	DefaultMaxConditionalDepth = 32
)

Variables

This section is empty.

Functions

func SanitizeFilename

func SanitizeFilename(s string) string

SanitizeFilename removes or replaces characters that are invalid in filenames This is a standalone function for use by callers

func SanitizeFolderPath

func SanitizeFolderPath(s string) string

SanitizeFolderPath sanitizes a folder name by replacing invalid filesystem characters

Types

type Context

type Context struct {
	// Basic identifiers
	ID        string
	ContentID string

	// Title information
	Title         string
	OriginalTitle string // Japanese/original language title

	// Date information
	ReleaseDate *time.Time
	Runtime     int // in minutes

	// People
	Director    string
	Actresses   []string // Array of actress names
	FirstName   string   // For single actress context
	LastName    string   // For single actress context
	ActressName string   // Explicit actress name for .actors image filenames

	// Production info
	Maker  string // Studio/Maker
	Label  string
	Series string

	// Categories
	Genres []string

	// Media info
	OriginalFilename string
	VideoFilePath    string // Path to video file for mediainfo extraction

	// Indexing (for screenshots, multi-part, etc.)
	Index int

	// Multi-part file information
	PartNumber  int    // Part number (1, 2, 3, etc.) - 0 means single file
	PartSuffix  string // Original part suffix detected from filename (e.g., "-pt1", "-A")
	IsMultiPart bool   // Whether this is a multi-part file

	// Additional metadata
	Rating      float64
	Description string
	CoverURL    string
	TrailerURL  string

	// Translations keyed by normalized language code (e.g. "en", "ja")
	// IMMUTABLE after construction - safe for concurrent read access
	Translations map[string]models.MovieTranslation

	// Optional per-context override for rendered language preference
	// When empty, Engine default language is used
	// IMPORTANT: Setting this changes behavior of unqualified tags like <TITLE>
	DefaultLanguage string

	// Output configuration
	GroupActress bool // Replace multiple actresses with "@Group"
	// contains filtered or unexported fields
}

Context holds all data available for template execution

func NewContextFromMovie

func NewContextFromMovie(movie *models.Movie) *Context

NewContextFromMovie creates a template context from a Movie model

func NewContextFromScraperResult

func NewContextFromScraperResult(result *models.ScraperResult) *Context

NewContextFromScraperResult creates a template context from a ScraperResult

func (*Context) Clone

func (c *Context) Clone() *Context

Clone creates a copy of the context. Preserves cached mediainfo to avoid duplicate expensive analysis.

func (*Context) GetMediaInfo

func (c *Context) GetMediaInfo() *mediainfo.VideoInfo

GetMediaInfo lazy-loads and caches video metadata. Thread-safe: uses sync.Once to ensure single initialization even under concurrent access. Preserves pre-existing cached values from Clone() to avoid duplicate expensive analysis.

type Engine

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

Engine is a template processor for format strings

func NewEngine

func NewEngine() *Engine

NewEngine creates a new template engine

func NewEngineWithOptions

func NewEngineWithOptions(opts EngineOptions) *Engine

NewEngineWithOptions creates a new template engine with custom limits.

func (*Engine) Execute

func (e *Engine) Execute(template string, ctx *Context) (string, error)

Execute processes a template string with the given context

func (*Engine) ExecuteWithContext

func (e *Engine) ExecuteWithContext(execCtx context.Context, template string, ctx *Context) (string, error)

ExecuteWithContext processes a template string with cancellation support and output limits.

func (*Engine) TruncateTitle

func (e *Engine) TruncateTitle(title string, maxLen int) string

TruncateTitle smartly truncates a title to maxLen characters

func (*Engine) TruncateTitleBytes

func (e *Engine) TruncateTitleBytes(title string, maxBytes int) string

TruncateTitleBytes smartly truncates a title to fit within maxBytes (byte length) This is needed because file paths have byte length limits, not rune count limits

func (*Engine) Validate

func (e *Engine) Validate(template string) error

Validate checks template shape and size before execution.

func (*Engine) ValidatePathLength

func (e *Engine) ValidatePathLength(path string, maxLen int) error

type EngineOptions

type EngineOptions struct {
	MaxTemplateBytes    int
	MaxOutputBytes      int
	MaxConditionalDepth int
	// Template language configuration (OPT-IN behavior change)
	// Setting DefaultLanguage changes how unqualified tags like <TITLE> behave
	DefaultLanguage   string
	FallbackLanguages []string
}

EngineOptions defines validation and execution limits for template rendering.

Jump to

Keyboard shortcuts

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