summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGrailFinder <wohilas@gmail.com>2023-02-11 11:18:28 +0300
committerGrailFinder <wohilas@gmail.com>2023-02-11 11:18:28 +0300
commit298f2c832081366fed9b4d683ba665c9d7b9d150 (patch)
tree32b3b19751dd98c3032b3430fcfc76da486376b4 /main.go
parente501adcff44c94025a904c0e65917d77be2b91f1 (diff)
Feat: append to metadata.json instead of replacing
Diffstat (limited to 'main.go')
-rw-r--r--main.go39
1 files changed, 30 insertions, 9 deletions
diff --git a/main.go b/main.go
index c09e0e3..0b5d981 100644
--- a/main.go
+++ b/main.go
@@ -12,10 +12,11 @@ import (
)
const (
- subExt = ".vtt"
- outdir = "/mnt/desktop/media/datasets/nesfatelp_voice/utterances"
- ffCmdOut = "./ff_commands"
- timeSep = "-->"
+ subExt = ".vtt"
+ outdir = "/mnt/desktop/media/datasets/nesfatelp_voice/utterances"
+ ffCmdOut = "./ff_commands"
+ timeSep = "-->"
+ metadataPath = "/mnt/desktop/media/datasets/nesfatelp_voice/metadata.json"
)
type Utterance struct {
@@ -96,6 +97,24 @@ func writeLines(lines []string, path string) error {
return w.Flush()
}
+func readJson(filepath string) map[string]string {
+ plan, _ := ioutil.ReadFile(filepath)
+ data := make(map[string]string)
+ err := json.Unmarshal(plan, &data)
+ if err != nil {
+ log.Fatal(err)
+ }
+ return data
+}
+
+func writeJson(data map[string]string) {
+ metadataJson, _ := json.MarshalIndent(data, "", " ")
+ err := ioutil.WriteFile(metadataPath, metadataJson, 0644)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
func buildFFmpegCall(fd *FileData, ut *Utterance) string {
return fmt.Sprintf(
`ffmpeg -i %s -ss %s -to %s \
@@ -130,10 +149,12 @@ func main() {
fmt.Println("utterances len:", len(utterances))
writeLines(ffmpegCommands, ffCmdOut)
- metadata := utterancesToFileTextMap(utterances)
- metadataJson, _ := json.MarshalIndent(metadata, "", " ")
- err := ioutil.WriteFile("metadata.json", metadataJson, 0644)
- if err != nil {
- log.Fatal(err)
+ metadata := readJson(metadataPath)
+ newMeta := utterancesToFileTextMap(utterances)
+
+ for k, v := range newMeta {
+ metadata[k] = v
}
+
+ writeJson(metadata)
}