From 498f7c8d3fdd97ff4b09ce573092b2ba192cdd9b Mon Sep 17 00:00:00 2001 From: Mathis Maquenne <124215603+mathismqn@users.noreply.github.com> Date: Sun, 22 Jun 2025 17:46:46 -0400 Subject: [PATCH] feat(watch): add command to register a playlist to the watch list --- cmd/watch_add.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cmd/watch_add.go diff --git a/cmd/watch_add.go b/cmd/watch_add.go new file mode 100644 index 0000000..23d4f7d --- /dev/null +++ b/cmd/watch_add.go @@ -0,0 +1,48 @@ +package cmd + +import ( + "fmt" + "time" + + "github.com/mathismqn/godeez/internal/store" + "github.com/spf13/cobra" +) + +var watchAddCmd = &cobra.Command{ + Use: "add ", + Short: "Add a playlist to the watch list", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + id := args[0] + ok, err := store.IsWatched(id) + if err != nil { + return err + } + if ok { + fmt.Printf("Playlist %s is already being watched\n", id) + return nil + } + + playlist := &store.WatchedPlaylist{ + ID: id, + Quality: opts.Quality, + BPM: opts.BPM, + Timeout: opts.Timeout, + } + + if err := playlist.Save(); err != nil { + return fmt.Errorf("failed to add playlist %s to watch list: %w", id, err) + } + fmt.Printf("Playlist %s added to watch list\n", id) + + return nil + }, +} + +func init() { + watchCmd.AddCommand(watchAddCmd) + + watchAddCmd.Flags().StringVarP(&opts.Quality, "quality", "q", "best", "download quality [mp3_128, mp3_320, flac, best]") + watchAddCmd.Flags().DurationVarP(&opts.Timeout, "timeout", "t", 2*time.Minute, "timeout for each download (e.g. 10s, 1m, 2m30s)") + watchAddCmd.Flags().BoolVar(&opts.BPM, "bpm", false, "fetch BPM/key and add to file tags") +}