Skip to content

Commit

Permalink
Added .ssa/.ass
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Dec 16, 2017
1 parent 40fcb94 commit dc44db4
Show file tree
Hide file tree
Showing 15 changed files with 1,629 additions and 195 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
Thumbs.db
.idea/
cover*
test
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -5,7 +5,7 @@

This is a Golang library to manipulate subtitles.

It allows you to manipulate `srt`, `stl`, `ttml` and `webvtt` files for now.
It allows you to manipulate `srt`, `stl`, `ttml`, `ssa/ass` and `webvtt` files for now.

Available operations are `parsing`, `writing`, `syncing`, `fragmenting`, `unfragmenting` and `merging`.

Expand Down Expand Up @@ -78,6 +78,6 @@ If **astisub** has been installed properly you can:
- [x] .ttml
- [x] .vtt
- [x] .stl
- [x] .ssa/.ass
- [ ] .teletext
- [ ] .ssa/.ass
- [ ] .smi
16 changes: 8 additions & 8 deletions srt.go
Expand Up @@ -22,7 +22,7 @@ var (

// parseDurationSRT parses an .srt duration
func parseDurationSRT(i string) (time.Duration, error) {
return parseDuration(i, ",")
return parseDuration(i, ",", 3)
}

// ReadFromSRT parses an .srt content
Expand All @@ -46,15 +46,15 @@ func ReadFromSRT(i io.Reader) (o *Subtitles, err error) {
// Remove trailing empty lines
if len(s.Lines) > 0 {
for i := len(s.Lines) - 1; i >= 0; i-- {
if len(s.Lines[i]) > 0 {
for j := len(s.Lines[i]) - 1; j >= 0; j-- {
if len(s.Lines[i][j].Text) == 0 {
s.Lines[i] = s.Lines[i][:j]
if len(s.Lines[i].Items) > 0 {
for j := len(s.Lines[i].Items) - 1; j >= 0; j-- {
if len(s.Lines[i].Items[j].Text) == 0 {
s.Lines[i].Items = s.Lines[i].Items[:j]
} else {
break
}
}
if len(s.Lines[i]) == 0 {
if len(s.Lines[i].Items) == 0 {
s.Lines = s.Lines[:i]
}

Expand All @@ -80,15 +80,15 @@ func ReadFromSRT(i io.Reader) (o *Subtitles, err error) {
o.Items = append(o.Items, s)
} else {
// Add text
s.Lines = append(s.Lines, []LineItem{{Text: line}})
s.Lines = append(s.Lines, Line{Items: []LineItem{{Text: line}}})
}
}
return
}

// formatDurationSRT formats an .srt duration
func formatDurationSRT(i time.Duration) string {
return formatDuration(i, ",")
return formatDuration(i, ",", 3)
}

// WriteToSRT writes subtitles in .srt format
Expand Down

0 comments on commit dc44db4

Please sign in to comment.