summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGrailFinder <wohilas@gmail.com>2023-02-12 10:11:19 +0300
committerGrailFinder <wohilas@gmail.com>2023-02-12 10:11:19 +0300
commit79ef44e3b799370c48e8fade52a98a39ae519f6f (patch)
tree30d326194d11ac4d0d663444021bec9f1192be6c /main.go
parentc3ee8c6c88e6f879c7dce7316629e1fe18f08c71 (diff)
Feat (metadata): return empty map when no file
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/main.go b/main.go
index a0fe70a..61e0515 100644
--- a/main.go
+++ b/main.go
@@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io/ioutil"
- "log"
"os"
"path"
"path/filepath"
@@ -68,7 +67,7 @@ func linesToUtterances(lines []string, fd *FileData) []*Utterance {
func readLines(filepath string) []string {
file, err := os.Open(filepath)
if err != nil {
- log.Fatal(err)
+ panic(err)
}
defer file.Close()
@@ -79,7 +78,7 @@ func readLines(filepath string) []string {
}
if err := scanner.Err(); err != nil {
- log.Fatal(err)
+ panic(err)
}
return resp
}
@@ -102,11 +101,14 @@ func writeLines(lines []string, path string) error {
}
func readJson(filepath string) map[string]string {
- plan, _ := ioutil.ReadFile(filepath)
data := make(map[string]string)
- err := json.Unmarshal(plan, &data)
+ plan, err := ioutil.ReadFile(filepath)
if err != nil {
- log.Fatal(err)
+ return data
+ }
+ err = json.Unmarshal(plan, &data)
+ if err != nil {
+ panic(err)
}
return data
}
@@ -115,7 +117,7 @@ func writeJson(data map[string]string) {
metadataJson, _ := json.MarshalIndent(data, "", " ")
err := ioutil.WriteFile(metadataPath, metadataJson, 0644)
if err != nil {
- log.Fatal(err)
+ panic(err)
}
}
@@ -139,7 +141,7 @@ func utterancesToFileTextMap(utterances []*Utterance) map[string]string {
func oneFileRun(filepath string) []*Utterance {
fd := NewFileData(filepath)
- fmt.Println("working with:", fd)
+ fmt.Println("working with:", filepath)
lines := readLines(fd.VttPath)
utterances := linesToUtterances(lines, fd)
@@ -158,7 +160,7 @@ func dirRun(dirpath string) []*Utterance {
resp := []*Utterance{}
vttFiles := getVttList(dirpath)
for _, vtt := range vttFiles {
- utterances := oneFileRun(vtt)
+ utterances := oneFileRun(path.Join(dirpath, vtt))
resp = append(resp, utterances...)
}
return resp
@@ -184,8 +186,8 @@ func getVttList(dirpath string) []string {
}
func main() {
- vttFilepath := flag.String("vttfile", "", "path to a vtt file")
- vttDir := flag.String("vttdir", "", "path to a vtt dir")
+ vttFilepath := flag.String("f", "", "path to a vtt file")
+ vttDir := flag.String("d", "", "path to a vtt dir")
// vttFilepath := os.Args[1]
flag.Parse()