-
Notifications
You must be signed in to change notification settings - Fork 19
/
catalog_music_videos.go
executable file
·83 lines (71 loc) · 2.91 KB
/
catalog_music_videos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package applemusic
import (
"context"
"fmt"
)
// MusicVideoAttributes represents the attributes of the resource.
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"`
}
// MusicVideoRelationships represents a to-one or to-many relationship from one resource object to others.
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
}
// MusicVideo represents a music video.
type MusicVideo struct {
Id string `json:"id"`
Type string `json:"type"`
Href string `json:"href"`
Attributes MusicVideoAttributes `json:"attributes"`
Relationships MusicVideoRelationships `json:"relationships"`
}
// MusicVideos represents a list of music videos.
type MusicVideos struct {
Data []MusicVideo `json:"data"`
Href string `json:"href,omitempty"`
Next string `json:"next,omitempty"`
}
func (s *CatalogService) getMusicVideos(ctx context.Context, u string) (*MusicVideos, *Response, error) {
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
musicVideos := &MusicVideos{}
resp, err := s.client.Do(ctx, req, musicVideos)
if err != nil {
return nil, resp, err
}
return musicVideos, resp, nil
}
// GetMusicVideo fetches a music video using its identifier.
func (s *CatalogService) GetMusicVideo(ctx context.Context, storefront, id string, opt *Options) (*MusicVideos, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/music-videos/%s", storefront, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.getMusicVideos(ctx, u)
}
// GetMusicVideosByIds fetches one or more music videos using their identifiers.
func (s *CatalogService) GetMusicVideosByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*MusicVideos, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/music-videos", storefront)
u, err := addOptions(u, makeIdsOptions(ids, opt))
if err != nil {
return nil, nil, err
}
return s.getMusicVideos(ctx, u)
}