From 298f2c832081366fed9b4d683ba665c9d7b9d150 Mon Sep 17 00:00:00 2001 From: GrailFinder Date: Sat, 11 Feb 2023 11:18:28 +0300 Subject: Feat: append to metadata.json instead of replacing --- main.go | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'main.go') 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) } -- cgit v1.2.3