summaryrefslogtreecommitdiff
path: root/cmd/init.go
diff options
context:
space:
mode:
authorjakka <jakkadoujin@gmail.com>2025-04-12 14:44:39 +0300
committerjakka <jakkadoujin@gmail.com>2025-04-12 14:44:39 +0300
commit1675136966473083e970badfe92433a05d2d7fee (patch)
tree5cd22f2ee065514a1c5db508f6d6a5ed3757c454 /cmd/init.go
parent6f3071a58211598ee23d1ef6ab17156e15b2e27b (diff)
implemented database and concurrent file scanning
Diffstat (limited to 'cmd/init.go')
-rw-r--r--cmd/init.go38
1 files changed, 31 insertions, 7 deletions
diff --git a/cmd/init.go b/cmd/init.go
index 836a04a..18e3b65 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -4,8 +4,10 @@ import (
"context"
"errors"
"os"
+ "os/exec"
"path/filepath"
"runtime"
+ "strings"
"github.com/urfave/cli/v2"
)
@@ -26,21 +28,35 @@ func getLocalStorage() string {
}
func getDb(cCtx *cli.Context) (context.Context, error) {
- if cCtx.Path("database") == "" {
+ if cCtx.Path("dbfile") == "" {
localFolder := getLocalStorage()
if localFolder == "" {
- return context.WithValue(cCtx.Context, "database", ""), errors.New("failed to locate application data folder")
+ return context.WithValue(cCtx.Context, "dbfile", ""), errors.New("failed to locate application data folder")
}
- return context.WithValue(cCtx.Context, "database", filepath.Join(localFolder, "reencoder.db")), nil
+ return context.WithValue(cCtx.Context, "dbfile", filepath.Join(localFolder, "reencoder.db")), nil
}
- if _, err := os.Stat(cCtx.Path("database")); err != nil {
- return context.WithValue(cCtx.Context, "database", ""), err
+ if _, err := os.Stat(cCtx.Path("dbfile")); err != nil {
+ return context.WithValue(cCtx.Context, "dbfile", ""), err
}
- return context.WithValue(cCtx.Context, "database", cCtx.Path("database")), nil
+ return context.WithValue(cCtx.Context, "dbfile", cCtx.Path("dbfile")), nil
+}
+
+func checkTools() error {
+ if _, err := exec.LookPath("flac"); err != nil {
+ return errors.New("missing flac executable")
+ }
+ if _, err := exec.LookPath("metaflac"); err != nil {
+ return errors.New("missing metaflac executable")
+ }
+ return nil
}
func initCmd(cCtx *cli.Context) (context.Context, error) {
+ if err := checkTools(); err != nil {
+ return nil, err
+ }
+
if _, err := os.Stat(cCtx.Path("path")); err != nil {
return nil, err
}
@@ -49,5 +65,13 @@ func initCmd(cCtx *cli.Context) (context.Context, error) {
if err != nil {
return nil, err
}
- return context.WithValue(ctx, "path", cCtx.Path("path")), nil
+
+ ctx = context.WithValue(ctx, "path", cCtx.Path("path"))
+
+ encoder, err := exec.Command("flac", "-v").Output()
+ if err != nil {
+ return nil, err
+ }
+
+ return context.WithValue(ctx, "encoder", strings.ReplaceAll(strings.Split(string(encoder), " ")[1], "\n", "")), nil
}