From 5a39e523da7f4fe2c9c1e6c369a366162be122fa Mon Sep 17 00:00:00 2001 From: jakka Date: Wed, 4 Jun 2025 17:07:16 +0300 Subject: started rewriting --- cmd/init.go | 84 ------------------------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 cmd/init.go (limited to 'cmd/init.go') diff --git a/cmd/init.go b/cmd/init.go deleted file mode 100644 index 2852565..0000000 --- a/cmd/init.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "context" - "errors" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - - "github.com/urfave/cli/v2" -) - -func getLocalStorage() string { - switch runtime.GOOS { - case "windows": - return os.Getenv("APPDATA") - case "linux": - home, _ := os.UserHomeDir() - return filepath.Join(home, ".local", "share") - case "darwin": - home, _ := os.UserHomeDir() - return filepath.Join(home, "Library", "Application Support") - default: - return "" - } -} - -func getDb(cCtx *cli.Context) (context.Context, error) { - if cCtx.Path("dbfile") == "" { - localFolder := getLocalStorage() - if localFolder == "" { - return context.WithValue(cCtx.Context, "dbfile", ""), errors.New("failed to locate application data folder") - } - - return context.WithValue(cCtx.Context, "dbfile", filepath.Join(localFolder, "reencoder")), nil - } - if _, err := os.Stat(cCtx.Path("dbfile")); err != nil { - return context.WithValue(cCtx.Context, "dbfile", ""), err - } - 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 initArgs(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 - } - - ctx, err := getDb(cCtx) - if err != nil { - return nil, err - } - - ctx = context.WithValue(ctx, "path", cCtx.Path("path")) - - encoder, err := exec.Command("flac", "-v").Output() - if err != nil { - return nil, err - } - - ctx = context.WithValue(ctx, "encoder", strings.ReplaceAll(strings.Split(string(encoder), " ")[1], "\n", "")) - - defargs := []string{"-8f", "-j4"} - - if cCtx.Value("flac") == nil { - return context.WithValue(ctx, "flac", defargs), nil - } - return context.WithValue(ctx, "flac", cCtx.StringSlice("flac")), nil -} -- cgit v1.3.1