-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfilter_merge.go
More file actions
36 lines (30 loc) · 769 Bytes
/
Copy pathfilter_merge.go
File metadata and controls
36 lines (30 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package subtitles
// filterMerge combines all separate captions with same time spawn into one caption
func (subtitle *Subtitle) filterMerge() *Subtitle {
idxToRemove := []int{}
for i, cap := range subtitle.Captions {
for j, pCap := range subtitle.Captions[0:i] {
if pCap.Start == cap.Start && pCap.End == cap.End {
subtitle.Captions[j].Text = append(pCap.Text, cap.Text...)
idxToRemove = append(idxToRemove, i)
break
}
}
}
newCaptions := []Caption{}
for i, cap := range subtitle.Captions {
if !contains(idxToRemove, i) {
newCaptions = append(newCaptions, cap)
}
}
subtitle.Captions = newCaptions
return subtitle
}
func contains(s []int, e int) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}