forked from martinlindhe/subtitles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
45 lines (42 loc) · 886 Bytes
/
filter.go
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
37
38
39
40
41
42
43
44
45
package subtitles
import (
"fmt"
)
// FilterCaptions pass the captions through a filter function
func (subtitle *Subtitle) FilterCaptions(filter string) {
switch filter {
case "all":
subtitle.filterCapitalization()
subtitle.filterHTML()
subtitle.filterOCR()
subtitle.filterStyle()
case "caps":
subtitle.filterCapitalization()
case "html":
subtitle.filterHTML()
case "ocr":
subtitle.filterOCR()
case "style":
subtitle.filterStyle()
case "none":
default:
fmt.Printf("Unrecognized filter name: %s\n", filter)
}
subtitle.cleanEmptyLines()
}
func (subtitle *Subtitle) cleanEmptyLines() {
var ret []Caption
for _, cap := range subtitle.Captions {
var lines []string
for _, v := range cap.Text {
if len(v) > 0 {
lines = append(lines, v)
}
}
if len(lines) > 0 {
cap.Text = lines
ret = append(ret, cap)
}
}
subtitle.Captions = ret
}