27 lines
478 B
Go
Raw Normal View History

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