diff options
| -rw-r--r-- | cmd/cmd.go | 74 | ||||
| -rw-r--r-- | cmd/init.go | 53 | ||||
| -rw-r--r-- | cmd/main.go | 5 | ||||
| -rw-r--r-- | files/index.go | 7 | ||||
| -rw-r--r-- | go.mod | 23 | ||||
| -rw-r--r-- | go.sum | 27 |
6 files changed, 189 insertions, 0 deletions
diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 0000000..86a1b92 --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,74 @@ +package main + +import ( + "fmt" + "os" + "os/signal" + "time" + + "github.com/tidwall/buntdb" + "github.com/urfave/cli/v2" + "golang.org/x/sync/errgroup" +) + +func runCmd(cCtx *cli.Context) error { + ctx, err := initCmd(cCtx) + if err != nil { + return err + } + + db, err := buntdb.Open(ctx.Value("database").(string)) + if err != nil { + return err + } + defer db.Close() + + ctx, stop := signal.NotifyContext(ctx, os.Interrupt) + defer stop() + + test := new(errgroup.Group) + test.SetLimit(3) + for n := 1; n < 10; n++ { + test.Go(func() error { + select { + case <-ctx.Done(): + return nil + default: + fmt.Println("test") + time.Sleep(3 * time.Second) + return nil + } + }) + } + _ = test.Wait() + fmt.Println("reached") + return cCtx.Err() +} + +func start() { + app := &cli.App{ + Name: "reencoder", + Usage: "reencodes and stores info", + UsageText: "reencoder /path/to/folder", + Description: "indexes files, checks for encoder and reencodes", + Args: true, + ArgsUsage: "specify amusic links to download", + Flags: []cli.Flag{ + &cli.PathFlag{ + Name: "path", + Usage: "Path to folder with files to reencode", + Value: ".", + Aliases: []string{"p"}, + }, + &cli.PathFlag{ + Name: "database", + Usage: "Path to database", + Aliases: []string{"d"}, + }, + }, + Action: runCmd, + } + if err := app.Run(os.Args); err != nil { + panic(err.Error()) + } +} diff --git a/cmd/init.go b/cmd/init.go new file mode 100644 index 0000000..836a04a --- /dev/null +++ b/cmd/init.go @@ -0,0 +1,53 @@ +package main + +import ( + "context" + "errors" + "os" + "path/filepath" + "runtime" + + "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("database") == "" { + localFolder := getLocalStorage() + if localFolder == "" { + return context.WithValue(cCtx.Context, "database", ""), errors.New("failed to locate application data folder") + } + + return context.WithValue(cCtx.Context, "database", filepath.Join(localFolder, "reencoder.db")), nil + } + if _, err := os.Stat(cCtx.Path("database")); err != nil { + return context.WithValue(cCtx.Context, "database", ""), err + } + return context.WithValue(cCtx.Context, "database", cCtx.Path("database")), nil +} + +func initCmd(cCtx *cli.Context) (context.Context, error) { + if _, err := os.Stat(cCtx.Path("path")); err != nil { + return nil, err + } + + ctx, err := getDb(cCtx) + if err != nil { + return nil, err + } + return context.WithValue(ctx, "path", cCtx.Path("path")), nil +} diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..6d4c482 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + start() +} diff --git a/files/index.go b/files/index.go new file mode 100644 index 0000000..e02e4ba --- /dev/null +++ b/files/index.go @@ -0,0 +1,7 @@ +package main + +import "context" + +func IndexFlacs(ctx context.Context) error { + return nil +} @@ -0,0 +1,23 @@ +module github.com/justjakka/reencoder + +go 1.24.2 + +require github.com/urfave/cli/v2 v2.27.6 + +require ( + github.com/tidwall/btree v1.4.2 // indirect + github.com/tidwall/gjson v1.14.3 // indirect + github.com/tidwall/grect v0.1.4 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + github.com/tidwall/rtred v0.1.2 // indirect + github.com/tidwall/tinyqueue v0.1.1 // indirect +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/tidwall/buntdb v1.3.2 + github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect + golang.org/x/sync v0.13.0 +) @@ -0,0 +1,27 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= +github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/tidwall/btree v1.4.2 h1:PpkaieETJMUxYNADsjgtNRcERX7mGc/GP2zp/r5FM3g= +github.com/tidwall/btree v1.4.2/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE= +github.com/tidwall/buntdb v1.3.2 h1:qd+IpdEGs0pZci37G4jF51+fSKlkuUTMXuHhXL1AkKg= +github.com/tidwall/buntdb v1.3.2/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU= +github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= +github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/grect v0.1.4 h1:dA3oIgNgWdSspFzn1kS4S/RDpZFLrIxAZOdJKjYapOg= +github.com/tidwall/grect v0.1.4/go.mod h1:9FBsaYRaR0Tcy4UwefBX/UDcDcDy9V5jUcxHzv2jd5Q= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8= +github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ= +github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE= +github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw= +github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g= +github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= |
