applemusic

package module
Version: v0.0.0-...-fa57b98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2020 License: MIT Imports: 11 Imported by: 0

README

go-apple-music

GoDoc Build Status Go Report Card

A Go client library for accessing the Apple Music API.

This library is heavily inspired by go-github.

Installation

Use go get.

go get -u github.com/minchao/go-apple-music

Usage

import "github.com/minchao/go-apple-music"

Construct a new API client, then use to access the Apple Music API. For example:

ctx := context.Background()
tp := applemusic.Transport{Token: "APPLE_MUSIC_API_TOKEN"}
client := applemusic.NewClient(tp.Client())

// Fetch all the storefronts in alphabetical order
storefronts, _, err := client.Storefront.GetAll(ctx, nil)
Create a developer token

Use the token generator tool to quickly create a developer token.

$ cd examples/token-genrator
$ go build

Usage:

$ ./generate-toke
Usage: generate-token [options]
  -k string
        MusicKit key
  -l int
        TTL (time-to-live), must not be greater than 15777000 (6 months in seconds) (default 3600)
  -pf string
        MusicKit private key, the path of private key file (.p8)
  -pk string
        MusicKit private key, enter string without BEGIN and END annotations
  -t string
        Team ID

Run:

$ ./generate-toke \
    -k=MUSICKIT_KEY \
    -t=TEAM_ID \
    -pf=MUSICKIT_PRIVATE_KEY_FILE
Create a Music User Token

Use the requestUserToken(forDeveloperToken:completionHandler:) method in the StoreKit framework.

Todo

  • Fetch Recent
    • Get recently played
    • Get recent stations
  • Manage Ratings
    • Get personal album rating
    • Get multiple personal album ratings
    • Add a personal album rating
    • Delete a personal album rating
    • Get personal music video rating
    • Get multiple personal music video ratings
    • Add a personal music video rating
    • Delete a personal music video rating
    • Get personal playlist rating
    • Get multiple personal playlist ratings
    • Add a personal playlist rating
    • Delete a personal playlist rating
    • Get personal song rating
    • Get multiple personal song ratings
    • Add a personal song rating
    • Delete a personal song rating
    • Get personal station rating
    • Get multiple personal station ratings
    • Add a personal station rating
    • Delete a personal station rating
  • Fetch Recommendations
    • Get default recommendations
    • Get album recommendations
    • Get playlist recommendations
    • Get a recommendation
    • Get multiple recommendations

License

See the LICENSE file for license rights and limitations (MIT).

Documentation

Index

Constants

View Source
const (
	// PlaylistTypeUserShared is a playlist created and shared by an Apple Music user.
	PlaylistTypeUserShared = PlaylistType("user-shared")

	// PlaylistTypeEditorial is a playlist created by an Apple Music curator.
	PlaylistTypeEditorial = PlaylistType("editorial")

	// PlaylistTypeExternal is a playlist created by an non-Apple curator or brand.
	PlaylistTypeExternal = PlaylistType("external")

	// PlaylistTypePersonalMix is a personalized playlist for an Apple Music user.
	PlaylistTypePersonalMix = PlaylistType("personal-mix")
)

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors.

Types

type Activities

type Activities struct {
	Data []Activity `json:"data"`
	Href string     `json:"href,omitempty"`
	Next string     `json:"next,omitempty"`
}

Activities represents a list of activities.

type Activity

type Activity struct {
	Id            string                `json:"id"`
	Type          string                `json:"type"`
	Href          string                `json:"href"`
	Attributes    ActivityAttributes    `json:"attributes"`
	Relationships ActivityRelationships `json:"relationships"`
}

Activity represents an activity.

type ActivityAttributes

type ActivityAttributes struct {
	URL            string          `json:"url"`
	Name           string          `json:"name"`
	Artwork        Artwork         `json:"artwork"`
	EditorialNotes *EditorialNotes `json:"editorialNotes,omitempty"`
}

ActivityAttributes represents the attributes of the resource.

type ActivityRelationships

type ActivityRelationships struct {
	Playlists Playlists `json:"playlists"` // Default inclusion: Identifiers only
}

ActivityRelationships represents a to-one or to-many relationship from one resource object to others.

type Album

type Album struct {
	Id            string             `json:"id"`
	Type          string             `json:"type"`
	Href          string             `json:"href"`
	Attributes    AlbumAttributes    `json:"attributes"`
	Relationships AlbumRelationships `json:"relationships"`
}

Album represents an album.

type AlbumAttributes

type AlbumAttributes struct {
	ArtistName     string          `json:"artistName"`
	Artwork        Artwork         `json:"artwork"`
	ContentRating  string          `json:"contentRating,omitempty"`
	Copyright      string          `json:"copyright"`
	EditorialNotes *EditorialNotes `json:"editorialNotes,omitempty"`
	GenreNames     []string        `json:"genreNames"`
	IsComplete     bool            `json:"isComplete"`
	IsSingle       bool            `json:"isSingle"`
	Name           string          `json:"name"`
	RecordLabel    string          `json:"recordLabel"`
	ReleaseDate    string          `json:"releaseDate"`
	PlayParams     *PlayParameters `json:"playParams,omitempty"`
	TrackCount     int64           `json:"trackCount"`
	URL            string          `json:"url"`
}

AlbumAttributes represents the attributes of the resource.

type AlbumRelationships

type AlbumRelationships struct {
	Artists Artists `json:"artists"`          // Default inclusion: Identifiers only
	Genres  *Genres `json:"genres,omitempty"` // Default inclusion: None
	Tracks  Tracks  `json:"tracks"`           // The songs and music videos on the album. Default inclusion: Objects
}

AlbumRelationships represents a to-one or to-many relationship from one resource object to others.

type Albums

type Albums struct {
	Data []Album `json:"data"`
	Href string  `json:"href,omitempty"`
	Next string  `json:"next,omitempty"`
}

Albums represents a list of albums.

type AppleCurators

type AppleCurators struct {
	Data []Curator `json:"data"`
	Href string    `json:"href,omitempty"`
	Next string    `json:"next,omitempty"`
}

AppleCurators represents a list of apple curators.

type Artist

type Artist struct {
	Id            string              `json:"id"`
	Type          string              `json:"type"`
	Href          string              `json:"href"`
	Attributes    ArtistAttributes    `json:"attributes"`
	Relationships ArtistRelationships `json:"relationships"`
}

Artist represents an artist of an album.

type ArtistAttributes

type ArtistAttributes struct {
	GenreNames     []string        `json:"genreNames"`
	EditorialNotes *EditorialNotes `json:"editorialNotes,omitempty"`
	Name           string          `json:"name"`
	URL            string          `json:"url"`
}

ArtistAttributes represents the attributes of the resource.

type ArtistRelationships

type ArtistRelationships struct {
	Albums      Albums       `json:"albums"`
	Genres      *Genres      `json:"genres,omitempty"`
	MusicVideos *MusicVideos `json:"music-videos,omitempty"`
	Playlists   *Playlists   `json:"playlists,omitempty"`
}

ArtistRelationships represents a to-one or to-many relationship from one resource object to others.

type Artists

type Artists struct {
	Data []Artist `json:"data"`
	Href string   `json:"href,omitempty"`
	Next string   `json:"next,omitempty"`
}

Artists represents a list of artists.

type Artwork

type Artwork struct {
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	URL        string `json:"url"`
	BgColor    string `json:"bgColor"`
	TextColor1 string `json:"textColor1"`
	TextColor2 string `json:"textColor2"`
	TextColor3 string `json:"textColor3"`
	TextColor4 string `json:"textColor4"`
	IsMosaic   bool   `json:"isMosaic,omitempty"` // Undocumented, Used in Playlists.
}

Artwork represents an artwork.

type CatalogService

type CatalogService service

CatalogService handles communication with the catalog related methods of the Apple Music API.

func (*CatalogService) GetActivitiesByIds

func (s *CatalogService) GetActivitiesByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Activities, *Response, error)

GetActivitiesByIds fetches one or more activities using their identifiers.

func (*CatalogService) GetActivity

func (s *CatalogService) GetActivity(ctx context.Context, storefront, id string, opt *Options) (*Activities, *Response, error)

GetActivity fetches an activity using its identifier.

func (*CatalogService) GetAlbum

func (s *CatalogService) GetAlbum(ctx context.Context, storefront, id string, opt *Options) (*Albums, *Response, error)

GetAlbum fetches an album using its identifier.

func (*CatalogService) GetAlbumsByIds

func (s *CatalogService) GetAlbumsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Albums, *Response, error)

GetAlbumsByIds fetches one or more albums using their identifiers.

func (*CatalogService) GetAllCharts

func (s *CatalogService) GetAllCharts(ctx context.Context, storefront string, opt *ChartsOptions) (*Charts, *Response, error)

GetAllCharts fetches one or more charts.

func (*CatalogService) GetAllGenres

func (s *CatalogService) GetAllGenres(ctx context.Context, storefront string, opt *PageOptions) (*Genres, *Response, error)

GetAllGenres fetches all genres for the current top charts.

func (*CatalogService) GetAppleCurator

func (s *CatalogService) GetAppleCurator(ctx context.Context, storefront, id string, opt *Options) (*AppleCurators, *Response, error)

GetAppleCurator fetches an apple curator using its identifier.

func (*CatalogService) GetAppleCuratorsByIds

func (s *CatalogService) GetAppleCuratorsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*AppleCurators, *Response, error)

GetAppleCuratorsByIds fetches one or more apple curators using their identifiers.

func (*CatalogService) GetArtist

func (s *CatalogService) GetArtist(ctx context.Context, storefront, id string, opt *Options) (*Artists, *Response, error)

GetArtist fetches a artist using its identifier.

func (*CatalogService) GetArtistsByIds

func (s *CatalogService) GetArtistsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Artists, *Response, error)

GetArtistsByIds fetches one or more artists using their identifiers.

func (*CatalogService) GetCurator

func (s *CatalogService) GetCurator(ctx context.Context, storefront, id string, opt *Options) (*Curators, *Response, error)

GetCurator fetches an curator using its identifier.

func (*CatalogService) GetCuratorsByIds

func (s *CatalogService) GetCuratorsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Curators, *Response, error)

GetCuratorsByIds fetches one or more curators using their identifiers.

func (*CatalogService) GetGenre

func (s *CatalogService) GetGenre(ctx context.Context, storefront, id string, opt *Options) (*Genres, *Response, error)

GetGenre fetches a genre using its identifier.

func (*CatalogService) GetGenresByIds

func (s *CatalogService) GetGenresByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Genres, *Response, error)

GetGenresByIds fetches one or more genres.

func (*CatalogService) GetMusicVideo

func (s *CatalogService) GetMusicVideo(ctx context.Context, storefront, id string, opt *Options) (*MusicVideos, *Response, error)

GetMusicVideo fetches a music video using its identifier.

func (*CatalogService) GetMusicVideosByIds

func (s *CatalogService) GetMusicVideosByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*MusicVideos, *Response, error)

GetMusicVideosByIds fetches one or more music videos using their identifiers.

func (*CatalogService) GetPlaylist

func (s *CatalogService) GetPlaylist(ctx context.Context, storefront, id string, opt *Options) (*Playlists, *Response, error)

GetPlaylist fetches a playlist using its identifier.

func (*CatalogService) GetPlaylistsByIds

func (s *CatalogService) GetPlaylistsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Playlists, *Response, error)

GetPlaylistsByIds fetches one or more playlists using their identifiers.

func (*CatalogService) GetSong

func (s *CatalogService) GetSong(ctx context.Context, storefront, id string, opt *Options) (*Songs, *Response, error)

GetSong fetches a song using its identifier.

func (*CatalogService) GetSongsByIds

func (s *CatalogService) GetSongsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Songs, *Response, error)

GetSongsByIds fetches one or more songs using their identifiers.

func (*CatalogService) GetStation

func (s *CatalogService) GetStation(ctx context.Context, storefront, id string, opt *Options) (*Stations, *Response, error)

GetStation fetches a station using its identifier.

func (*CatalogService) GetStationsByIds

func (s *CatalogService) GetStationsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Stations, *Response, error)

GetStationsByIds fetches one or more stations using their identifiers.

func (*CatalogService) Search

func (s *CatalogService) Search(ctx context.Context, storefront string, opt *SearchOptions) (*Search, *Response, error)

Search searches the catalog using a query.

func (*CatalogService) SearchHints

func (s *CatalogService) SearchHints(ctx context.Context, storefront string, opt *SearchHintsOptions) (*SearchHints, *Response, error)

SearchHints fetches the search term results for a hint.

type ChartAlbums

type ChartAlbums struct {
	Name  string `json:"name"`
	Chart string `json:"chart"`
	Albums
}

ChartAlbums represents a chart of albums.

type ChartMusicVideos

type ChartMusicVideos struct {
	Name  string `json:"name"`
	Chart string `json:"chart"`
	MusicVideos
}

ChartMusicVideos represents a chart of music videos.

type ChartPlaylists

type ChartPlaylists struct {
	Name  string `json:"name"`
	Chart string `json:"chart"`
	Playlists
}

ChartPlaylists represent a chart of playlists.

type ChartResults

type ChartResults struct {
	Albums      *[]ChartAlbums      `json:"albums,omitempty"`
	Songs       *[]ChartSongs       `json:"songs,omitempty"`
	MusicVideos *[]ChartMusicVideos `json:"music-videos,omitempty"`
	Playlists   *[]ChartPlaylists   `json:"playlists,omitempty"`
}

ChartResults represents a results, that contains chart collections.

type ChartSongs

type ChartSongs struct {
	Name  string `json:"name"`
	Chart string `json:"chart"`
	Songs
}

ChartSongs represents a chart of songs.

type Charts

type Charts struct {
	Results ChartResults `json:"results"`
}

Charts represents the result of one or more charts.

type ChartsOptions

type ChartsOptions struct {
	// A list of the types of charts to include in the results.
	// The possible values are albums, songs, and music-videos.
	Types string `url:"types"`

	// (Optional) The localization to use, specified by a language tag.
	// The possible values are in the supportedLanguageTags array belonging to the Storefront object specified by storefront.
	// Otherwise, the storefront’s defaultLanguageTag is used.
	Language string `url:"l,omitempty"`

	// (Optional) The chart to fetch for the specified types.
	// For possible values, get all the charts by sending this endpoint without the chart parameter.
	// The possible values for this parameter are the chart attributes of the Chart objects in the response.
	Chart string `url:"chart,omitempty"`

	// (Optional) The identifier for the genre to use in the chart results. To get the genre identifiers.
	Genre string `url:"genre,omitempty"`

	// (Optional) The number of resources to include per chart.
	// The default value is 20 and the maximum value is 50.
	Limit int `url:"limit,omitempty"`

	// (Optional; only with chart specified) The next page or group of objects to fetch.
	Offset int `url:"offset,omitempty"`
}

ChartsOptions specifies the parameters to fetch charts.

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string

	// Services used for talking to different parts of the Apple Music API.
	Storefront *StorefrontsService
	Catalog    *CatalogService
	Me         *MeService
	// contains filtered or unexported fields
}

A Client manages communication with the Apple Music API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Apple Music API client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response.

The provided ctx must be non-nil. If it is canceled or time out, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request.

type Curator

type Curator struct {
	Id            string               `json:"id"`
	Type          string               `json:"type"`
	Href          string               `json:"href"`
	Attributes    CuratorAttributes    `json:"attributes"`
	Relationships CuratorRelationships `json:"relationships"`
}

Curator represents a curator of resources.

type CuratorAttributes

type CuratorAttributes struct {
	URL            string          `json:"url"`
	Name           string          `json:"name"`
	Artwork        Artwork         `json:"artwork"`
	EditorialNotes *EditorialNotes `json:"editorialNotes,omitempty"`
}

CuratorAttributes represents the attributes of the resource.

type CuratorRelationships

type CuratorRelationships struct {
	Playlists Playlists `json:"playlists"` // Default inclusion: Identifiers only
}

CuratorRelationships represents a to-one or to-many relationship from one resource object to others.

type Curators

type Curators struct {
	Data []Curator `json:"data"`
	Href string    `json:"href,omitempty"`
	Next string    `json:"next,omitempty"`
}

Curators represents a list of curators.

type EditorialNotes

type EditorialNotes struct {
	Standard string `json:"standard"`
	Name     string `json:"name,omitempty"` // Undocumented
	Short    string `json:"short"`
}

EditorialNotes represents notes.

type Error

type Error struct {
	Id     string      `json:"id"`
	About  string      `json:"about"`
	Status string      `json:"status"`
	Code   string      `json:"code"`
	Title  string      `json:"title"`
	Detail string      `json:"detail"`
	Source Source      `json:"source"`
	Meta   interface{} `json:"meta"`
}

Error contains information about an error that occurred while processing a request.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Errors   []Error `json:"errors"`
}

ErrorResponse reports one or more errors caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Genre

type Genre struct {
	Id         string          `json:"id"`
	Type       string          `json:"type"`
	Href       string          `json:"href"`
	Attributes GenreAttributes `json:"attributes"`
}

Genre represents a genre for resources.

type GenreAttributes

type GenreAttributes struct {
	Name string `json:"name"`
}

GenreAttributes represents the attributes of the resource.

type Genres

type Genres struct {
	Data []Genre `json:"data"`
	Href string  `json:"href,omitempty"`
	Next string  `json:"next,omitempty"`
}

Genres represents a list of genres.

type HistoryHeavyRotation

type HistoryHeavyRotation struct {
	Data []Resource `json:"data"`
	Href string     `json:"href,omitempty"`
	Next string     `json:"next,omitempty"`
}

HistoryHeavyRotation represents a list of heavy rotation content.

type IdsOptions

type IdsOptions struct {
	Ids string `url:"ids"`

	Options
}

type LibraryMusicVideo

type LibraryMusicVideo struct {
	Id         string                      `json:"id"`
	Type       string                      `json:"type"`
	Href       string                      `json:"href,omitempty"`
	Attributes LibraryMusicVideoAttributes `json:"attributes,omitempty"`
}

LibraryMusicVideo represents a Resource object that represents a library music video.

type LibraryMusicVideoAttributes

type LibraryMusicVideoAttributes struct {
	AlbumName        string         `json:"albumName"`
	ArtistName       string         `json:"artistName"`
	Artwork          Artwork        `json:"artwork"`
	ContentRating    string         `json:"contentRating,omitempty"`
	DurationInMillis int64          `json:"durationInMillis,omitempty"`
	Name             string         `json:"name"`
	PlayParams       PlayParameters `json:"playParams,omitempty"`
	TrackNumber      int            `json:"trackNumber,omitempty"`
}

LibraryMusicVideoAttributes represents the attributes of library music video object.

type LibraryMusicVideos

type LibraryMusicVideos struct {
	Data []LibraryMusicVideo `json:"data"`
	Href string              `json:"href,omitempty"`
	Next string              `json:"next,omitempty"`
}

LibraryMusicVideos represents a list of library music video.

type LibraryPlaylist

type LibraryPlaylist struct {
	Id            string                       `json:"id"`
	Type          string                       `json:"type"`
	Href          string                       `json:"href"`
	Attributes    LibraryPlaylistAttributes    `json:"attributes"`
	Relationships LibraryPlaylistRelationships `json:"relationships"`
}

LibraryPlaylist represents a library playlist.

type LibraryPlaylistAttributes

type LibraryPlaylistAttributes struct {
	Artwork     *Artwork        `json:"artwork"`
	Description *EditorialNotes `json:"description"`
	Name        string          `json:"name"`
	PlayParams  *PlayParameters `json:"playParams"`
	CanDelete   bool            `json:"canDelete"`
	CanEdit     bool            `json:"canEdit"`
}

LibraryPlaylistAttributes represents the attributes of library playlist.

type LibraryPlaylistRelationships

type LibraryPlaylistRelationships struct {
	Tracks Tracks `json:"tracks"` // The library songs and library music videos included in the playlist. Only available when fetching single library playlist resource by ID.
}

LibraryPlaylistRelationships represents a to-one or to-many relationship from one resource object to others.

type LibraryPlaylistTracks

type LibraryPlaylistTracks struct {
	Data []Song `json:"data"`
	Next string `json:"next,omitempty"`
}

type LibraryPlaylists

type LibraryPlaylists struct {
	Data []LibraryPlaylist `json:"data"`
	Next string            `json:"next,omitempty"`
}

LibraryPlaylists represents a list of library playlist.

type LibraryPlaylistsByIdsOptions

type LibraryPlaylistsByIdsOptions struct {
	Ids string `url:"ids"`

	Options
}

LibraryPlaylistsByIdsOptions specifies the optional parameters to the MeService.GetLibraryPlaylistsByIds method.

type LibrarySong

type LibrarySong struct {
	Id         string                `json:"id"`
	Type       string                `json:"type"`
	Href       string                `json:"href,omitempty"`
	Attributes LibrarySongAttributes `json:"attributes,omitempty"`
}

LibrarySong represents a Resource object that represents a library song.

type LibrarySongAttributes

type LibrarySongAttributes struct {
	AlbumName        string         `json:"albumName"`
	ArtistName       string         `json:"artistName"`
	Artwork          Artwork        `json:"artwork"`
	ContentRating    string         `json:"contentRating,omitempty"`
	DiscNumber       int            `json:"discNumber"`
	DurationInMillis int64          `json:"durationInMillis,omitempty"`
	Name             string         `json:"name"`
	PlayParams       PlayParameters `json:"playParams,omitempty"`
	TrackNumber      int            `json:"trackNumber"`
}

LibrarySongAttributes represents the attributes of library song object.

type LibrarySongs

type LibrarySongs struct {
	Data []LibrarySong `json:"data"`
	Href string        `json:"href,omitempty"`
	Next string        `json:"next,omitempty"`
}

LibrarySongs represents a list of library songs.

type MeService

type MeService service

MeService handles communication with the me related methods of the Apple Music API.

func (*MeService) GetAllLibraryMusicVideos

func (s *MeService) GetAllLibraryMusicVideos(ctx context.Context, opt *PageOptions) (*LibraryMusicVideos, *Response, error)

GetAllLibraryMusicVideos fetches all the library music videos in alphabetical order.

func (*MeService) GetAllLibraryPlaylists

func (s *MeService) GetAllLibraryPlaylists(ctx context.Context, opt *PageOptions) (*LibraryPlaylists, *Response, error)

GetAllLibraryPlaylists fetches all the library playlists in alphabetical order.

func (*MeService) GetAllLibrarySongs

func (s *MeService) GetAllLibrarySongs(ctx context.Context, opt *PageOptions) (*LibrarySongs, *Response, error)

GetAllLibrarySongs fetches all the library songs in alphabetical order.

func (*MeService) GetHistoryHeavyRotation

func (s *MeService) GetHistoryHeavyRotation(ctx context.Context, opt *PageOptions) (*HistoryHeavyRotation, *Response, error)

GetHistoryHeavyRotation fetches the resources in heavy rotation for the user.

func (*MeService) GetLibraryPlaylist

func (s *MeService) GetLibraryPlaylist(ctx context.Context, id string, opt *Options) (*LibraryPlaylists, *Response, error)

GetLibraryPlaylist fetches a library playlist using its identifier.

func (*MeService) GetLibraryPlaylistTracks

func (s *MeService) GetLibraryPlaylistTracks(ctx context.Context, id string, opt *Options) ([]Song, error)

GetLibraryPlaylist fetches a library playlist using its identifier.

func (*MeService) GetLibraryPlaylistsByIds

func (s *MeService) GetLibraryPlaylistsByIds(ctx context.Context, opt *LibraryPlaylistsByIdsOptions) (*LibraryPlaylists, *Response, error)

GetLibraryPlaylistsByIds fetches one or more library playlists using their identifiers.

func (*MeService) GetStorefront

func (s *MeService) GetStorefront(ctx context.Context, opt *PageOptions) (*Storefronts, *Response, error)

GetStorefront fetches a user’s storefront.

type MusicVideo

type MusicVideo struct {
	Id            string                  `json:"id"`
	Type          string                  `json:"type"`
	Href          string                  `json:"href"`
	Attributes    MusicVideoAttributes    `json:"attributes"`
	Relationships MusicVideoRelationships `json:"relationships"`
}

MusicVideo represents a music video.

type MusicVideoAttributes

type MusicVideoAttributes struct {
	URL              string          `json:"url"`
	Name             string          `json:"name"`
	GenreNames       []string        `json:"genreNames"`
	ISRC             string          `json:"isrc"`
	ArtistName       string          `json:"artistName"`
	ReleaseDate      string          `json:"releaseDate"`
	Artwork          Artwork         `json:"artwork"`
	PlayParams       *PlayParameters `json:"playParams,omitempty"`
	DurationInMillis int64           `json:"durationInMillis,omitempty"`
	ContentRating    string          `json:"contentRating,omitempty"`
	EditorialNotes   *EditorialNotes `json:"editorialNotes,omitempty"`
	TrackNumber      int             `json:"trackNumber,omitempty"`
	VideoSubType     string          `json:"videoSubType,omitempty"`
}

MusicVideoAttributes represents the attributes of the resource.

type MusicVideoRelationships

type MusicVideoRelationships struct {
	Albums  Albums  `json:"albums"`           // Default inclusion: Identifiers only
	Artists Artists `json:"artists"`          // Default inclusion: Identifiers only
	Genres  *Genres `json:"genres,omitempty"` // Default inclusion: None
}

MusicVideoRelationships represents a to-one or to-many relationship from one resource object to others.

type MusicVideos

type MusicVideos struct {
	Data []MusicVideo `json:"data"`
	Href string       `json:"href,omitempty"`
	Next string       `json:"next,omitempty"`
}

MusicVideos represents a list of music videos.

type Options

type Options struct {
	// The localization to use, specified by a language tag.
	// Any supported language tag may be used here, if one is not specified then en-us is used.
	Language string `url:"l,omitempty"`

	// Additional relationships to include in the fetch.
	Include string `url:"include,omitempty"`
}

Options specifies the optional parameters to support language tag and relationships.

type PageOptions

type PageOptions struct {
	// The limit on the number of objects, or number of objects in the specified relationship, that are returned.
	Limit int `url:"limit,omitempty"`

	// The next page or group of objects to fetch.
	Offset int `url:"offset,omitempty"`

	Options
}

PageOptions specifies the optional parameters to support pagination of the objects.

type PlayParameters

type PlayParameters struct {
	Id        string `json:"id"`
	Kind      string `json:"kind"`
	IsLibrary bool   `json:"isLibrary,omitempty"` // Undocumented, Used in LibraryPlaylist.
	CatalogId string `json:"catalogId,omitempty"` // Undocumented, Used in LibraryPlaylist.
}

PlayParameters represents play parameters for resources.

type Playlist

type Playlist struct {
	Id            string                `json:"id"`
	Type          string                `json:"type"`
	Href          string                `json:"href"`
	Attributes    PlaylistAttributes    `json:"attributes"`
	Relationships PlaylistRelationships `json:"relationships,omitempty"`
}

Playlist represents a playlist.

type PlaylistAttributes

type PlaylistAttributes struct {
	Artwork          *Artwork        `json:"artwork,omitempty"`
	CuratorName      string          `json:"curatorName,omitempty"`
	Description      *EditorialNotes `json:"description,omitempty"`
	LastModifiedDate string          `json:"lastModifiedDate"`
	Name             string          `json:"name"`
	PlaylistType     PlaylistType    `json:"playlistType"`
	PlayParams       *PlayParameters `json:"playParams,omitempty"`
	URL              string          `json:"url"`
}

PlaylistAttributes represents the attributes of the resource.

type PlaylistRelationships

type PlaylistRelationships struct {
	Curator Curators `json:"curator"` // Default inclusion: Identifiers only
	Tracks  Tracks   `json:"tracks"`  // The songs and music videos included in the playlist. Default inclusion: Objects
}

PlaylistRelationships represents a to-one or to-many relationship from one resource object to others.

type PlaylistType

type PlaylistType string

PlaylistType represents the type of playlist.

type Playlists

type Playlists struct {
	Data []Playlist `json:"data"`
	Href string     `json:"href,omitempty"`
	Next string     `json:"next,omitempty"`
}

Playlists represents a list of playlists.

type Preview

type Preview struct {
	Url string `json:"url"`
}

Preview represents an audio preview for resources.

type Resource

type Resource struct {
	json.RawMessage `json:",inline"`
}

Resource represents a resource—such as an album, song, or playlist—in the Apple Music catalog or iCloud Music Library.

func (Resource) Parse

func (r Resource) Parse() (resource interface{}, err error)

Parse parses the Resource. For recognized Resource types, a value of the corresponding struct type will be returned.

func (Resource) Type

func (r Resource) Type() string

Type returns the type of resource.

type Response

type Response struct {
	*http.Response
}

Response is a Apple Music API response.

type Search struct {
	Results SearchResults `json:"results"`
}

Search represents the result of search for resources.

type SearchHints

type SearchHints struct {
	Results SearchHintsResults `json:"results"`
}

SearchHints represents the result of search hints.

type SearchHintsOptions

type SearchHintsOptions struct {
	Term     string `url:"term"`
	Language string `url:"l,omitempty"`
	Limit    int    `url:"limit,omitempty"` // (Optional) The number of search terms to be returned. The default value is 10.
	Types    string `url:"types,omitempty"`
}

SearchHintsOptions specifies the parameters to search hints.

type SearchHintsResults

type SearchHintsResults struct {
	Terms []string `json:"terms"`
}

SearchHintsResults represents a results, that contains terms array.

type SearchOptions

type SearchOptions struct {
	// The entered text for the search with ‘+’ characters between each word,
	// to replace spaces (for example term=james+br).
	Term string `url:"term"`

	// (Optional) The localization to use, specified by a language tag.
	// The possible values are in the supportedLanguageTags array belonging to the Storefront object specified by storefront.
	// Otherwise, the storefront’s defaultLanguageTag is used.
	Language string `url:"l,omitempty"`

	// (Optional) The limit on the number of objects, or number of objects in the specified relationship, that are returned.
	// The default value is 5 and the maximum value is 25.
	Limit int `url:"limit,omitempty"`

	// (Optional; valid only with types specified) The next page or group of objects to fetch.
	Offset int `url:"offset,omitempty"`

	// (Optional) The list of the types of resources to include in the results.
	Types string `url:"types,omitempty"`
}

SearchOptions specifies the parameters to search the catalog.

type SearchResults

type SearchResults struct {
	Activities    *Activities    `json:"activities,omitempty"`
	Albums        *Albums        `json:"albums,omitempty"`
	AppleCurators *AppleCurators `json:"apple-curators,omitempty"`
	Artists       *Artists       `json:"artists,omitempty"`
	Curators      *Curators      `json:"curators,omitempty"`
	MusicVideos   *MusicVideos   `json:"music-videos,omitempty"`
	Playlists     *Playlists     `json:"playlists,omitempty"`
	Stations      *Stations      `json:"stations,omitempty"`
	Songs         *Songs         `json:"songs,omitempty"`
}

SearchResults represents a results, that contains a map of search results. The members of the results object are the types of resources and the value for each is a Response Root object.

type Song

type Song struct {
	Id            string            `json:"id"`
	Type          string            `json:"type"`
	Href          string            `json:"href"`
	Attributes    SongAttributes    `json:"attributes"`
	Relationships SongRelationships `json:"relationships"`
}

Song represents a song.

type SongAttributes

type SongAttributes struct {
	Artwork          Artwork         `json:"artwork"`
	ArtistName       string          `json:"artistName"`
	URL              string          `json:"url"`
	DiscNumber       int             `json:"discNumber"`
	GenreNames       []string        `json:"genreNames"`
	ISRC             string          `json:"isrc"`
	DurationInMillis int64           `json:"durationInMillis,omitempty"`
	ReleaseDate      string          `json:"releaseDate"`
	Name             string          `json:"name"`
	PlayParams       *PlayParameters `json:"playParams,omitempty"`
	TrackNumber      int             `json:"trackNumber,omitempty"`
	ComposerName     string          `json:"composerName,omitempty"`
	ContentRating    string          `json:"contentRating,omitempty"`
	EditorialNotes   *EditorialNotes `json:"editorialNotes,omitempty"`
	MovementCount    int             `json:"movementCount,omitempty"`
	MovementName     string          `json:"movementName,omitempty"`
	MovementNumber   int             `json:"movementNumber,omitempty"`
	WorkName         string          `json:"workName,omitempty"`
	Previews         *[]Preview      `json:"previews,omitempty"`
	AlbumName        string          `json:"albumName"`
}

SongAttributes represents the attributes of the resource.

type SongRelationships

type SongRelationships struct {
	Albums  Albums  `json:"albums"`           // Default inclusion: Identifiers only
	Artists Artists `json:"artists"`          // Default inclusion: Identifiers only
	Genres  *Genres `json:"genres,omitempty"` // Default inclusion: None
}

SongRelationships represents a to-one or to-many relationship from one resource object to others.

type Songs

type Songs struct {
	Data []Song `json:"data"`
	Href string `json:"href,omitempty"`
	Next string `json:"next,omitempty"`
}

Songs represents a list of songs.

type Source

type Source struct {
	Parameter string      `json:"parameter"`
	Pointer   interface{} `json:"pointer"` // JSON pointer, A pointer to the associated entry in the request document.
}

Source represents the source of an error.

type Station

type Station struct {
	Id         string            `json:"id"`
	Type       string            `json:"type"`
	Href       string            `json:"href"`
	Attributes StationAttributes `json:"attributes"`
}

Station represents a station.

type StationAttributes

type StationAttributes struct {
	URL              string          `json:"url"`
	Name             string          `json:"name"`
	Artwork          Artwork         `json:"artwork"`
	PlayParams       PlayParameters  `json:"playParams"` // Undocumented
	EditorialNotes   *EditorialNotes `json:"editorialNotes,omitempty"`
	IsLive           bool            `json:"isLive"`
	DurationInMillis int64           `json:"durationInMillis,omitempty"`
	EpisodeNumber    string          `json:"episodeNumber,omitempty"`
}

StationAttributes represents the attributes of the resource.

type Stations

type Stations struct {
	Data []Station `json:"data"`
	Href string    `json:"href,omitempty"`
	Next string    `json:"next,omitempty"`
}

Stations represents a list of stations.

type Storefront

type Storefront struct {
	Id         string               `json:"id"`
	Type       string               `json:"type"`
	Href       string               `json:"href"`
	Attributes StorefrontAttributes `json:"attributes"`
}

Storefront represents a storefront, an iTunes Store territory that the content is available in.

type StorefrontAttributes

type StorefrontAttributes struct {
	DefaultLanguageTag    string   `json:"defaultLanguageTag"`
	Name                  string   `json:"name"`
	SupportedLanguageTags []string `json:"supportedLanguageTags"`
}

StorefrontAttributes represents a to-one or to-many relationship from one resource object to others.

type Storefronts

type Storefronts struct {
	Data []Storefront `json:"data"`
	Next string       `json:"next,omitempty"`
}

Storefronts represents a list of storefronts.

type StorefrontsService

type StorefrontsService service

StorefrontsService handles communication with the storefront related methods of the Apple Music API.

func (*StorefrontsService) Get

Get fetches a single storefront using its identifier.

func (*StorefrontsService) GetAll

GetAll fetches all the storefronts in alphabetical order.

func (*StorefrontsService) GetByIds

func (s *StorefrontsService) GetByIds(ctx context.Context, ids []string, opt *Options) (*Storefronts, *Response, error)

GetByIds fetches multiple storefronts by ids.

type TooManyRequestsError

type TooManyRequestsError errorMessageResponse

TooManyRequestsError represents the Too Many Requests (429) error when the server exceeds its capacity.

func (*TooManyRequestsError) Error

func (e *TooManyRequestsError) Error() string

type Tracks

type Tracks struct {
	Data []Resource `json:"data"`
	Href string     `json:"href,omitempty"`
}

Tracks represents a list of songs and music videos.

type Transport

type Transport struct {
	Token          string // Apple Music developer token
	MusicUserToken string

	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

Transport is an http.RoundTripper.

func (*Transport) Client

func (t *Transport) Client() *http.Client

Client returns an *http.Client that makes requests.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type UnauthorizedError

type UnauthorizedError errorMessageResponse

UnauthorizedError occurs when server denied the request.

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL