gspot/src/components/commands/downloadCover.go

24 lines
435 B
Go
Raw Normal View History

2024-02-18 09:30:19 +00:00
package commands
import (
"os"
"path/filepath"
)
func (c *Commander) DownloadCover(path string) error {
destinationPath := filepath.Clean(path)
state, err := c.Client.PlayerState(c.Context)
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
}