This commit is contained in:
parent
1747097e7a
commit
e56ffc60a3
@ -18,8 +18,8 @@ var Services = fx.Options(
|
|||||||
fx.Provide(
|
fx.Provide(
|
||||||
func() *slog.Logger {
|
func() *slog.Logger {
|
||||||
return slog.New(tint.NewHandler(os.Stdout, &tint.Options{
|
return slog.New(tint.NewHandler(os.Stdout, &tint.Options{
|
||||||
AddSource: true,
|
Level: slog.LevelDebug.Level(),
|
||||||
Level: slog.LevelDebug.Level(),
|
TimeFormat: "[15:04:05.000]",
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
services.NewSpotifyClient,
|
services.NewSpotifyClient,
|
||||||
|
@ -2,7 +2,6 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
err := s.Shutdown()
|
err := s.Shutdown()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("SHUTDOWN", "error shutting down", err)
|
c.Log.Error("SHUTDOWN", "error shutting down", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
@ -232,6 +231,13 @@ func Run(c *commands.Commander, s fx.Shutdowner) {
|
|||||||
return c.Repeat()
|
return c.Repeat()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "shuffle",
|
||||||
|
Usage: "Toggle shuffle mode",
|
||||||
|
Action: func(cCtx *cli.Context) error {
|
||||||
|
return c.Shuffle()
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "seek",
|
Name: "seek",
|
||||||
Usage: "Seek to a position in the song",
|
Usage: "Seek to a position in the song",
|
||||||
@ -265,7 +271,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
slog.Error("COMMANDER", "run error", err)
|
c.Log.Error("COMMANDER", "run error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ func (c *Commander) activateDevice(ctx context.Context) (spotify.ID, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
slog.Error("COMMANDER", "failed to activated device", "YOU MUST RUN gospt setdevice FIRST")
|
c.Log.Error("COMMANDER", "failed to activated device", "YOU MUST RUN gospt setdevice FIRST")
|
||||||
}
|
}
|
||||||
return device.ID, nil
|
return device.ID, nil
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,14 @@ type CommanderParams struct {
|
|||||||
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Client *spotify.Client
|
Client *spotify.Client
|
||||||
|
Log *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
type Commander struct {
|
type Commander struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Client *spotify.Client
|
Client *spotify.Client
|
||||||
User *spotify.PrivateUser
|
User *spotify.PrivateUser
|
||||||
|
Log *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommander(p CommanderParams) CommanderResult {
|
func NewCommander(p CommanderParams) CommanderResult {
|
||||||
@ -38,6 +40,7 @@ func NewCommander(p CommanderParams) CommanderResult {
|
|||||||
Context: p.Context,
|
Context: p.Context,
|
||||||
Client: p.Client,
|
Client: p.Client,
|
||||||
User: currentUser,
|
User: currentUser,
|
||||||
|
Log: p.Log,
|
||||||
}
|
}
|
||||||
return CommanderResult{
|
return CommanderResult{
|
||||||
Commander: c,
|
Commander: c,
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Commander) Repeat() error {
|
func (c *Commander) Repeat() error {
|
||||||
state, err := c.Client.PlayerState(c.Context)
|
state, err := c.Client.PlayerState(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -18,6 +14,6 @@ func (c *Commander) Repeat() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Repeat set to", newState)
|
c.Log.Info("COMMANDER", "Repeat set to", newState)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
14
src/components/commands/shuffle.go
Normal file
14
src/components/commands/shuffle.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
func (c *Commander) Shuffle() error {
|
||||||
|
state, err := c.Client.PlayerState(c.Context)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = c.Client.Shuffle(c.Context, !state.ShuffleState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Log.Info("COMMANDER", "shuffle state", !state.ShuffleState)
|
||||||
|
return nil
|
||||||
|
}
|
@ -40,10 +40,7 @@ func (fn roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)
|
|||||||
|
|
||||||
func NewSpotifyClient(conf *config.Config) (c SpotifyClientResult, err error) {
|
func NewSpotifyClient(conf *config.Config) (c SpotifyClientResult, err error) {
|
||||||
if conf.ClientId == "" || (conf.ClientSecret == "" && conf.ClientSecretCmd == "") || conf.Port == "" {
|
if conf.ClientId == "" || (conf.ClientSecret == "" && conf.ClientSecretCmd == "") || conf.Port == "" {
|
||||||
fmt.Println("PLEASE WRITE YOUR CONFIG FILE IN", filepath.Join(configDir, "gospt/gospt.yml"))
|
return SpotifyClientResult{}, fmt.Errorf("INVALID CONFIG")
|
||||||
fmt.Println("GO HERE TO AND MAKE AN APPLICATION: https://developer.spotify.com/dashboard/applications")
|
|
||||||
fmt.Print("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"\nport:\"8888\"\n\n")
|
|
||||||
return SpotifyClientResult{}, fmt.Errorf("\nINVALID CONFIG")
|
|
||||||
}
|
}
|
||||||
if conf.ClientSecretCmd != "" {
|
if conf.ClientSecretCmd != "" {
|
||||||
args := strings.Fields(conf.ClientSecretCmd)
|
args := strings.Fields(conf.ClientSecretCmd)
|
||||||
@ -129,7 +126,7 @@ func NewSpotifyClient(conf *config.Config) (c SpotifyClientResult, err error) {
|
|||||||
_ = server.ListenAndServe()
|
_ = server.ListenAndServe()
|
||||||
}()
|
}()
|
||||||
url := auth.AuthURL(state)
|
url := auth.AuthURL(state)
|
||||||
fmt.Println(url)
|
slog.Info("AUTH", "url", url)
|
||||||
cmd := exec.Command("xdg-open", url)
|
cmd := exec.Command("xdg-open", url)
|
||||||
_ = cmd.Start()
|
_ = cmd.Start()
|
||||||
// wait for auth to complete
|
// wait for auth to complete
|
||||||
@ -141,7 +138,7 @@ func NewSpotifyClient(conf *config.Config) (c SpotifyClientResult, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return SpotifyClientResult{}, err
|
return SpotifyClientResult{}, err
|
||||||
}
|
}
|
||||||
fmt.Println("You are logged in as:", user.ID)
|
slog.Info("AUTH", "You are logged in as:", user.ID)
|
||||||
return SpotifyClientResult{Client: client}, nil
|
return SpotifyClientResult{Client: client}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user