Skip to content

Commit

Permalink
Merge 4ae3e61 into 9f2ecac
Browse files Browse the repository at this point in the history
  • Loading branch information
mysamimi committed Dec 4, 2021
2 parents 9f2ecac + 4ae3e61 commit f37760b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions subtitles.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,20 @@ func (s *Subtitles) Order() {
var tmp = s.Items[index-1]
s.Items[index-1] = s.Items[index]
s.Items[index] = tmp
s.Items[index].Index = index
swapped = true
}
}
}
}

// FixIndex fix item index
func (s *Subtitles) FixIndex() {
for i := 0; i < len(s.Items); i++ {
s.Items[i].Index = i + 1
}
}

// RemoveStyling removes the styling from the subtitles
func (s *Subtitles) RemoveStyling() {
s.Regions = map[string]*Region{}
Expand Down
4 changes: 2 additions & 2 deletions webvtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) {
}

// Loop through subtitles
for index, item := range s.Items {
for _, item := range s.Items {
// Add comments
if len(item.Comments) > 0 {
c = append(c, []byte("NOTE ")...)
Expand All @@ -350,7 +350,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) {
}

// Add time boundaries
c = append(c, []byte(strconv.Itoa(index+1))...)
c = append(c, []byte(strconv.Itoa(item.Index))...)
c = append(c, bytesLineSeparator...)
c = append(c, []byte(formatDurationWebVTT(item.StartAt))...)
c = append(c, bytesWebVTTTimeBoundariesSeparator...)
Expand Down

0 comments on commit f37760b

Please sign in to comment.