updates'
This commit is contained in:
parent
e9b7c73342
commit
eaf4554765
@ -65,6 +65,31 @@ func GetClient(ctx context.Context) (*spotify.Client, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client := spotify.New(auth.Client(context.Background(), tok))
|
client := spotify.New(auth.Client(context.Background(), tok))
|
||||||
|
new_token, err := client.Token()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if new_token != tok {
|
||||||
|
out, err := json.MarshalIndent(new_token, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
homdir, _ := os.UserHomeDir()
|
||||||
|
err = ioutil.WriteFile(filepath.Join(homdir, ".config/gospt/auth.json"), out, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
panic("FAILED TO SAVE AUTH")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out, err := json.MarshalIndent(tok, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
homdir, _ := os.UserHomeDir()
|
||||||
|
err = ioutil.WriteFile(filepath.Join(homdir, ".config/gospt/auth.json"), out, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
panic("FAILED TO SAVE AUTH")
|
||||||
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
// first start an HTTP server
|
// first start an HTTP server
|
||||||
|
@ -13,30 +13,65 @@ func Run(client *spotify.Client, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to get current user")
|
return fmt.Errorf("Failed to get current user")
|
||||||
}
|
}
|
||||||
fmt.Println("YOU ARE", user.DisplayName)
|
fmt.Println("The following commands are currently supported:\nplay pause next shuffle\nhave fun", user.DisplayName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "play":
|
case "play":
|
||||||
|
err := Play(ctx, client, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "pause":
|
||||||
|
err := Pause(ctx, client, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "next":
|
||||||
|
err := Skip(ctx, client, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "shuffle":
|
||||||
|
err := Shuffle(ctx, client, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Unsupported Command")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Play(ctx context.Context, client *spotify.Client, args []string) error {
|
||||||
err := client.Play(ctx)
|
err := client.Play(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Playing!")
|
fmt.Println("Playing!")
|
||||||
case "pause":
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Pause(ctx context.Context, client *spotify.Client, args []string) error {
|
||||||
err := client.Pause(ctx)
|
err := client.Pause(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Pausing!")
|
fmt.Println("Pausing!")
|
||||||
case "next":
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Skip(ctx context.Context, client *spotify.Client, args []string) error {
|
||||||
err := client.Next(ctx)
|
err := client.Next(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Skipping!")
|
fmt.Println("Skipping!")
|
||||||
case "shuffle":
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Shuffle(ctx context.Context, client *spotify.Client, args []string) error {
|
||||||
state, err := client.PlayerState(ctx)
|
state, err := client.PlayerState(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to get current playstate")
|
return fmt.Errorf("Failed to get current playstate")
|
||||||
@ -46,6 +81,5 @@ func Run(client *spotify.Client, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Shuffle set to", !state.ShuffleState)
|
fmt.Println("Shuffle set to", !state.ShuffleState)
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user