From 98c54d249b4033d9ff180a883d9219e1e6d287dd Mon Sep 17 00:00:00 2001 From: Tordarus Date: Thu, 16 Jan 2025 14:20:16 +0100 Subject: [PATCH] code cleanup --- bool_func_utils.go | 2 -- ffmpeg.go | 2 +- main.go | 27 ++++----------------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/bool_func_utils.go b/bool_func_utils.go index 471a734..f0b8059 100644 --- a/bool_func_utils.go +++ b/bool_func_utils.go @@ -2,7 +2,6 @@ package main import ( "errors" - "fmt" "io/fs" "os" "path/filepath" @@ -39,7 +38,6 @@ func SymlinkFilesOnly(path string) bool { func VideosOnly(path string) bool { streams, err := GetStreamsFromFile(path) - fmt.Println("VIDEOS_ONLY", "DEBUG", streams, err) return err == nil && strings.Contains(streams, "video") } diff --git a/ffmpeg.go b/ffmpeg.go index 08bd6eb..2cc66d1 100644 --- a/ffmpeg.go +++ b/ffmpeg.go @@ -15,7 +15,7 @@ func GetStreamsFromFile(path string) (string, error) { path, ) - data, err := cmd.CombinedOutput() + data, err := cmd.Output() return string(data), err } diff --git a/main.go b/main.go index a9e1b3c..0300999 100644 --- a/main.go +++ b/main.go @@ -53,11 +53,6 @@ func main() { panic(err) } - files = channel.MapSuccessive(files, func(s string) string { - fmt.Println("DEBUG", s) - return s - }) - groupedFiles := channel.GroupByTime(files, FlagGroupMultipleFileChangesByTime, func(events map[string]struct{}, event string) map[string]struct{} { if events == nil { events = map[string]struct{}{} @@ -67,22 +62,8 @@ func main() { }) filesByGroup := channel.FlatMap(groupedFiles, func(key string, _ struct{}) string { return key }) - - filesByGroup = channel.MapSuccessive(filesByGroup, func(s string) string { - fmt.Println("GROUPED", s) - fmt.Println("EXISTS", Exists(s)) - fmt.Println("SymlinkFilesOnly", SymlinkFilesOnly(s)) - fmt.Println("VideosOnly", VideosOnly(s)) - return s - }) - filteredFiles := channel.Filter(filesByGroup, Or(Not(Exists), And(SymlinkFilesOnly, VideosOnly))) - filteredFiles = channel.MapSuccessive(filteredFiles, func(s string) string { - fmt.Println("FILTERED", s) - return s - }) - for file := range filteredFiles { if err := TranscodeFile(file); err != nil { fmt.Fprintln(os.Stderr, fmt.Errorf("could not transcode file '%s': %w", file, err)) @@ -95,12 +76,12 @@ func TranscodeFile(file string) error { newPath := filepath.Join(FlagTargetDir, relPath+".mp3") newDir := filepath.Dir(newPath) - fmt.Printf("check '%s'\n", relPath) + fmt.Printf("check: '%s'\n", relPath) // file was deleted in source directory. // delete corresponding file in target directory as well if _, err := os.Stat(file); errors.Is(err, fs.ErrNotExist) { - fmt.Printf("remove '%s'\n", relPath) + fmt.Printf("remove: '%s'\n", relPath) return os.Remove(newPath) } @@ -123,13 +104,13 @@ func TranscodeFile(file string) error { } if currentFileHash == expectedFileHash { - fmt.Printf("skip '%s'. hashes match\n", relPath) + fmt.Printf("skip because hashes match: '%s'\n", relPath) return nil } } } - fmt.Printf("convert '%s'\n", relPath) + fmt.Printf("convert: '%s'\n", relPath) if err := ConvertToAudio(context.Background(), file, newPath); err != nil { fmt.Fprintln(os.Stderr, fmt.Errorf("encoding of video '%s' failed: %w", file, err)) }