This commit is contained in:
parent
aaa467eee0
commit
775331ce69
@ -111,8 +111,15 @@ func Run(c *commands.Commander, s fx.Shutdowner) {
|
||||
Name: "nowplaying",
|
||||
Aliases: []string{"now"},
|
||||
Usage: "Prints the current song",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "force",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "bypass cache",
|
||||
},
|
||||
},
|
||||
Action: func(cCtx *cli.Context) error {
|
||||
return c.NowPlaying()
|
||||
return c.NowPlaying(cCtx.Bool("force"))
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -2,17 +2,34 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
func (c *Commander) NowPlaying() error {
|
||||
current, err := c.Client.PlayerCurrentlyPlaying(c.Context)
|
||||
func (c *Commander) NowPlaying(force bool) error {
|
||||
if force {
|
||||
current, err := c.Client.PlayerCurrentlyPlaying(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
str := FormatSong(current)
|
||||
fmt.Println(str)
|
||||
_, err = c.Cache.Put("now_playing", str, 5*time.Second)
|
||||
return err
|
||||
}
|
||||
song, err := c.Cache.GetOrDo("now_playing", func() (string, error) {
|
||||
current, err := c.Client.PlayerCurrentlyPlaying(c.Context)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
str := FormatSong(current)
|
||||
return str, nil
|
||||
}, 5*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
str := FormatSong(current)
|
||||
fmt.Println(str)
|
||||
fmt.Println(song)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user