From ed4bf624438c900907cc2a63c79b53f4cd981967 Mon Sep 17 00:00:00 2001 From: jjohnstondev Date: Mon, 9 Jan 2023 22:37:44 -0800 Subject: [PATCH] link --- cmd/link.go | 32 ++++++++++++++++++++++++++++++++ internal/commands/commands.go | 8 ++++++++ 2 files changed, 40 insertions(+) create mode 100644 cmd/link.go diff --git a/cmd/link.go b/cmd/link.go new file mode 100644 index 0000000..ef28497 --- /dev/null +++ b/cmd/link.go @@ -0,0 +1,32 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + "os" + + "gospt/internal/commands" + + "github.com/spf13/cobra" +) + +// linkCmd represents the link command +var linkCmd = &cobra.Command{ + Use: "link", + Short: "Print link to currently playing song", + Long: `Print link to currently playing song`, + Run: func(cmd *cobra.Command, args []string) { + link, err := commands.Link(ctx, client) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println(link) + }, +} + +func init() { + rootCmd.AddCommand(linkCmd) +} diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 0d80e5c..160688b 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -378,6 +378,14 @@ func Status(ctx *gctx.Context, client *spotify.Client) error { return PrintState(state) } +func Link(ctx *gctx.Context, client *spotify.Client) (string, error) { + state, err := client.PlayerState(ctx) + if err != nil { + return "", err + } + return state.Item.ExternalURLs["spotify"], nil +} + func NowPlaying(ctx *gctx.Context, client *spotify.Client) error { current, err := client.PlayerCurrentlyPlaying(ctx) if err != nil {