This commit is contained in:
parent
696ee7e263
commit
e39355fb69
20
cmd/download_cover.go
Normal file
20
cmd/download_cover.go
Normal file
@ -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)
|
||||||
|
},
|
||||||
|
}
|
@ -920,6 +920,23 @@ func (c *Commands) Status(ctx *gctx.Context) error {
|
|||||||
return nil
|
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) {
|
func (c *Commands) Link(ctx *gctx.Context) (string, error) {
|
||||||
state, err := c.Client().PlayerState(ctx)
|
state, err := c.Client().PlayerState(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user