refactor: remove disabled watcher feature
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NOTE: The watch command is disabled due to database concurrency issues.
|
||||
// To re-enable, uncomment RootCmd.AddCommand(watchCmd) in init().
|
||||
var watchCmd = &cobra.Command{
|
||||
Use: "watch",
|
||||
Short: "Watch playlists and auto-download new tracks",
|
||||
}
|
||||
|
||||
func init() {
|
||||
// RootCmd.AddCommand(watchCmd)
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"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: strings.ToLower(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", "mp3_320", "download quality [mp3_128, mp3_320, flac]")
|
||||
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")
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/mathismqn/godeez/internal/store"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var watchListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List watched playlists",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
playlists, err := store.ListWatchedPlaylists()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list watched playlists: %w", err)
|
||||
}
|
||||
|
||||
if len(playlists) == 0 {
|
||||
fmt.Println("No watched playlists.")
|
||||
return nil
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "ID\tQuality\tFetch BPM\tTimeout")
|
||||
fmt.Fprintln(w, "---\t-------\t----------\t-------")
|
||||
|
||||
for _, playlist := range playlists {
|
||||
fmt.Fprintf(w, "%s\t%s\t%t\t%s\n", playlist.ID, playlist.Quality, playlist.BPM, playlist.Timeout)
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
watchCmd.AddCommand(watchListCmd)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mathismqn/godeez/internal/store"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var watchRemoveCmd = &cobra.Command{
|
||||
Use: "remove <playlist_id>",
|
||||
Short: "Remove a playlist from 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 {
|
||||
return fmt.Errorf("playlist %s is not being watched", id)
|
||||
}
|
||||
|
||||
if err := store.RemoveWatchedPlaylist(id); err != nil {
|
||||
return fmt.Errorf("failed to remove playlist %s from watch list: %w", id, err)
|
||||
}
|
||||
fmt.Printf("Playlist %s removed from watch list\n", id)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
watchCmd.AddCommand(watchRemoveCmd)
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mathismqn/godeez/internal/config"
|
||||
"github.com/mathismqn/godeez/internal/watcher"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var watchRunCmd = &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "Start the background playlist watcher",
|
||||
Hidden: true,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
appConfig, err := config.New("")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cmd.SetContext(context.WithValue(cmd.Context(), appConfigKey, appConfig))
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
appConfig, _ := cmd.Context().Value(appConfigKey).(*config.Config)
|
||||
watcher.New(appConfig).Run(cmd.Context(), opts)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
watchCmd.AddCommand(watchRunCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user