diff --git a/internal/api/api.go b/internal/api/api.go index 3983987..27556ce 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -54,6 +54,8 @@ func Run(ctx *gctx.Context, client *spotify.Client, args []string) error { return commands.Status(ctx, client) case "devices": return commands.Devices(ctx, client) + case "nowplaying": + return commands.NowPlaying(ctx, client) case "setdevice": return tui.DisplayDevices(ctx, client) default: diff --git a/internal/commands/commands.go b/internal/commands/commands.go index a71e13d..88998ad 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -325,6 +325,14 @@ func Status(ctx *gctx.Context, client *spotify.Client) error { return PrintState(state) } +func NowPlaying(ctx *gctx.Context, client *spotify.Client) error { + current, err := client.PlayerCurrentlyPlaying(ctx) + if err != nil { + return err + } + return PrintPlaying(current) +} + func Shuffle(ctx *gctx.Context, client *spotify.Client) error { state, err := client.PlayerState(ctx) if err != nil { @@ -361,6 +369,10 @@ func TrackList(ctx *gctx.Context, client *spotify.Client, page int) (*spotify.Sa return client.CurrentUsersTracks(ctx, spotify.Limit(50), spotify.Offset((page-1)*50)) } +func GetQueue(ctx *gctx.Context, client *spotify.Client) (*spotify.Queue, error) { + return client.GetQueue(ctx) +} + func Playlists(ctx *gctx.Context, client *spotify.Client, page int) (*spotify.SimplePlaylistPage, error) { return client.CurrentUsersPlaylists(ctx, spotify.Limit(50), spotify.Offset((page-1)*50)) } @@ -380,6 +392,11 @@ func PrintState(state *spotify.PlayerState) error { return nil } +func PrintPlaying(current *spotify.CurrentlyPlaying) error { + fmt.Println(fmt.Sprintf("%s by %s", current.Item.Name, current.Item.Artists[0].Name)) + return nil +} + func PrintDevices(devices []spotify.PlayerDevice) error { out, err := json.MarshalIndent(devices, "", " ") if err != nil {