gospt/internal/api/api.go

68 lines
1.6 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-09 06:50:27 +00:00
"os"
"path/filepath"
2023-01-07 07:40:39 +00:00
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-09 06:50:27 +00:00
configDir, _ := os.UserConfigDir()
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
2023-01-09 18:54:21 +00:00
return tui.StartTea(ctx, client)
2023-01-09 06:50:27 +00:00
}
2023-01-09 04:42:02 +00:00
return tui.DisplayMain(ctx, client)
2023-01-07 07:40:39 +00:00
}
switch args[0] {
2023-01-09 06:50:27 +00:00
case "help", "--help":
return commands.PrintHelp(ctx)
2023-01-07 07:40:39 +00:00
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)
2023-01-09 04:04:58 +00:00
case "nowplaying":
return commands.NowPlaying(ctx, client)
2023-01-08 02:14:36 +00:00
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")
}
}