chapterremove

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package chapterremove parses and evaluates yt-dlp-compatible chapter removal specifications without depending on Python.

Index

Constants

View Source
const (
	MaxSpecifications     = 64
	MaxSpecificationBytes = 4096
	MaxTotalBytes         = 64 << 10
	MaxRanges             = 256
	// The chapter title language is a bounded Python regular-expression
	// search, matching the pinned ModifyChaptersPP use of regex.search().
	// Keep these limits local to chapter removal: this package shares syntax
	// translation with match filters and metadata transforms, not their
	// execution policy.
	MaxRegexSourceBytes      = 4096
	MaxRegexTranslatedBytes  = 16 << 10
	MaxRegexInputBytes       = 64 << 10
	MaxRegexAttempts         = 256
	MaxRegexInspectedBytes   = 4 << 20
	RegexMatchTimeout        = 25 * time.Millisecond
	RegexAggregateWallBudget = 250 * time.Millisecond
)

Variables

View Source
var (
	ErrInvalidSpecification = errors.New("invalid chapter removal specification")
	ErrLimit                = errors.New("chapter removal limit exceeded")
)

Functions

This section is empty.

Types

type EvaluationBudget

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

EvaluationBudget bounds one logical group of chapter-title searches. It is intentionally caller-owned so Program remains immutable and safe to reuse concurrently. A fresh budget is suitable for a single MatchTitle call; product code shares one budget across an entire media item's chapters.

func NewEvaluationBudget

func NewEvaluationBudget() *EvaluationBudget

NewEvaluationBudget returns a bounded accounting object for a complete chapter-removal evaluation. It contains no source text or title data.

type Program

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

Program is an immutable, concurrency-safe chapter removal program.

func Parse

func Parse(specifications []string) (Program, error)

Parse compiles repeatable --remove-chapters values. Values beginning with "*" are comma-separated time ranges; every other value is a title regular expression using search semantics.

func (Program) Empty

func (program Program) Empty() bool

Empty reports whether the program requests no title or range removal.

func (Program) HasPatterns

func (program Program) HasPatterns() bool

HasPatterns reports whether title matching was requested.

func (Program) HasRanges

func (program Program) HasRanges() bool

HasRanges reports whether manual time ranges were requested.

func (Program) MatchTitle

func (program Program) MatchTitle(ctx context.Context, title string) (bool, error)

MatchTitle reports whether any configured expression occurs in title.

func (Program) MatchTitleWithBudget

func (program Program) MatchTitleWithBudget(ctx context.Context, title string, budget *EvaluationBudget) (bool, error)

MatchTitleWithBudget reports whether any configured Python expression searches title. The source, translated expression, input, number of attempts, inspected bytes, individual match time, and aggregate wall time are all bounded. Errors deliberately contain no pattern or title text.

func (Program) ResolveRanges

func (program Program) ResolveRanges(duration float64) ([]Range, error)

ResolveRanges maps open range ends to duration and drops intervals wholly outside the media. Returned ranges are clamped but intentionally not merged; the shared cut planner performs stable overlap/adjacency merging.

type Range

type Range struct {
	Start float64
	End   *float64
}

Range is a parsed manual removal range. A nil End means the end of the media. Start defaults to zero for an open start.

Jump to

Keyboard shortcuts

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