Skip to content

Commit

Permalink
Added teletext
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Renard committed Feb 16, 2018
1 parent 0074155 commit 46d48da
Show file tree
Hide file tree
Showing 4 changed files with 1,125 additions and 15 deletions.
5 changes: 3 additions & 2 deletions astisub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var (
fragmentDuration = flag.Duration("f", 0, "the fragment duration")
inputPath = astiflag.Strings{}
teletextPage = flag.Int("p", 0, "the teletext page")
outputPath = flag.String("o", "", "the output path")
syncDuration = flag.Duration("s", 0, "the sync duration")
)
Expand All @@ -36,7 +37,7 @@ func main() {
// Open first input path
var sub *astisub.Subtitles
var err error
if sub, err = astisub.OpenFile(inputPath[0]); err != nil {
if sub, err = astisub.Open(astisub.Options{Filename: inputPath[0], Teletext: astisub.TeletextOptions{Page: *teletextPage}}); err != nil {
astilog.Fatalf("%s while opening %s", err, inputPath[0])
}

Expand Down Expand Up @@ -68,7 +69,7 @@ func main() {

// Open second input path
var sub2 *astisub.Subtitles
if sub2, err = astisub.OpenFile(inputPath[1]); err != nil {
if sub2, err = astisub.Open(astisub.Options{Filename: inputPath[1], Teletext: astisub.TeletextOptions{Page: *teletextPage}}); err != nil {
astilog.Fatalf("%s while opening %s", err, inputPath[1])
}

Expand Down
39 changes: 28 additions & 11 deletions subtitles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ var (
bytesSpace = []byte(" ")
)

// Colors
var (
ColorBlack = &Color{}
ColorBlue = &Color{Blue: 255}
ColorCyan = &Color{Blue: 255, Green: 255}
ColorGreen = &Color{Green: 255}
ColorMagenta = &Color{Blue: 255, Red: 255}
ColorRed = &Color{Red: 255}
ColorYellow = &Color{Green: 255, Red: 255}
ColorWhite = &Color{Blue: 255, Green: 255, Red: 255}
)

// Errors
var (
ErrInvalidExtension = errors.New("astisub: invalid extension")
Expand All @@ -32,31 +44,30 @@ var Now = func() time.Time {

// Options represents open or write options
type Options struct {
Page int
PID int
Src string
Filename string
Teletext TeletextOptions
}

// Open opens a subtitle file based on options
// Open opens a subtitle reader based on options
func Open(o Options) (s *Subtitles, err error) {
// Open the file
var f *os.File
if f, err = os.Open(o.Src); err != nil {
err = errors.Wrapf(err, "astisub: opening %s failed", o.Src)
if f, err = os.Open(o.Filename); err != nil {
err = errors.Wrapf(err, "astisub: opening %s failed", o.Filename)
return
}
defer f.Close()

// Parse the content
switch filepath.Ext(o.Src) {
switch filepath.Ext(o.Filename) {
case ".srt":
s, err = ReadFromSRT(f)
case ".ssa", ".ass":
s, err = ReadFromSSA(f)
case ".stl":
s, err = ReadFromSTL(f)
case ".ts":
s, err = ReadFromTeletext(f, o.PID, o.Page)
s, err = ReadFromTeletext(f, o.Teletext)
case ".ttml":
s, err = ReadFromTTML(f)
case ".vtt":
Expand All @@ -68,8 +79,8 @@ func Open(o Options) (s *Subtitles, err error) {
}

// OpenFile opens a file regardless of other options
func OpenFile(src string) (*Subtitles, error) {
return Open(Options{Src: src})
func OpenFile(filename string) (*Subtitles, error) {
return Open(Options{Filename: filename})
}

// Subtitles represents an ordered list of items with formatting
Expand Down Expand Up @@ -139,7 +150,7 @@ func (c *Color) String(base int) string {
}

// StyleAttributes represents style attributes
// TODO Merge attributes
// TODO Convert styles+inline styles form different formats as well
type StyleAttributes struct {
SSAAlignment *int
SSAAlphaLevel *float64
Expand Down Expand Up @@ -167,6 +178,12 @@ type StyleAttributes struct {
SSASpacing *int // pixels
SSAStrikeout *bool
SSAUnderline *bool
TeletextColor *Color
TeletextDoubleHeight *bool
TeletextDoubleSize *bool
TeletextDoubleWidth *bool
TeletextSpacesAfter *int
TeletextSpacesBefore *int
TTMLBackgroundColor string
TTMLColor string
TTMLDirection string
Expand Down
Loading

0 comments on commit 46d48da

Please sign in to comment.