Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 4 additions & 52 deletions album.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spotify

import (
"context"
"errors"
"fmt"
"strconv"
"strings"
Expand All @@ -15,12 +14,7 @@ type SimpleAlbum struct {
Name string `json:"name"`
// A slice of [SimpleArtist].
Artists []SimpleArtist `json:"artists"`
// The field is present when getting an artist’s
// albums. Possible values are “album”, “single”,
// “compilation”, “appears_on”. Compare to album_type
// this field represents relationship between the artist
// and the album.
AlbumGroup string `json:"album_group"`

// The type of the album: one of "album",
// "single", or "compilation".
AlbumType string `json:"album_type"`
Expand All @@ -32,13 +26,6 @@ type SimpleAlbum struct {
//
// [Spotify URI]: https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids
URI URI `json:"uri"`
// The markets in which the album is available, identified using
// [ISO 3166-1 alpha-2] country codes. Note that an album is considered
// available in a market when at least 1 of its tracks is available in that
// market.
//
// [ISO 3166-1 alpha-2]: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
AvailableMarkets []string `json:"available_markets"`
// A link to the Web API endpoint providing full
// details of the album.
Endpoint string `json:"href"`
Expand Down Expand Up @@ -88,14 +75,9 @@ type Copyright struct {
// FullAlbum provides extra album data in addition to the data provided by [SimpleAlbum].
type FullAlbum struct {
SimpleAlbum
Copyrights []Copyright `json:"copyrights"`
Genres []string `json:"genres"`
// The popularity of the album, represented as an integer between 0 and 100,
// with 100 being the most popular. Popularity of an album is calculated
// from the popularity of the album's individual tracks.
Popularity Numeric `json:"popularity"`
Tracks SimpleTrackPage `json:"tracks"`
ExternalIDs map[string]string `json:"external_ids"`
Copyrights []Copyright `json:"copyrights"`
Genres []string `json:"genres"`
Tracks SimpleTrackPage `json:"tracks"`
}

// SavedAlbum provides info about an album saved to a user's account.
Expand Down Expand Up @@ -136,36 +118,6 @@ func toStringSlice(ids []ID) []string {
return result
}

// GetAlbums gets Spotify Catalog information for [multiple albums], given their
// [Spotify ID]s. It supports up to 20 IDs in a single call. Albums are returned
// in the order requested. If an album is not found, that position in the
// result slice will be nil.
//
// Supported options: [Market].
//
// [multiple albums]: https://developer.spotify.com/documentation/web-api/reference/get-multiple-albums
// [Spotify ID]: https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids
func (c *Client) GetAlbums(ctx context.Context, ids []ID, opts ...RequestOption) ([]*FullAlbum, error) {
if len(ids) > 20 {
return nil, errors.New("spotify: exceeded maximum number of albums")
}
params := processOptions(opts...).urlParams
params.Set("ids", strings.Join(toStringSlice(ids), ","))

spotifyURL := fmt.Sprintf("%salbums?%s", c.baseURL, params.Encode())

var a struct {
Albums []*FullAlbum `json:"albums"`
}

err := c.get(ctx, spotifyURL, &a)
if err != nil {
return nil, err
}

return a.Albums, nil
}

// AlbumType represents the type of an album. It can be used to filter
// results when searching for albums.
type AlbumType int
Expand Down
39 changes: 0 additions & 39 deletions album_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,6 @@ func TestFindAlbumBadID(t *testing.T) {
}
}

// The example from https://developer.spotify.com/web-api/get-several-albums/
func TestFindAlbums(t *testing.T) {
client, server := testClientFile(http.StatusOK, "test_data/find_albums.txt")
defer server.Close()

res, err := client.GetAlbums(context.Background(), []ID{"41MnTivkwTO3UUJ8DrqEJJ", "6JWc4iAiJ9FjyK0B59ABb4", "6UXCm6bOO4gFlDQZV5yL37", "0X8vBD8h1Ga9eLT8jx9VCC"})
if err != nil {
t.Fatal(err)
}
if len(res) != 4 {
t.Fatalf("Expected 4 albums, got %d", len(res))
}
expectedAlbums := []string{
"The Best Of Keane (Deluxe Edition)",
"Strangeland",
"Night Train",
"Mirrored",
}
for i, name := range expectedAlbums {
if res[i].Name != name {
t.Error("Expected album", name, "but got", res[i].Name)
}
}
release := res[0].ReleaseDateTime()
if release.Year() != 2013 ||
release.Month() != 11 ||
release.Day() != 8 {
t.Errorf("Expected release 2013-11-08, got %d-%02d-%02d\n",
release.Year(), release.Month(), release.Day())
}
releaseMonthPrecision := res[3].ReleaseDateTime()
if releaseMonthPrecision.Year() != 2007 ||
releaseMonthPrecision.Month() != 3 ||
releaseMonthPrecision.Day() != 1 {
t.Errorf("Expected release 2007-03-01, got %d-%02d-%02d\n",
releaseMonthPrecision.Year(), releaseMonthPrecision.Month(), releaseMonthPrecision.Day())
}
}

func TestFindAlbumTracks(t *testing.T) {
client, server := testClientFile(http.StatusOK, "test_data/find_album_tracks.txt")
defer server.Close()
Expand Down
46 changes: 1 addition & 45 deletions artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ type SimpleArtist struct {
// FullArtist provides extra artist data in addition to what is provided by [SimpleArtist].
type FullArtist struct {
SimpleArtist
// The popularity of the artist, expressed as an integer between 0 and 100.
// The artist's popularity is calculated from the popularity of the artist's tracks.
Popularity Numeric `json:"popularity"`
// A list of genres the artist is associated with. For example, "Prog Rock"
// or "Post-Grunge". If not yet classified, the slice is empty.
Genres []string `json:"genres"`
Followers Followers `json:"followers"`
Genres []string `json:"genres"`
// Images of the artist in various sizes, widest first.
Images []Image `json:"images"`
}
Expand All @@ -44,46 +40,6 @@ func (c *Client) GetArtist(ctx context.Context, id ID) (*FullArtist, error) {
return &a, nil
}

// GetArtists gets spotify catalog information for several artists based on their
// Spotify IDs. It supports up to 50 artists in a single call. Artists are
// returned in the order requested. If an artist is not found, that position
// in the result will be nil. Duplicate IDs will result in duplicate artists
// in the result.
func (c *Client) GetArtists(ctx context.Context, ids ...ID) ([]*FullArtist, error) {
spotifyURL := fmt.Sprintf("%sartists?ids=%s", c.baseURL, strings.Join(toStringSlice(ids), ","))

var a struct {
Artists []*FullArtist
}

err := c.get(ctx, spotifyURL, &a)
if err != nil {
return nil, err
}

return a.Artists, nil
}

// GetArtistsTopTracks gets Spotify catalog information about an artist's top
// tracks in a particular country. It returns a maximum of 10 tracks. The
// country is specified as an [ISO 3166-1 alpha-2] country code.
//
// [ISO 3166-1 alpha-2]: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
func (c *Client) GetArtistsTopTracks(ctx context.Context, artistID ID, country string) ([]FullTrack, error) {
spotifyURL := fmt.Sprintf("%sartists/%s/top-tracks?country=%s", c.baseURL, artistID, country)

var t struct {
Tracks []FullTrack `json:"tracks"`
}

err := c.get(ctx, spotifyURL, &t)
if err != nil {
return nil, err
}

return t.Tracks, nil
}

// GetRelatedArtists gets Spotify catalog information about artists similar to a
// given artist. Similarity is based on analysis of the Spotify community's
// listening history. This function returns up to 20 artists that are considered
Expand Down
30 changes: 0 additions & 30 deletions artist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,11 @@ func TestFindArtist(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if followers := artist.Followers.Count; followers != 2265279 {
t.Errorf("Got %d followers, want 2265279\n", followers)
}
if artist.Name != "Pitbull" {
t.Error("Got ", artist.Name, ", wanted Pitbull")
}
}

func TestArtistTopTracks(t *testing.T) {
client, server := testClientFile(http.StatusOK, "test_data/artist_top_tracks.txt")
defer server.Close()

tracks, err := client.GetArtistsTopTracks(context.Background(), ID("43ZHCT0cAZBISjO8DG9PnE"), "SE")
if err != nil {
t.Fatal(err)
}

if l := len(tracks); l != 10 {
t.Fatalf("Got %d tracks, expected 10\n", l)
}
track := tracks[9]
if track.Name != "(You're The) Devil in Disguise" {
t.Error("Incorrect track name")
}
if track.TrackNumber != 24 {
t.Errorf("Track number was %d, expected 24\n", track.TrackNumber)
}
}

func TestRelatedArtists(t *testing.T) {
client, server := testClientFile(http.StatusOK, "test_data/related_artists.txt")
defer server.Close()
Expand All @@ -131,9 +107,6 @@ func TestRelatedArtists(t *testing.T) {
if a2.Name != "Carl Perkins" {
t.Error("Expected Carl Perkins, got ", a2.Name)
}
if a2.Popularity != 54 {
t.Errorf("Expected popularity 54, got %d\n", a2.Popularity)
}
}

func TestRelatedArtistsWithFloats(t *testing.T) {
Expand All @@ -151,9 +124,6 @@ func TestRelatedArtistsWithFloats(t *testing.T) {
if a2.Name != "Carl Perkins" {
t.Error("Expected Carl Perkins, got ", a2.Name)
}
if a2.Popularity != 54 {
t.Errorf("Expected popularity 54, got %d\n", a2.Popularity)
}
}

func TestArtistAlbumsFiltered(t *testing.T) {
Expand Down
76 changes: 0 additions & 76 deletions category.go

This file was deleted.

Loading
Loading