gospt/internal/api/api.go

63 lines
1.5 KiB
Go
Raw Normal View History

2023-01-08 05:34:31 +00:00
package api
2023-01-07 07:40:39 +00:00
import (
"fmt"
2023-01-08 05:22:54 +00:00
"gospt/internal/commands"
2023-01-08 05:26:06 +00:00
"gospt/internal/gctx"
2023-01-08 05:22:54 +00:00
"gospt/internal/tui"
2023-01-08 00:03:43 +00:00
2023-01-07 07:40:39 +00:00
"github.com/zmb3/spotify/v2"
)
2023-01-08 05:26:06 +00:00
func Run(ctx *gctx.Context, client *spotify.Client, args []string) error {
2023-01-07 07:40:39 +00:00
if len(args) == 0 {
2023-01-08 00:03:43 +00:00
user, err := client.CurrentUser(ctx)
2023-01-07 07:40:39 +00:00
if err != nil {
return fmt.Errorf("Failed to get current user")
}
2023-01-07 16:19:19 +00:00
fmt.Println("The following commands are currently supported:\nplay pause next shuffle\nhave fun", user.DisplayName)
2023-01-07 07:40:39 +00:00
return nil
}
switch args[0] {
case "play":
2023-01-08 00:57:51 +00:00
return commands.Play(ctx, client)
2023-01-07 07:40:39 +00:00
case "pause":
2023-01-08 00:57:51 +00:00
return commands.Pause(ctx, client)
2023-01-08 18:00:00 +00:00
case "toggleplay":
return commands.TogglePlay(ctx, client)
case "next":
return commands.Skip(ctx, client)
case "previous":
return commands.Previous(ctx, client)
case "playurl":
return commands.PlayUrl(ctx, client, args)
2023-01-08 08:00:29 +00:00
case "like":
return commands.Like(ctx, client)
case "unlike":
return commands.Unlike(ctx, client)
2023-01-07 07:40:39 +00:00
case "shuffle":
2023-01-08 00:57:51 +00:00
return commands.Shuffle(ctx, client)
2023-01-08 18:00:00 +00:00
case "repeat":
return commands.Repeat(ctx, client)
2023-01-08 04:58:18 +00:00
case "radio":
return commands.Radio(ctx, client)
2023-01-08 07:57:33 +00:00
case "clearradio":
return commands.ClearRadio(ctx, client)
case "refillradio":
return commands.RefillRadio(ctx, client)
2023-01-08 00:03:43 +00:00
case "tracks":
2023-01-08 00:57:51 +00:00
return tui.DisplayList(ctx, client)
2023-01-09 03:44:35 +00:00
case "playlists":
return tui.DisplayPlaylists(ctx, client)
2023-01-08 00:57:51 +00:00
case "status":
return commands.Status(ctx, client)
2023-01-08 02:14:36 +00:00
case "devices":
return commands.Devices(ctx, client)
case "setdevice":
2023-01-08 18:00:00 +00:00
return tui.DisplayDevices(ctx, client)
2023-01-07 16:19:19 +00:00
default:
return fmt.Errorf("Unsupported Command")
}
}