diff --git a/internal/commands/commands.go b/internal/commands/commands.go index f8506f5..ddb7f52 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -56,6 +56,22 @@ func UserArtists(ctx *gctx.Context, client *spotify.Client, page int) (*spotify. return artists, nil } +func ArtistAlbums(ctx *gctx.Context, client *spotify.Client, artist spotify.ID, page int) (*spotify.SimpleAlbumPage, error) { + albums, err := client.GetArtistAlbums(ctx, artist, []spotify.AlbumType{1, 2, 3, 4}, spotify.Market(spotify.CountryUSA), spotify.Limit(50), spotify.Offset((page-1)*50)) + if err != nil { + return nil, err + } + return albums, nil +} + +func AlbumTracks(ctx *gctx.Context, client *spotify.Client, album spotify.ID, page int) (*spotify.SimpleTrackPage, error) { + tracks, err := client.GetAlbumTracks(ctx, album, spotify.Limit(50), spotify.Offset((page-1)*50), spotify.Market(spotify.CountryUSA)) + if err != nil { + return nil, err + } + return tracks, nil +} + func UserAlbums(ctx *gctx.Context, client *spotify.Client, page int) (*spotify.SavedAlbumPage, error) { albums, err := client.CurrentUsersAlbums(ctx, spotify.Limit(50), spotify.Offset((page-1)*50)) if err != nil { diff --git a/internal/tui/main.go b/internal/tui/main.go index da91ee6..6b5d9b1 100644 --- a/internal/tui/main.go +++ b/internal/tui/main.go @@ -127,9 +127,10 @@ func (m *mainModel) LoadMoreItems() { items := []list.Item{} for _, artist := range artists.Artists { items = append(items, mainItem{ - Name: artist.Name, - ID: artist.ID, - Desc: fmt.Sprintf("%d followers, genres: %s, popularity: %d", artist.Followers.Count, artist.Genres, artist.Popularity), + Name: artist.Name, + ID: artist.ID, + Desc: fmt.Sprintf("%d followers, genres: %s, popularity: %d", artist.Followers.Count, artist.Genres, artist.Popularity), + SpotifyItem: artist.SimpleArtist, }) } for _, item := range items { @@ -146,9 +147,10 @@ func (m *mainModel) LoadMoreItems() { items := []list.Item{} for _, album := range albums.Albums { items = append(items, mainItem{ - Name: album.Name, - ID: album.ID, - Desc: fmt.Sprintf("%s, %d tracks", album.Artists[0].Name, album.Tracks.Total), + Name: album.Name, + ID: album.ID, + Desc: fmt.Sprintf("%s, %d tracks", album.Artists[0].Name, album.Tracks.Total), + SpotifyItem: album.SimpleAlbum, }) } for _, item := range items { @@ -313,6 +315,9 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.list.ResetSelected() m.list.NewStatusMessage("Setting view to tracks") } + case "albums": + album := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) + m.list.NewStatusMessage("Opening " + album.Name) case "playlist": currentlyPlaying = m.list.SelectedItem().FilterValue() m.list.NewStatusMessage("Playing " + currentlyPlaying) @@ -440,9 +445,10 @@ func ArtistsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) } for _, artist := range artists.Artists { items = append(items, mainItem{ - Name: artist.Name, - ID: artist.ID, - Desc: fmt.Sprintf("%d followers, genres: %s, popularity: %d", artist.Followers.Count, artist.Genres, artist.Popularity), + Name: artist.Name, + ID: artist.ID, + Desc: fmt.Sprintf("%d followers, genres: %s, popularity: %d", artist.Followers.Count, artist.Genres, artist.Popularity), + SpotifyItem: artist.SimpleArtist, }) } return items, nil @@ -456,9 +462,10 @@ func AlbumsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) } for _, album := range albums.Albums { items = append(items, mainItem{ - Name: album.Name, - ID: album.ID, - Desc: fmt.Sprintf("%s, %d tracks", album.Artists[0].Name, album.Tracks.Total), + Name: album.Name, + ID: album.ID, + Desc: fmt.Sprintf("%s, %d tracks", album.Artists[0].Name, album.Tracks.Total), + SpotifyItem: album.SimpleAlbum, }) } return items, nil