diff options
| author | jakka <jakkadoujin@gmail.com> | 2025-06-04 17:07:16 +0300 |
|---|---|---|
| committer | jakka <jakkadoujin@gmail.com> | 2025-06-04 17:07:16 +0300 |
| commit | 5a39e523da7f4fe2c9c1e6c369a366162be122fa (patch) | |
| tree | 033df21a928cf883549bd2fab71a0fa02dbfb3c8 /cmd/init.go | |
| parent | 9b50859cd0aa3832500fe4ea22e3b4e967d6032a (diff) | |
started rewriting
Diffstat (limited to 'cmd/init.go')
| -rw-r--r-- | cmd/init.go | 84 |
1 files changed, 0 insertions, 84 deletions
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 -} |
