@@ -14,6 +14,7 @@ import (
14
14
15
15
var (
16
16
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 ()
17
18
verbose = kingpin .Flag ("verbose" , "Verbose mode (more output)." ).Short ('v' ).Bool ()
18
19
quiet = kingpin .Flag ("quiet" , "Quiet mode (less output)." ).Short ('q' ).Bool ()
19
20
dontTouch = kingpin .Flag ("dont-touch" , "Do not try to process .srt (write directly to disk)." ).Bool ()
@@ -37,6 +38,7 @@ func main() {
37
38
}
38
39
39
40
inFileName := (* file ).Name ()
41
+ outFileName := * outFile
40
42
41
43
// skip "hidden" .dotfiles
42
44
baseName := filepath .Base (inFileName )
@@ -45,7 +47,7 @@ func main() {
45
47
os .Exit (1 )
46
48
}
47
49
48
- err := action (inFileName )
50
+ err := action (inFileName , outFileName )
49
51
if err != nil {
50
52
fmt .Println ("An error occured:" , err )
51
53
}
@@ -57,20 +59,16 @@ func verboseMessage(args ...interface{}) {
57
59
}
58
60
}
59
61
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 )
63
64
if err != nil {
64
65
return err
65
66
}
66
-
67
67
out , err := cleanupSub (data , filterName , keepAds , sync )
68
68
if err != nil {
69
69
return err
70
70
}
71
- writeText (fileName , * skipBackups , out )
72
-
73
- return nil
71
+ return writeText (outFileName , * skipBackups , out )
74
72
}
75
73
76
74
// 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,
90
88
return out , nil
91
89
}
92
90
93
- func action (inFileName string ) error {
91
+ func action (inFileName , outFileName string ) error {
92
+
93
+ if outFileName == "" {
94
+ outFileName = inFileName
95
+ }
94
96
95
97
ext := path .Ext (inFileName )
96
98
if subtitles .LooksLikeTextSubtitle (inFileName ) {
97
99
if ! * dontTouch {
98
- parseAndWriteSubFile (inFileName , * filterName , * keepAds , * sync )
100
+ parseAndWriteSubFile (inFileName , outFileName , * filterName , * keepAds , * sync )
99
101
}
100
102
return nil
101
103
}
@@ -104,9 +106,8 @@ func action(inFileName string) error {
104
106
105
107
if fileExists (subFileName ) {
106
108
verboseMessage ("Subs found locally in" , subFileName , ", skipping download" )
107
-
108
109
if ! * dontTouch {
109
- parseAndWriteSubFile (subFileName , * filterName , * keepAds , * sync )
110
+ parseAndWriteSubFile (subFileName , outFileName , * filterName , * keepAds , * sync )
110
111
}
111
112
return nil
112
113
}
@@ -148,7 +149,7 @@ func action(inFileName string) error {
148
149
}
149
150
150
151
func backupSub (fileName string ) {
151
- log .Fatal ("XXX TODO impl backupSub" )
152
+ log .Println ("XXX TODO impl backupSub" )
152
153
}
153
154
154
155
func writeText (outFileName string , skipBackups bool , text string ) error {
0 commit comments