code cleanup

This commit is contained in:
Tordarus 2025-01-16 14:20:16 +01:00
parent da6f025c7c
commit 98c54d249b
3 changed files with 5 additions and 26 deletions

View File

@ -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")
}

View File

@ -15,7 +15,7 @@ func GetStreamsFromFile(path string) (string, error) {
path,
)
data, err := cmd.CombinedOutput()
data, err := cmd.Output()
return string(data), err
}

27
main.go
View File

@ -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))
}