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") +}