Skip to content

Commit 695f068

Browse files
committed
rework to only export a few functions
1 parent c230a8e commit 695f068

32 files changed

+417
-472
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:
2+
go test -v

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Subber is a cli tool and library for reading,
44
writing and manipulating .srt subtitle files written in Go
55

6+
WARNING: The API is unstable, work in progress!
67

78
### Features
89

@@ -22,10 +23,10 @@ and the `subber` cli app automates this task.
2223

2324
# Installation
2425

25-
Assuming golang is installed on your system:
26+
To install the command line:
2627

2728
```
28-
go install github.com/martinlindhe/subber
29+
go install github.com/martinlindhe/subber/subber
2930
```
3031

3132

filter/caps.go renamed to caps.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
package filter
1+
package subber
22

33
import (
4-
"fmt"
4+
"log"
55
"strings"
6-
7-
"github.com/martinlindhe/subber/caption"
86
)
97

10-
// CapsFixer converts "ALL CAPS" text into "Initial letter capped"
11-
func CapsFixer(captions []caption.Caption) []caption.Caption {
8+
// filterCapitalization converts "ALL CAPS" text into "Initial letter capped"
9+
func filterCapitalization(captions []caption) []caption {
1210

1311
for _, cap := range captions {
1412
for i, line := range cap.Text {
1513

1614
clean := ucFirst(line)
1715

1816
if clean != cap.Text[i] {
19-
fmt.Printf("[caps] %s -> %s\n", cap.Text[i], clean)
17+
log.Printf("[caps] %s -> %s\n", cap.Text[i], clean)
2018
cap.Text[i] = clean
2119
}
2220
}

caps_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package subber
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestFilterCapitalization(t *testing.T) {
10+
11+
var in = []caption{
12+
{
13+
Seq: 1,
14+
Start: makeTime(0, 0, 4, 630),
15+
End: makeTime(0, 0, 6, 18),
16+
Text: []string{"GO NINJA!", "NINJA GO!"},
17+
},
18+
}
19+
20+
var expected = []caption{
21+
{
22+
1,
23+
makeTime(0, 0, 4, 630),
24+
makeTime(0, 0, 6, 18),
25+
[]string{"Go ninja!", "Ninja go!"},
26+
},
27+
}
28+
29+
assert.Equal(t, expected, filterCapitalization(in))
30+
}

caption.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package subber
2+
3+
import "time"
4+
5+
// caption represents one subtitle block
6+
type caption struct {
7+
Seq int
8+
Start time.Time
9+
End time.Time
10+
Text []string
11+
}

caption/caption.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

caption/caption_test.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

caption_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package subber
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestRenderTime(t *testing.T) {
10+
11+
cap := caption{
12+
1,
13+
makeTime(18, 40, 22, 110),
14+
makeTime(18, 41, 20, 123),
15+
[]string{"<i>Go ninja!</i>"},
16+
}
17+
18+
assert.Equal(t, "18:40:22,110 --> 18:41:20,123", cap.srtTime())
19+
}

cleaner/cleaner.go renamed to cleaner.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
package cleaner
1+
package subber
22

33
import (
4-
"fmt"
4+
"log"
55
"strings"
6-
7-
"github.com/martinlindhe/subber/caption"
86
)
97

8+
// CleanupSub performs cleanup on .srt data, returning a string. caller is responsible for passing UTF8 string
9+
func CleanupSub(utf8 string, filterName string, keepAds bool) (string, error) {
10+
11+
captions := parseSrt(utf8)
12+
if !keepAds {
13+
captions = removeAds(captions)
14+
}
15+
16+
captions = filterSubs(captions, filterName)
17+
18+
out := renderSrt(captions)
19+
20+
return out, nil
21+
}
22+
1023
// RemoveAds removes advertisement from the subtitles
11-
func RemoveAds(subs []caption.Caption) []caption.Caption {
24+
func removeAds(subs []caption) []caption {
1225

13-
var res []caption.Caption
26+
var res []caption
1427

1528
ads := []string{
1629

@@ -79,7 +92,7 @@ func RemoveAds(subs []caption.Caption) []caption.Caption {
7992
for _, adLine := range ads {
8093
if !isAd && strings.Contains(x, adLine) {
8194
isAd = true
82-
fmt.Println("[ads]", orgSeq, sub.Text, "matched", adLine)
95+
log.Println("[ads]", orgSeq, sub.Text, "matched", adLine)
8396
break
8497
}
8598
}

cleaner/cleaner_test.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)