Skip to content

Commit c55001e

Browse files
committed
cmd/subber: add -o switch
1 parent 724b4b5 commit c55001e

File tree

5 files changed

+23
-157
lines changed

5 files changed

+23
-157
lines changed

cmd/dcsub2srt/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# About
22

3-
Command line util to convert DCSubtitles into .srt format
3+
Used to be a separate tool to converts a DCSubtitles to .srt.
44

5+
Instead, use:
56

6-
# Installation
7-
```
8-
go get -u github.com/martinlindhe/subtitles/cmd/dcsub2srt
9-
```
7+
subber vid.xml -o vid.srt
8+
9+
See [subber](../subber)

cmd/dcsub2srt/main.go

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

cmd/ssa2srt/README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
# About
22

3-
Converts a .ssa to .srt
3+
Used to be a separate tool to converts a .ssa to .srt.
44

5+
Instead, use:
56

6-
# Installation
7+
subber vid.ssa -o vid.srt
78

8-
```
9-
go install github.com/martinlindhe/subtitles/cmd/ssa2srt
10-
```
11-
12-
13-
# Usage
14-
15-
```
16-
$ ssa2srt subtile.ssa
17-
```
9+
See [subber](../subber)

cmd/ssa2srt/ssa2srt.go

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

cmd/subber/subber.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
var (
1616
file = kingpin.Arg("file", "A .srt (to clean) or video file (to fetch subs).").Required().File()
17+
outFile = kingpin.Flag("output-file", "A .srt (to clean) or video file (to fetch subs).").Short('o').String()
1718
verbose = kingpin.Flag("verbose", "Verbose mode (more output).").Short('v').Bool()
1819
quiet = kingpin.Flag("quiet", "Quiet mode (less output).").Short('q').Bool()
1920
dontTouch = kingpin.Flag("dont-touch", "Do not try to process .srt (write directly to disk).").Bool()
@@ -37,6 +38,7 @@ func main() {
3738
}
3839

3940
inFileName := (*file).Name()
41+
outFileName := *outFile
4042

4143
// skip "hidden" .dotfiles
4244
baseName := filepath.Base(inFileName)
@@ -45,7 +47,7 @@ func main() {
4547
os.Exit(1)
4648
}
4749

48-
err := action(inFileName)
50+
err := action(inFileName, outFileName)
4951
if err != nil {
5052
fmt.Println("An error occured:", err)
5153
}
@@ -57,20 +59,16 @@ func verboseMessage(args ...interface{}) {
5759
}
5860
}
5961

60-
func parseAndWriteSubFile(fileName string, filterName string, keepAds bool, sync int) error {
61-
62-
data, err := ioutil.ReadFile(fileName)
62+
func parseAndWriteSubFile(inFileName, outFileName string, filterName string, keepAds bool, sync int) error {
63+
data, err := ioutil.ReadFile(inFileName)
6364
if err != nil {
6465
return err
6566
}
66-
6767
out, err := cleanupSub(data, filterName, keepAds, sync)
6868
if err != nil {
6969
return err
7070
}
71-
writeText(fileName, *skipBackups, out)
72-
73-
return nil
71+
return writeText(outFileName, *skipBackups, out)
7472
}
7573

7674
// cleanupSub parses .srt or .ssa, performs cleanup and renders to a .srt, returning a string. caller is responsible for passing UTF8 string
@@ -90,12 +88,16 @@ func cleanupSub(data []byte, filterName string, keepAds bool, sync int) (string,
9088
return out, nil
9189
}
9290

93-
func action(inFileName string) error {
91+
func action(inFileName, outFileName string) error {
92+
93+
if outFileName == "" {
94+
outFileName = inFileName
95+
}
9496

9597
ext := path.Ext(inFileName)
9698
if subtitles.LooksLikeTextSubtitle(inFileName) {
9799
if !*dontTouch {
98-
parseAndWriteSubFile(inFileName, *filterName, *keepAds, *sync)
100+
parseAndWriteSubFile(inFileName, outFileName, *filterName, *keepAds, *sync)
99101
}
100102
return nil
101103
}
@@ -104,9 +106,8 @@ func action(inFileName string) error {
104106

105107
if fileExists(subFileName) {
106108
verboseMessage("Subs found locally in", subFileName, ", skipping download")
107-
108109
if !*dontTouch {
109-
parseAndWriteSubFile(subFileName, *filterName, *keepAds, *sync)
110+
parseAndWriteSubFile(subFileName, outFileName, *filterName, *keepAds, *sync)
110111
}
111112
return nil
112113
}
@@ -148,7 +149,7 @@ func action(inFileName string) error {
148149
}
149150

150151
func backupSub(fileName string) {
151-
log.Fatal("XXX TODO impl backupSub")
152+
log.Println("XXX TODO impl backupSub")
152153
}
153154

154155
func writeText(outFileName string, skipBackups bool, text string) error {

0 commit comments

Comments
 (0)