link
This commit is contained in:
parent
2a4eb07b3a
commit
ed4bf62443
32
cmd/link.go
Normal file
32
cmd/link.go
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
|
||||
*/
|
||||
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)
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user