download_cover
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
abs3nt 2023-10-14 09:27:58 -07:00
parent 696ee7e263
commit e39355fb69
Signed by: abs3nt
GPG Key ID: FDC6662313FA9386
2 changed files with 37 additions and 0 deletions

20
cmd/download_cover.go Normal file
View 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)
},
}

View File

@ -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 {