parser

package
v0.0.0-...-42431c4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorBlack   = &Color{}
	ColorBlue    = &Color{Blue: 255}
	ColorCyan    = &Color{Blue: 255, Green: 255}
	ColorGray    = &Color{Blue: 128, Green: 128, Red: 128}
	ColorGreen   = &Color{Green: 128}
	ColorLime    = &Color{Green: 255}
	ColorMagenta = &Color{Blue: 255, Red: 255}
	ColorMaroon  = &Color{Red: 128}
	ColorNavy    = &Color{Blue: 128}
	ColorOlive   = &Color{Green: 128, Red: 128}
	ColorPurple  = &Color{Blue: 128, Red: 128}
	ColorRed     = &Color{Red: 255}
	ColorSilver  = &Color{Blue: 192, Green: 192, Red: 192}
	ColorTeal    = &Color{Blue: 128, Green: 128}
	ColorYellow  = &Color{Green: 255, Red: 255}
	ColorWhite   = &Color{Blue: 255, Green: 255, Red: 255}
)

Colors

View Source
var (
	ErrInvalidExtension   = errors.New("astisub: invalid extension")
	ErrNoSubtitlesToWrite = errors.New("astisub: no subtitles to write")
)

Errors

View Source
var (
	JustificationUnchanged = Justification(1)
	JustificationLeft      = Justification(2)
	JustificationCentered  = Justification(3)
	JustificationRight     = Justification(4)
)
View Source
var (
	BytesBOM = []byte{239, 187, 191}
)

Bytes

View Source
var Now = func() time.Time {
	return time.Now()
}

Now allows testing functions using it

Functions

This section is empty.

Types

type Color

type Color struct {
	Alpha, Blue, Green, Red uint8
}

Color represents a color

func (*Color) SSAString

func (c *Color) SSAString() string

SSAString expresses the color as an SSA string

func (*Color) TTMLString

func (c *Color) TTMLString() string

TTMLString expresses the color as a TTML string

type Item

type Item struct {
	Comments    []string
	Index       int
	EndAt       time.Duration
	InlineStyle *StyleAttributes
	Lines       []Line
	Region      *Region
	StartAt     time.Duration
	Style       *Style
}

Item represents a text to show between 2 time boundaries with formatting

func (Item) String

func (i Item) String() string

String implements the Stringer interface

type Justification

type Justification int

type Line

type Line struct {
	Items     []LineItem
	VoiceName string
}

Line represents a set of formatted line items

func (Line) String

func (l Line) String() string

String implement the Stringer interface

type LineItem

type LineItem struct {
	InlineStyle *StyleAttributes
	Style       *Style
	Text        string
}

LineItem represents a formatted line item

type Metadata

type Metadata struct {
	Comments                                            []string
	Framerate                                           int
	Language                                            string
	SSACollisions                                       string
	SSAOriginalEditing                                  string
	SSAOriginalScript                                   string
	SSAOriginalTiming                                   string
	SSAOriginalTranslation                              string
	SSAPlayDepth                                        *int
	SSAPlayResX, SSAPlayResY                            *int
	SSAScriptType                                       string
	SSAScriptUpdatedBy                                  string
	SSASynchPoint                                       string
	SSATimer                                            *float64
	SSAUpdateDetails                                    string
	SSAWrapStyle                                        string
	STLCountryOfOrigin                                  string
	STLCreationDate                                     *time.Time
	STLDisplayStandardCode                              string
	STLMaximumNumberOfDisplayableCharactersInAnyTextRow *int
	STLMaximumNumberOfDisplayableRows                   *int
	STLPublisher                                        string
	STLRevisionDate                                     *time.Time
	STLSubtitleListReferenceCode                        string
	STLTimecodeStartOfProgramme                         time.Duration
	Title                                               string
	TTMLCopyright                                       string
}

Metadata represents metadata TODO Merge attributes

type Options

type Options struct {
	Filename string
}

Options represents open or write options

type Region

type Region struct {
	ID          string
	InlineStyle *StyleAttributes
	Style       *Style
}

Region represents a subtitle's region

type SSAOptions

type SSAOptions struct {
	OnUnknownSectionName func(name string)
	OnInvalidLine        func(line string)
}

SSAOptions

type Style

type Style struct {
	ID          string
	InlineStyle *StyleAttributes
	Style       *Style
}

Style represents a subtitle's style

type StyleAttributes

type StyleAttributes struct {
	SSAAlignment       *int
	SSAAlphaLevel      *float64
	SSAAngle           *float64 // degrees
	SSABackColour      *Color
	SSABold            *bool
	SSABorderStyle     *int
	SSAEffect          string
	SSAEncoding        *int
	SSAFontName        string
	SSAFontSize        *float64
	SSAItalic          *bool
	SSALayer           *int
	SSAMarginLeft      *int // pixels
	SSAMarginRight     *int // pixels
	SSAMarginVertical  *int // pixels
	SSAMarked          *bool
	SSAOutline         *float64 // pixels
	SSAOutlineColour   *Color
	SSAPrimaryColour   *Color
	SSAScaleX          *float64 // %
	SSAScaleY          *float64 // %
	SSASecondaryColour *Color
	SSAShadow          *float64 // pixels
	SSASpacing         *float64 // pixels
	SSAStrikeout       *bool
	SSAUnderline       *bool
	STLBoxing          *bool
	STLItalics         *bool
	STLJustification   *Justification
	//STLPosition          *STLPosition
	STLUnderline         *bool
	TeletextColor        *Color
	TeletextDoubleHeight *bool
	TeletextDoubleSize   *bool
	TeletextDoubleWidth  *bool
	TeletextSpacesAfter  *int
	TeletextSpacesBefore *int
	// TODO Use pointers with real types below
	TTMLBackgroundColor  *string // https://htmlcolorcodes.com/fr/
	TTMLColor            *string
	TTMLDirection        *string
	TTMLDisplay          *string
	TTMLDisplayAlign     *string
	TTMLExtent           *string
	TTMLFontFamily       *string
	TTMLFontSize         *string
	TTMLFontStyle        *string
	TTMLFontWeight       *string
	TTMLLineHeight       *string
	TTMLOpacity          *string
	TTMLOrigin           *string
	TTMLOverflow         *string
	TTMLPadding          *string
	TTMLShowBackground   *string
	TTMLTextAlign        *string
	TTMLTextDecoration   *string
	TTMLTextOutline      *string
	TTMLUnicodeBidi      *string
	TTMLVisibility       *string
	TTMLWrapOption       *string
	TTMLWritingMode      *string
	TTMLZIndex           *int
	WebVTTAlign          string
	WebVTTItalics        bool
	WebVTTLine           string
	WebVTTLines          int
	WebVTTPosition       string
	WebVTTRegionAnchor   string
	WebVTTScroll         string
	WebVTTSize           string
	WebVTTVertical       string
	WebVTTViewportAnchor string
	WebVTTWidth          string
}

StyleAttributes represents style attributes

type Subtitles

type Subtitles struct {
	Items    []*Item
	Metadata *Metadata
	Regions  map[string]*Region
	Styles   map[string]*Style
}

Subtitles represents an ordered list of items with formatting

func NewSubtitles

func NewSubtitles() *Subtitles

NewSubtitles creates new subtitles

func Open

func Open(o Options) (s *Subtitles, err error)

Open opens a subtitle reader based on options

func OpenFile

func OpenFile(filename string) (*Subtitles, error)

OpenFile opens a file regardless of other options

func ReadFromSSA

func ReadFromSSA(i io.Reader) (o *Subtitles, err error)

ReadFromSSA parses an .ssa content

func ReadFromSSAWithOptions

func ReadFromSSAWithOptions(i io.Reader, opts SSAOptions) (o *Subtitles, err error)

ReadFromSSAWithOptions parses an .ssa content

func (*Subtitles) Add

func (s *Subtitles) Add(d time.Duration)

Add adds a duration to each time boundaries. As in the time package, duration can be negative.

func (*Subtitles) ApplyLinearCorrection

func (s *Subtitles) ApplyLinearCorrection(actual1, desired1, actual2, desired2 time.Duration)

ApplyLinearCorrection applies linear correction

func (Subtitles) Duration

func (s Subtitles) Duration() time.Duration

Duration returns the subtitles duration

func (*Subtitles) ForceDuration

func (s *Subtitles) ForceDuration(d time.Duration, addDummyItem bool)

ForceDuration updates the subtitles duration. If requested duration is bigger, then we create a dummy item. If requested duration is smaller, then we remove useless items and we cut the last item or add a dummy item.

func (*Subtitles) Fragment

func (s *Subtitles) Fragment(f time.Duration)

Fragment fragments subtitles with a specific fragment duration

func (Subtitles) IsEmpty

func (s Subtitles) IsEmpty() bool

IsEmpty returns whether the subtitles are empty

func (*Subtitles) Merge

func (s *Subtitles) Merge(i *Subtitles)

Merge merges subtitles i into subtitles

func (*Subtitles) Optimize

func (s *Subtitles) Optimize()

Optimize optimizes subtitles

func (*Subtitles) Order

func (s *Subtitles) Order()

Order orders items

func (*Subtitles) RemoveStyling

func (s *Subtitles) RemoveStyling()

RemoveStyling removes the styling from the subtitles

func (*Subtitles) Unfragment

func (s *Subtitles) Unfragment()

Unfragment unfragments subtitles

func (Subtitles) Write

func (s Subtitles) Write(dst string) (err error)

Write writes subtitles to a file

func (Subtitles) WriteToSSA

func (s Subtitles) WriteToSSA(o io.Writer) (err error)

WriteToSSA writes subtitles in .ssa format

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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