feat(watch): add command to register a playlist to the watch list
This commit is contained in:
@@ -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 <playlist_id>",
|
||||||
|
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")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user