summaryrefslogtreecommitdiff
path: root/files/index.go
diff options
context:
space:
mode:
Diffstat (limited to 'files/index.go')
-rw-r--r--files/index.go53
1 files changed, 51 insertions, 2 deletions
diff --git a/files/index.go b/files/index.go
index e02e4ba..ea05dc4 100644
--- a/files/index.go
+++ b/files/index.go
@@ -1,7 +1,56 @@
-package main
+package files
-import "context"
+import (
+ "context"
+ "io/fs"
+ "path/filepath"
+ "time"
+
+ "github.com/briandowns/spinner"
+ "golang.org/x/sync/errgroup"
+)
func IndexFlacs(ctx context.Context) error {
+ spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
+ spin.Suffix = " Indexing flacs..."
+
+ spin.Start()
+
+ wg := new(errgroup.Group)
+ wg.SetLimit(100)
+
+ if err := filepath.WalkDir(ctx.Value("path").(string), func(path string, info fs.DirEntry, err error) error {
+ select {
+ case <-ctx.Done():
+ spin.FinalMSG = "Stopping...\n"
+ spin.Stop()
+ return nil
+ default:
+ if err != nil {
+ return err
+ }
+ if !info.IsDir() {
+ if filepath.Ext(path) == ".flac" {
+ wg.Go(func() error {
+ select {
+ case <-ctx.Done():
+ return nil
+ default:
+ return ProcessFile(ctx, path, info)
+ }
+ })
+ }
+
+ }
+ return nil
+ }
+
+ }); err != nil {
+ return err
+ }
+
+ wg.Wait()
+ spin.FinalMSG = "Done indexing flacs"
+ spin.Stop()
return nil
}