diff --git a/cmd/download_cover.go b/cmd/download_cover.go new file mode 100644 index 0000000..f4ec450 --- /dev/null +++ b/cmd/download_cover.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(downloadCoverCmd) +} + +var downloadCoverCmd = &cobra.Command{ + Use: "download_cover", + Aliases: []string{"now"}, + Short: "Returns url for currently playing song art", + Long: `Returns url for currently playing song art`, + Args: cobra.MatchAll(cobra.ExactArgs(1)), + Run: func(cmd *cobra.Command, args []string) { + commands.DownloadCover(ctx, args) + }, +} diff --git a/src/commands/commands.go b/src/commands/commands.go index 33588c8..0e3dc3d 100644 --- a/src/commands/commands.go +++ b/src/commands/commands.go @@ -920,6 +920,23 @@ func (c *Commands) Status(ctx *gctx.Context) error { return nil } +func (c *Commands) DownloadCover(ctx *gctx.Context, args []string) error { + destinationPath := filepath.Clean(args[0]) + state, err := c.Client().PlayerState(ctx) + if err != nil { + return err + } + f, err := os.OpenFile(destinationPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + if err != nil { + return err + } + err = state.Item.Album.Images[0].Download(f) + if err != nil { + return err + } + return nil +} + func (c *Commands) Link(ctx *gctx.Context) (string, error) { state, err := c.Client().PlayerState(ctx) if err != nil {