makemkv

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnhandledLine is returned when attempting to parse a makemkvcon output
	// line with an unhandled prefix.
	ErrUnhandledLine = fmt.Errorf("unhandled line")

	// ErrNotFound is returned when something is not found.
	ErrNotFound = fmt.Errorf("not found")
)

Functions

func FindExe

func FindExe() (string, error)

FindExe attempts to return the path of the makemkvcon executable on Linux and Darwin operating systems.

func Maximums

func Maximums[S []E, E any, V constraints.Ordered](s S, f func(E) (V, error)) S

Maximums returns all elements of the slice that maximize the given function, i.e., where f(e) = max(f(e0), f(e1), ..., f(eN)).

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string with hours, minutes and seconds values separated by colons like "1:22:33".

func ParseLines

func ParseLines(r io.Reader) iter.Seq2[Line, error]

ParseLines parses makemkvcon output lines from r. It returns a sequence of [Line, error] where either Line is a parsed line or err is non-nil. The sequence ends after all lines have been parsed and r returns EOF. Individual line parsing errors do not trigger an early return.

Types

type Con

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

Con is the interface for running makemkvcon commands.

func New

func New(cfg *Config) (*Con, error)

New returns a new Con.

If cfg.ExePath is empty, it will attempt to locate the executable automatically.

func (*Con) BackupTitle

func (c *Con) BackupTitle(ctx context.Context, driveIndex, titleIndex int, dstDir string) (iter.Seq2[Line, error], error)

BackupTitle creates a backup of title titleIndex of drive driveIndex in dstDir. The directory is created automatically if necessary.

func (*Con) ListDrives

func (c *Con) ListDrives(ctx context.Context) (*LineIterator[[]*DriveScanLine], error)

ListDrives returns the list of drives detected by makemkvcon.

func (*Con) RunCmd

func (c *Con) RunCmd(ctx context.Context, args ...string) (iter.Seq2[Line, error], error)

RunCmd runs an arbitrary makemkvcon command with the given args. It terminates when the context is canceled or the command terminates.

func (*Con) RunDefaultCmd

func (c *Con) RunDefaultCmd(ctx context.Context, args ...string) (iter.Seq2[Line, error], error)

RunDefaultCmd calls RunCmd with default args in addition to the specified args. Default args include -r (machine-readable output), --minlength, and --profile.

func (*Con) ScanDrive

func (c *Con) ScanDrive(ctx context.Context, driveIndex int) (*LineIterator[*Disc], error)

ScanDrive returns information about the disc in the given drive. The driveIndex should be obtained from ListDrives.

type Config

type Config struct {
	// ExePath is the path to the makemkvcon executable. It must exist.
	ExePath string

	// ProfilePath is the path to a makemkv profile XML file. makemkvcon relies
	// on it for the app_DefaultSelectionString setting, which determines what
	// streams (video, audio, and subtitles) are selected by default. It must
	// exist if non-empty.
	ProfilePath string

	// ReadCacheSizeMB is the value that is passed with the --cache argument to
	// makemkvcon. It must be at least 1.
	ReadCacheSizeMB int64 `validate:"min=1"`

	// MinLengthSeconds is the value that is passed with the --minlength argument
	// to makemkvcon. It must be at least 1.
	//
	// It filters out titles with video streams less than the given length, which
	// is very useful for weeding out unimportant streams.
	MinLengthSeconds int64 `validate:"min=1"`
}

Config is the makemkvcon configuration.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate returns an error if the configuration is invalid.

type CurrentProgressLine

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

CurrentProgressLine represents a makemkvcon "PRGC" output line, which describes the current sub-task.

See https://makemkv.com/developers/usage.txt.

func ParseCurrentProgressLine

func ParseCurrentProgressLine(s string) (*CurrentProgressLine, error)

ParseCurrentProgressLine parses the string that follows "PRGC:" in the output of makemkvcon.

func (*CurrentProgressLine) Kind

func (l *CurrentProgressLine) Kind() LineKind

type Disc

type Disc struct {
	Info

	Titles []*Title
}

Disc is a sequence of titles plus some metadata.

func (*Disc) GetTitle

func (d *Disc) GetTitle(index int) *Title

GetTitle returns the title with the given index, creating it (and previous titles) if necessary.

func (*Disc) TitleCount

func (d *Disc) TitleCount() int

TitleCount returns the number of titles on the disc.

func (*Disc) TitlesWithAngle

func (d *Disc) TitlesWithAngle(targetAngle int) []*Title

TitlesWithAngle returns all titles with the given angle.

func (*Disc) TitlesWithLongestDuration

func (d *Disc) TitlesWithLongestDuration() []*Title

TitlesWithLongestDuration returns all titles that tie for maximum duration.

func (*Disc) TitlesWithMostChapters

func (d *Disc) TitlesWithMostChapters() []*Title

TitlesWithMostChapters returns all titles that tie for maximum number of chapters.

func (*Disc) TitlesWithMostStreams

func (d *Disc) TitlesWithMostStreams() []*Title

TitlesWithMostStreams returns all titles that tie for maximum number of streams.

type DiscInfoLine

type DiscInfoLine struct {
	*InfoLine
}

DiscInfoLine represents a makemkvcon "CINFO" output line, which provides information about a disc.

See https://makemkv.com/developers/usage.txt.

func ParseDiscInfoLine

func ParseDiscInfoLine(s string) (*DiscInfoLine, error)

ParseDiscInfo parses the string that follows "CINFO:" in the output of makemkvcon.

func (*DiscInfoLine) Kind

func (l *DiscInfoLine) Kind() LineKind

type DriveScanLine

type DriveScanLine struct {
	Index      int
	Visible    int
	Enabled    int
	Flags      int
	DriveName  string
	DiscTitle  string
	VolumeName string
}

DriveScanLine represents a makemkvcon "DRV" output line, which describes a disc drive.

See https://makemkv.com/developers/usage.txt.

func ParseDriveScanLine

func ParseDriveScanLine(s string) (*DriveScanLine, error)

ParseDriveScanLine parses the string that follows "DRV:" in the output of makemkvcon.

func (*DriveScanLine) Kind

func (l *DriveScanLine) Kind() LineKind

type Info

type Info []*InfoLine

Info is a slice of related InfoLines.

func (Info) GetAttr

func (info Info) GetAttr(id defs.Attr) (string, error)

GetAttr returns the Value of the InfoLine where ID matches id or ErrNotFound if such a line does not exist.

func (Info) GetAttrDefault

func (info Info) GetAttrDefault(id defs.Attr, defaultValue string) string

GetAttrDefault returns the Value of the InfoLine where ID matches id or defaultValue if such a line does not exist.

func (Info) GetAttrDuration

func (info Info) GetAttrDuration(id defs.Attr) (time.Duration, error)

GetAttrDuration is like GetAttr, except it also attempts to convert the value to a time.Duration.

func (Info) GetAttrInt

func (info Info) GetAttrInt(id defs.Attr) (int, error)

GetAttrInto is like GetAttr, except it also attempts to convert the Value to an integer.

func (Info) GetCode

func (info Info) GetCode(id defs.Attr) (int, error)

GetCode returns the Code of the InfoLine where ID matches id or ErrNotFound if such a line does not exist.

func (Info) GetCodeDefault

func (info Info) GetCodeDefault(id defs.Attr, defaultValue int) int

GetCodeDefault returns the Code of the InfoLine where ID matches id or defaultValue if such a line does not exist.

type InfoLine

type InfoLine struct {

	// ID is an integer that identifies the attribute.
	ID defs.Attr

	// Code is an integer that corresponds to Value, if Value is an enumeration.
	Code int

	// Value is the value of the attribute identified by ID.
	Value string
	// contains filtered or unexported fields
}

InfoLine is the common representation of the "CINFO", "TINFO" and "SINFO" makemkvcon output lines, which describe an attribute of a disc, title, or stream.

See https://makemkv.com/developers/usage.txt.

func (*InfoLine) String

func (l *InfoLine) String() string

type Line

type Line interface {
	Kind() LineKind
}

Line is a makemkvcon output line.

func ParseLine

func ParseLine(s string) (Line, error)

ParseLine parses a makemkvcon output line.

type LineIterator

type LineIterator[T any] struct {
	Seq iter.Seq2[Line, error]
	// contains filtered or unexported fields
}

LineIterator is a generic type that represents the lines output by a makemkvcon command and the generic final result.

func (*LineIterator[T]) GetResult

func (li *LineIterator[T]) GetResult() (T, error)

GetResult returns the final result of the command.

type LineKind

type LineKind int

LineKind enumerates the kinds of lines that makemkvcon outputs.

const (
	LineKindUnknown LineKind = iota
	LineKindMessage
	LineKindDriveScan
	LineKindTitleCount
	LineKindDiscInfo
	LineKindTitleInfo
	LineKindStreamInfo
	LineKindCurrentProgress
	LineKindTotalProgress
	LineKindProgressBar
)

LineKind constants.

type MessageLine

type MessageLine struct {
	Code      int
	Flags     int
	NumParams int
	Message   string
	Format    string
	Params    []string
}

MessageLine represents a makemkvcon "MSG" output line, which is an informational logging line.

See https://makemkv.com/developers/usage.txt.

func ParseMessageLine

func ParseMessageLine(s string) (*MessageLine, error)

ParseMessageLine parses the string that follows "MSG:" in the output of makemkvcon.

func (*MessageLine) Kind

func (l *MessageLine) Kind() LineKind

type ProgressBarLine

type ProgressBarLine struct {
	// Current represents the progress of the current sub-task.
	Current int

	// Total represents the progress of the overall task.
	Total int

	// Max is a constant denominator used to calculate the progress percentage.
	Max int
}

ProgressBarLine represents a "PRGV" output line, which describes the progress of a task and sub-task.

See https://makemkv.com/developers/usage.txt.

func ParseProgressBarLine

func ParseProgressBarLine(s string) (*ProgressBarLine, error)

ParseProgressBarLine parses the string that follows "PRGV:" in the output of makemkvcon.

func (*ProgressBarLine) CurrentProgress

func (l *ProgressBarLine) CurrentProgress() float64

CurrentProgress returns the progress of the current sub-task as a percentage.

func (*ProgressBarLine) Kind

func (l *ProgressBarLine) Kind() LineKind

func (*ProgressBarLine) TotalProgress

func (l *ProgressBarLine) TotalProgress() float64

TotalProgress returns the progress of the overall task as a percentage.

type Stream

type Stream struct {
	// Index is the index given by makemkv.
	Index int

	Info
}

Stream is a video, audio or subtitles stream. A Title is made up of multiple Streams.

func (*Stream) Type

func (s *Stream) Type() defs.TypeCode

Type returns the type code of the stream.

type StreamInfoLine

type StreamInfoLine struct {
	TitleIndex  int
	StreamIndex int

	*InfoLine
}

StreamInfoLine represents an "SINFO" makemkvcon output line, which provides information about a stream.

See https://makemkv.com/developers/usage.txt.

func ParseStreamInfoLine

func ParseStreamInfoLine(s string) (*StreamInfoLine, error)

ParseStreamInfoLine parses the string that follows "SINFO:" in the output of makemkvcon.

func (*StreamInfoLine) Kind

func (l *StreamInfoLine) Kind() LineKind

type Title

type Title struct {
	// Index is the index given by makemkv. Title numbers appear to be
	// deterministic if makemkv is run with the same --minlength argument.
	Index int

	Info

	Streams []*Stream
}

Title is a collection of Streams plus some metadata. It is identified by an index number. A Disc is made up of multiple Titles.

Streams may be video, audio, or subtitles.

func (*Title) GetStream

func (t *Title) GetStream(index int) *Stream

GetStream returns the stream with the given index, creating it (and all prior streams) as necessary.

type TitleCountLine

type TitleCountLine struct {
	Count int
}

TitleCountLine represents a "TCOUNT" makemkvcon output line, which describes the number of titles found on a disc.

See https://makemkv.com/developers/usage.txt.

func ParseTitleCountLine

func ParseTitleCountLine(s string) (*TitleCountLine, error)

ParseTitleCountLine parses the string that follows "TCOUNT:" in the output of makemkvcon.

func (*TitleCountLine) Kind

func (l *TitleCountLine) Kind() LineKind

type TitleInfoLine

type TitleInfoLine struct {
	TitleIndex int

	*InfoLine
}

TitleInfoLine represents a makemkvcon "TINFO" output line, which provides information about a title.

See https://makemkv.com/developers/usage.txt.

func ParseTitleInfoLine

func ParseTitleInfoLine(s string) (*TitleInfoLine, error)

ParseTitleInfoLine parses the string that follows "TINFO:" in the output of makemkvcon.

func (*TitleInfoLine) Kind

func (l *TitleInfoLine) Kind() LineKind

type TotalProgressLine

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

TotalProgressLine represents a makemkvcon "PRGT" output line, which describes the overall task being performed.

See https://makemkv.com/developers/usage.txt.

func ParseTotalProgressLine

func ParseTotalProgressLine(s string) (*TotalProgressLine, error)

ParseTotalProgressLine parses the string that follows "PRGT:" in the output of makemkvcon.

func (*TotalProgressLine) Kind

func (l *TotalProgressLine) Kind() LineKind

Directories

Path Synopsis
Package defs defines a subset of attributes and codes used by makemkv to describe discs, titles, and streams.
Package defs defines a subset of attributes and codes used by makemkv to describe discs, titles, and streams.

Jump to

Keyboard shortcuts

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