Documentation
¶
Overview ¶
Package makemkv provides a Go interface to makemkvcon, the command-line tool bundled with MakeMKV.
The central type is Con, which wraps makemkvcon and exposes three operations: listing drives (Con.ListDrives), scanning a disc (Con.ScanDrive), and backing up a title (Con.BackupTitle). All three stream progress lines back to the caller via Go's iter.Seq2 so the UI can update in real time without waiting for the command to finish.
Disc metadata (titles, streams, attributes) is modeled by Disc, Title, and Stream. Attribute IDs and their meanings are defined in the defs subpackage.
Index ¶
- Variables
- func FindExe() (string, error)
- func Grammar() string
- func Maximums[S []E, E any, V cmp.Ordered](s S, f func(E) (V, error)) S
- func ParseDuration(s string) (time.Duration, error)
- func ParseLines(r io.Reader) iter.Seq2[*Line, error]
- func Reg(key string) error
- type Attribute
- type Con
- func (c *Con) BackupTitle(ctx context.Context, driveIndex, titleIndex int, dstDir string) (iter.Seq2[*Line, error], error)
- func (c *Con) ListDrives(ctx context.Context) (*LineIterator[[]*DriveScan], error)
- func (c *Con) RunCmd(ctx context.Context, args ...string) (iter.Seq2[*Line, error], error)
- func (c *Con) RunDefaultCmd(ctx context.Context, args ...string) (iter.Seq2[*Line, error], error)
- func (c *Con) ScanDrive(ctx context.Context, driveIndex int) (*LineIterator[*Disc], error)
- type Config
- type CurrentSubtask
- type CurrentTask
- type Disc
- type DiscInfo
- type DriveScan
- type Info
- func (info Info) GetAttr(id defs.Attr) (string, error)
- func (info Info) GetAttrDefault(id defs.Attr, defaultValue string) string
- func (info Info) GetAttrDuration(id defs.Attr) (time.Duration, error)
- func (info Info) GetAttrInt(id defs.Attr) (int, error)
- func (info Info) GetCode(id defs.Attr) (int, error)
- func (info Info) GetCodeDefault(id defs.Attr, defaultValue int) int
- type Line
- type LineIterator
- type Message
- type Output
- type Progress
- type Str
- type Stream
- type StreamInfo
- type Task
- type Title
- type TitleCount
- type TitleInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when something is not found. ErrNotFound = fmt.Errorf("not found") )
Functions ¶
func FindExe ¶
FindExe attempts to return the path of the makemkvcon executable on Linux and Darwin operating systems.
func Grammar ¶ added in v0.5.0
func Grammar() string
Grammar returns an EBNF representation of the supported grammar.
func Maximums ¶
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 ¶
ParseDuration parses a duration string with hours, minutes and seconds values separated by colons like "1:22:33".
func ParseLines ¶
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 Attribute ¶ added in v0.5.0
type Attribute struct {
Pos lexer.Position
// ID is an integer that identifies the attribute.
ID int `@Int`
// Code is an integer that corresponds to Value, if Value is an enumeration.
Code int `"," @Int`
// Value is the value of the attribute identified by ID.
Value Str `"," @String`
}
Attribute is the common representation of the "CINFO", "TINFO" and "SINFO" makemkvcon output lines, which describe an attribute of a disc, title, or stream.
type Con ¶
type Con struct {
// contains filtered or unexported fields
}
Con is the interface for running makemkvcon commands.
func New ¶
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 ¶
ListDrives returns the list of drives detected by makemkvcon.
func (*Con) RunCmd ¶
RunCmd runs an arbitrary makemkvcon command with the given args. It terminates when the context is canceled or the command terminates.
func (*Con) RunDefaultCmd ¶
RunDefaultCmd calls RunCmd with default args in addition to the specified args. Default args include -r (machine-readable output), --minlength, and --profile.
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.
type CurrentSubtask ¶ added in v0.5.0
CurrentSubtask represents a makemkvcon "PRGC" output line, which describes the current sub-task.
type CurrentTask ¶ added in v0.5.0
CurrentTask represents a makemkvcon "PRGT" output line, which describes the overall task being performed.
type Disc ¶
Disc is a sequence of titles plus some metadata.
func (*Disc) GetTitle ¶
GetTitle returns the title with the given index, creating it (and previous titles) if necessary.
func (*Disc) TitleCount ¶
TitleCount returns the number of titles on the disc.
func (*Disc) TitlesWithAngle ¶
TitlesWithAngle returns all titles with the given angle.
func (*Disc) TitlesWithLongestDuration ¶
TitlesWithLongestDuration returns all titles that tie for maximum duration.
func (*Disc) TitlesWithMostChapters ¶
TitlesWithMostChapters returns all titles that tie for maximum number of chapters.
func (*Disc) TitlesWithMostStreams ¶
TitlesWithMostStreams returns all titles that tie for maximum number of streams.
type DiscInfo ¶ added in v0.5.0
DiscInfoLine represents a makemkvcon "CINFO" output line, which provides information about a disc.
type DriveScan ¶ added in v0.5.0
type DriveScan struct {
Pos lexer.Position
Index int `@Int`
Visible int `"," @Int`
Enabled int `"," @Int`
Flags int `"," @Int`
DriveName Str `"," @String`
DiscTitle Str `"," @String`
VolumeName Str `"," @String`
}
DriveScan represents a makemkvcon "DRV" output line, which describes a disc drive.
type Info ¶
type Info []*Attribute
Info is a slice of related Attributes.
func (Info) GetAttr ¶
GetAttr returns the Value of the Attribute where ID matches id or ErrNotFound if such an attribute does not exist.
func (Info) GetAttrDefault ¶
GetAttrDefault returns the Value of the Attribute where ID matches id or defaultValue if such an attribute does not exist.
func (Info) GetAttrDuration ¶
GetAttrDuration is like GetAttr, except it also attempts to convert the value to a time.Duration.
func (Info) GetAttrInt ¶
GetAttrInto is like GetAttr, except it also attempts to convert the Value to an integer.
type Line ¶
type Line struct {
Pos lexer.Position
DriveScan *DriveScan ` "DRV" ":" @@`
Message *Message `| "MSG" ":" @@`
DiscInfo *DiscInfo `| "CINFO" ":" @@`
TitleInfo *TitleInfo `| "TINFO" ":" @@`
StreamInfo *StreamInfo `| "SINFO" ":" @@`
CurrentTask *CurrentTask `| "PRGT" ":" @@`
CurrentSubtask *CurrentSubtask `| "PRGC" ":" @@`
Progress *Progress `| "PRGV" ":" @@`
TitleCount *TitleCount `| "TCOUNT" ":" @@`
}
Line represents a single line of output from makemkvcon.
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 Message ¶ added in v0.5.0
type Message struct {
Pos lexer.Position
Code int `@Int`
Flags int `"," @Int`
NumParams int `"," @Int`
Message Str `"," @String`
Format Str `"," @String`
Params []Str `( "," @String )*`
}
Message represents a makemkvcon "MSG" output line, which is an informational logging line.
type Output ¶ added in v0.5.0
Output represents the multi-line output of makemkvcon.
See https://makemkv.com/developers/usage.txt.
func ParseOutput ¶ added in v0.5.0
ParseOutput parses multi-line output from makemkvcon.
type Progress ¶ added in v0.5.0
type Progress struct {
Pos lexer.Position
SubtaskValue int `@Int`
TaskValue int `"," @Int`
// Max is a constant denominator used to calculate the progress percentage.
Max int `"," @Int`
}
Progress represents a makemkvcon "PRGV" output line, which describes the progress of a task and sub-task.
func (*Progress) SubtaskProgress ¶ added in v0.5.0
SubtaskProgress returns the progress of the current sub-task as a percentage.
func (*Progress) TaskProgress ¶ added in v0.5.0
TaskProgress returns the progress of the overall task as a percentage.
type StreamInfo ¶ added in v0.5.0
type StreamInfo struct {
Pos lexer.Position
TitleIndex int `@Int`
StreamIndex int `"," @Int`
Attribute *Attribute `"," @@`
}
StreamInfo represents an "SINFO" makemkvcon output line, which provides information about a stream.
type Task ¶ added in v0.5.0
Task is the common representation for makemkvcon "PRGT" and "PRGC" output lines, which describe the current task and subtask, respectively.
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.
type TitleCount ¶ added in v0.5.0
TitleCount represents a "TCOUNT" makemkvcon output line, which describes the number of titles found on a disc.