Skip to content

Commit

Permalink
add missing files, update library version
Browse files Browse the repository at this point in the history
  • Loading branch information
twexler committed Jul 2, 2021
1 parent bae6d85 commit 9ad0101
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
56 changes: 56 additions & 0 deletions internal/playlist/details.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
30 changes: 30 additions & 0 deletions internal/playlist/list.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
16 changes: 16 additions & 0 deletions internal/playlist/playlist.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9ad0101

Please # to comment.