diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 41 |
1 files changed, 33 insertions, 8 deletions
@@ -76,8 +76,7 @@ func linesToUtterances(lines []string, fd *FileData) []*Utterance { u.OutPath = fmt.Sprintf("%s/%s_%s_%s.opus", outdir, fd.AudioBase, u.LeftTime, u.RightTime) - // todo: compare and filter time - if u.LeftTime == u.RightTime { + if !adequateTimes(u.LeftTime, u.RightTime) { continue } resp = append(resp, u) @@ -86,6 +85,27 @@ func linesToUtterances(lines []string, fd *FileData) []*Utterance { return resp } +func adequateTimes(left, right string) bool { + if len(left) == len("06:18.240") { + left = "00:" + left + } + if len(right) == len("06:18.240") { + right = "00:" + right + } + lts, err := time.Parse("15:04:05.000", left) + if err != nil { + fmt.Println(left, right, err) + } + rts, err := time.Parse("15:04:05.000", right) + if err != nil { + fmt.Println(left, right, err) + } + if rts.After(lts) { + return true + } + return false +} + func buildFFmpegCall(ut *Utterance) string { return fmt.Sprintf( `yes no | ffmpeg -i "%s" -ss %s -to %s \ @@ -163,11 +183,11 @@ func main() { panic(err) } - // filteredUtterances := []*Utterance{} + filteredUtterances := []*Utterance{} // === concurrent === queue := make(chan *Utterance, len(utterances)) - done := make(chan bool, 1) + geshaft := make(chan *Utterance, len(utterances)) for _, ut := range utterances { if _, err := os.Stat(ut.OutPath); os.IsNotExist(err) { @@ -175,6 +195,8 @@ func main() { // if err := cutoutClipAndTranscode(ut); err == nil { // filteredUtterances = append(filteredUtterances, ut) // } + } else if err == nil { + geshaft <- ut } } @@ -182,20 +204,23 @@ func main() { workers := 100 for i := 0; i < workers; i++ { - go worker(queue, i, done) + go worker(queue, i, geshaft) } for { if len(queue) == 0 { // give time for workers to finish time.Sleep(3 * time.Second) - done <- true - close(done) close(queue) break } time.Sleep(1 * time.Second) } - newMeta := utterancesToFileTextMap(utterances) + + for ut := range geshaft { + filteredUtterances = append(filteredUtterances, ut) + } + close(geshaft) + newMeta := utterancesToFileTextMap(filteredUtterances) writeCSV(mapToCSV(newMeta)) } |