From 9ad01012a4095a2cf85ddd37367df32cdc3ec658 Mon Sep 17 00:00:00 2001 From: Ted Wexler Date: Fri, 2 Jul 2021 17:23:48 -0400 Subject: [PATCH] add missing files, update library version --- go.mod | 2 +- go.sum | 2 ++ internal/playlist/details.go | 56 +++++++++++++++++++++++++++++++++++ internal/playlist/list.go | 30 +++++++++++++++++++ internal/playlist/playlist.go | 16 ++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 internal/playlist/details.go create mode 100644 internal/playlist/list.go create mode 100644 internal/playlist/playlist.go diff --git a/go.mod b/go.mod index a112d37..70140cd 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/blang/semver v3.5.1+incompatible - github.com/brianstrauch/spotify v0.3.2 + github.com/brianstrauch/spotify v0.4.0 github.com/pkg/browser v0.0.0-20210606212950-a7b7a6107d32 github.com/rhysd/go-github-selfupdate v1.2.3 github.com/spf13/cobra v1.1.3 diff --git a/go.sum b/go.sum index 8f5151e..ffbf83f 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,8 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/brianstrauch/spotify v0.3.1 h1:IBd0vkal0bs+yilvp+6VR4aL9q94qiionwYHETcOHS4= github.com/brianstrauch/spotify v0.3.1/go.mod h1:sImRT74obai+LNgFVxr+qNVq2yt5KEfvNxz6ZDfYWaA= +github.com/brianstrauch/spotify v0.4.0 h1:yy3CSBmM17klWsRemfqlDI9Ai8wuw7tVntVH1XQcHhc= +github.com/brianstrauch/spotify v0.4.0/go.mod h1:sImRT74obai+LNgFVxr+qNVq2yt5KEfvNxz6ZDfYWaA= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= diff --git a/internal/playlist/details.go b/internal/playlist/details.go new file mode 100644 index 0000000..4edc8ae --- /dev/null +++ b/internal/playlist/details.go @@ -0,0 +1,56 @@ +package playlist + +import ( + "errors" + "fmt" + "spotify/internal" + "strings" + + "github.com/spf13/cobra" +) + +func NewDetailsCommand() *cobra.Command { + return &cobra.Command{ + Use: "details", + Aliases: []string{"e"}, + Short: "Get information on a playlist", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + api, err := internal.Authenticate() + if err != nil { + return err + } + playlists, err := api.GetPlaylists() + if err != nil { + return err + } + argLower := strings.ToLower(args[0]) + playlistID := "" + for _, pl := range playlists { + if strings.ToLower(pl.Name) == argLower { + playlistID = pl.ID + } + } + if playlistID == "" { + return errors.New("no such playlist") + } + playlist, err := api.GetPlaylist(playlistID) + if err != nil { + return err + } + fmt.Printf("📝: %s\n", playlist.Name) + fmt.Println("💿 Tracks:") + for i, tr := range playlist.Tracks.Items { + artistNames := make([]string, len(tr.Track.Artists)) + for i, artist := range tr.Track.Artists { + if err := artist.Get(api, &artist); err != nil { + return err + } + artistNames[i] = artist.Name + } + fmt.Printf("%d. %s - %s\n", i+1, strings.Join(artistNames, ". "), tr.Track.Name) + } + return nil + }, + } +} diff --git a/internal/playlist/list.go b/internal/playlist/list.go new file mode 100644 index 0000000..6e0ccd7 --- /dev/null +++ b/internal/playlist/list.go @@ -0,0 +1,30 @@ +package playlist + +import ( + "fmt" + "spotify/internal" + + "github.com/spf13/cobra" +) + +func NewListCommand() *cobra.Command { + return &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "list playlists", + RunE: func(cmd *cobra.Command, args []string) error { + api, err := internal.Authenticate() + if err != nil { + return err + } + playlists, err := api.GetPlaylists() + if err != nil { + return err + } + for _, pl := range playlists { + fmt.Println(pl.Name) + } + return nil + }, + } +} diff --git a/internal/playlist/playlist.go b/internal/playlist/playlist.go new file mode 100644 index 0000000..65b55ad --- /dev/null +++ b/internal/playlist/playlist.go @@ -0,0 +1,16 @@ +package playlist + +import ( + "github.com/spf13/cobra" +) + +func NewCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "playlist", + Aliases: []string{"p"}, + Short: "do things with playlists", + } + cmd.AddCommand(NewListCommand()) + cmd.AddCommand(NewDetailsCommand()) + return cmd +}