diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0b3d6a3..74f56a6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,9 +14,9 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.21 - - name: go vet -v ./... - run: go vet -v ./... + go-version: 1.22 + - name: go vet ./... + run: go vet ./... - name: go test -v ./... run: go test -v ./... - name: go build -v ./... diff --git a/.gitignore b/.gitignore index 3a8b25f..0e3260f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea -keepr assets/ diff --git a/cmd/keepr/keepr b/cmd/keepr/keepr new file mode 100755 index 0000000..c402252 Binary files /dev/null and b/cmd/keepr/keepr differ diff --git a/cmd/keepr/main.go b/cmd/keepr/main.go new file mode 100644 index 0000000..72dc1f1 --- /dev/null +++ b/cmd/keepr/main.go @@ -0,0 +1,103 @@ +package main + +import ( + "os" + "path/filepath" + "runtime" + "strings" + "sync/atomic" + "time" + + "github.com/rs/zerolog" + "kr.dev/walk" + + "git.tcp.direct/kayos/keepr/internal/collect" + "git.tcp.direct/kayos/keepr/internal/config" + "git.tcp.direct/kayos/keepr/internal/util" +) + +var ( + log *zerolog.Logger + basepath = "/" +) + +func init() { + if runtime.GOOS == "windows" { + // TODO: fix this garbage + basepath = "C:\\" + } +} + +func main() { + config.KeeprInit() + log = config.GetLogger() + var lastpath = "" + target := strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(config.Source), "/"), "/") + cripwalk := walk.New(os.DirFS(basepath), target) + _, output := filepath.Split(strings.TrimSuffix(config.Output, "/")) + log.Trace().Msgf("output is %s", output) + for cripwalk.Next() { + if err := cripwalk.Err(); err != nil { + log.Fatal().Caller().Str("caller", lastpath).Msg(err.Error()) + continue + } + lastpath = cripwalk.Path() + slog := log.With().Str("caller", cripwalk.Path()).Logger() + switch { + case cripwalk.Entry() == nil: + slog.Trace().Msg("nil") + continue + case cripwalk.Entry().IsDir(): + if strings.Contains(cripwalk.Path(), output) { + slog.Info().Msg("skiping directory entirely") + cripwalk.SkipDir() + } + continue + // slog.Trace().Msg("directory") + default: + if strings.Contains(cripwalk.Path(), config.Output) { + log.Trace().Msg("skipping file in destination") + cripwalk.SkipDir() + continue + } + sample, err := collect.Process(cripwalk.Entry(), util.APath(cripwalk.Path(), config.Relative)) + if err != nil { + slog.Warn().Caller().Str("caller", cripwalk.Path()).Err(err).Msgf("failed to process") + continue + } + if sample == nil { + slog.Trace().Msgf("skipping unknown file") + continue + } + slog.Info().Interface("sample", sample).Msg("processed") + } + } + + if config.StatsOnly { + log.Info().Msg("Printing stats") + collect.Library.TempoStats() + collect.Library.KeyStats() + collect.Library.DrumStats() + collect.Library.TypeStats() + return + } + + var errs []error + errs = append(errs, collect.Library.SymlinkTempos()) + errs = append(errs, collect.Library.SymlinkKeys()) + errs = append(errs, collect.Library.SymlinkDrums()) + errs = append(errs, collect.Library.SymlinkMelodicLoops()) + errs = append(errs, collect.Library.SymlinkMIDIs()) + errs = append(errs, collect.Library.SymlinkArtists()) + errs = append(errs, collect.Library.SymlinkGenres()) + errs = append(errs, collect.Library.SymlinkSources()) + errs = append(errs, collect.Library.SymlinkCreationDates()) + errs = append(errs, collect.Library.SymlinkSoftwares()) + + for !atomic.CompareAndSwapInt32(&collect.Backlog, 0, -1) { + time.Sleep(1 * time.Second) + print(".") + } + + log.Info().Errs("errs", errs).Msg("fin.") +} diff --git a/go.mod b/go.mod index 3987d4a..3655906 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.tcp.direct/kayos/keepr -go 1.22 +go 1.20 require ( git.tcp.direct/kayos/common v0.9.7