summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2023-02-26 14:48:15 +0600
committerGrail Finder <wohilas@gmail.com>2023-02-26 14:48:15 +0600
commit3f99abb502d373cb4b520b212afd4be9ed4da07f (patch)
tree221c7ccc943a4e4262d536cb268fd7dd04c59074 /main.go
parentf60be7df2d741b73863df63c8a275d1b9471db58 (diff)
Feat: use md5 hash to save on space with shorter names
Diffstat (limited to 'main.go')
-rw-r--r--main.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/main.go b/main.go
index fe7ac06..4cfa197 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "crypto/md5"
"flag"
"fmt"
"os"
@@ -12,7 +13,6 @@ import (
const (
subExt = ".vtt"
- outdir = "/mnt/nvme/data"
ffCmdOut = "data/ff_commands"
timeSep = "-->"
metadataPath = "data/metadata.json"
@@ -20,6 +20,10 @@ const (
segmentSize = "00:08:00"
)
+var (
+ outdir = "/mnt/nvme/data"
+)
+
type Utterance struct {
LeftTime string
RightTime string
@@ -59,6 +63,16 @@ func mapToCSV(req map[string]string) [][]string {
return resp
}
+func hashStr(req string) string {
+ return fmt.Sprintf("%x", md5.Sum([]byte(req)))
+}
+
+func fpathToOutname(req string) string {
+ basename := filepath.Base(req)
+ h := hashStr(basename)
+ return path.Join(outdir, h+".opus")
+}
+
func linesToUtterances(lines []string, fd *FileData) []*Utterance {
resp := []*Utterance{}
for i, line := range lines {
@@ -107,16 +121,6 @@ func adequateTimes(left, right string) bool {
return false
}
-func buildFFmpegCall(ut *Utterance) string {
- return fmt.Sprintf(
- `yes no | ffmpeg -i "%s" -ss %s -to %s \
- -metadata text_source="%s" \
- -ar 22050 "%s"`,
- ut.FD.AudioPath, ut.LeftTime, ut.RightTime,
- ut.FD.VttPath, ut.OutPath,
- )
-}
-
func utterancesToFileTextMap(utterances []*Utterance) map[string]string {
resp := make(map[string]string)
for _, ut := range utterances {
@@ -163,7 +167,7 @@ func getFileList(dirpath string, filter string) []string {
return resp
}
-func equalSlice(dirpath string) {
+func equalSliceRun(dirpath string) {
auFiles := getFileList(dirpath, "opus")
fQueue := make(chan string, len(auFiles))
@@ -171,7 +175,7 @@ func equalSlice(dirpath string) {
fQueue <- fpath
}
- workers := 3
+ workers := 20
for i := 0; i < workers; i++ {
go cutterQueue(fQueue, i)
}
@@ -190,17 +194,22 @@ func equalSlice(dirpath string) {
func main() {
vttFilepath := flag.String("f", "", "path to a vtt file")
vttDir := flag.String("d", "", "path to a vtt dir")
+ outDirArg := flag.String("o", "", "output dir")
sliceAudioDir := flag.String("slice-audio-dir", "",
"for equal segmentation only without subs")
flag.Parse()
+ if outDirArg != nil && *outDirArg != "" {
+ outdir = *outDirArg
+ }
+
utterances := []*Utterance{}
if vttDir != nil && *vttDir != "" {
utterances = dirRun(*vttDir)
} else if vttFilepath != nil && *vttFilepath != "" {
utterances = oneFileRun(*vttFilepath)
} else if sliceAudioDir != nil && *sliceAudioDir != "" {
- equalSlice(*sliceAudioDir)
+ equalSliceRun(*sliceAudioDir)
return
} else {
fmt.Println("no flags provided;")