-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepisodes.go
239 lines (198 loc) · 7.5 KB
/
episodes.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package spotify
import (
"fmt"
"strings"
)
type Episode struct {
// A URL to a 30 second preview (MP3 format) of the episode. null if not available.
AudioPreviewURL string `json:"audio_preview_url"`
// A description of the episode. HTML tags are stripped away from this field, use html_description field in case HTML tags are needed.
Description string `json:"description"`
// A description of the episode. This field may contain HTML tags.
HTMLDescription string `json:"html_description"`
// The episode length in milliseconds.
DurationMS int `json:"duration_ms"`
// Whether or not the episode has explicit content (true = yes it does; false = no it does not OR unknown).
Explicit bool `json:"explicit"`
// External URLs for this episode.
ExternalURLs ExternalURLs `json:"external_ur_ls"`
// A link to the Web API endpoint providing full details of the episode.
Href string `json:"href"`
// The Spotify ID for the episode.
ID string `json:"id"`
// The cover art for the episode in various sizes, widest first.
Images []Image `json:"images"`
// True if the episode is hosted outside of Spotify's CDN.
IsExternallyHosted bool `json:"is_externally_hosted"`
// True if the episode is playable in the given market. Otherwise false.
IsPlayable bool `json:"is_playable"`
// A list of the languages used in the episode, identified by their ISO 639-1 code.
Languages []string `json:"languages"`
// The name of the episode.
Name string `json:"name"`
// The date the episode was first released, for example "1981-12-15". Depending on the precision, it might be shown as "1981" or "1981-12".
ReleaseDate string `json:"release_date"`
// The precision with which release_date value is known.
ReleaseDatePrecision string `json:"release_date_precision"`
// The user's most recent position in the episode. Set if the supplied access token is a user token and has the scope 'user-read-playback-position'.
ResumePoint ResumePoint `json:"resume_point"`
// The object type.
Type string `json:"type"`
// The Spotify URI for the episode.
URI string `json:"uri"`
// Included in the response when a content restriction is applied.
Restrictions Restrictions `json:"restrictions"`
}
type FullEpisode struct {
Episode
// The show on which the episode belongs.
Show Show `json:"show"`
}
type SavedEpisode struct {
AddedAt string `json:"added_at"`
FullEpisode
}
type GetEpisodeParams struct {
Market Market `url:"market"`
}
type GetEpisodeResponse struct {
FullEpisode
}
// Get Spotify catalog information for a single episode identified by its unique Spotify ID.
func (c *Client) GetEpisode(id string, market Market) (*GetEpisodeResponse, error) {
episode := GetEpisodeResponse{}
var spotifyErr *SpotifyError
params := GetEpisodeParams{
Market: market,
}
_, err := c.get(fmt.Sprintf("/episodes/%s", id)).QueryStruct(params).Receive(&episode, &spotifyErr)
if err != nil {
return nil, err
}
if spotifyErr != nil {
return nil, spotifyErr
}
return &episode, nil
}
type GetSeveralEpisodesParams struct {
// A comma-separated list of the Spotify IDs for the episodes. Maximum: 50 IDs.
IDs string `url:"ids"`
Market Market `url:"market"`
}
type GetSeveralEpisodesResponse struct {
Episodes []FullEpisode `json:"episodes"`
}
// Get Spotify catalog information for several episodes based on their Spotify IDs.
//
// Required scope: user-read-playback-position
func (c *Client) GetSeveralEpisodes(ids []string, market Market) (*GetSeveralEpisodesResponse, error) {
episodes := GetSeveralEpisodesResponse{}
var spotifyErr *SpotifyError
params := GetSeveralEpisodesParams{
IDs: strings.Join(ids, ","),
Market: market,
}
_, err := c.get("/episodes").QueryStruct(params).Receive(&episodes, &spotifyErr)
if err != nil {
return nil, err
}
return &episodes, nil
}
type GetUsersSavedEpisodesParams struct {
Market Market `url:"market"`
// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.
Limit int `url:"limit"`
// The index of the first item to return. Default: 0 (the first item). Use with limit to get the next set of items.
Offset int `url:"offset"`
}
type GetUsersSavedEpisodesResponse struct {
Pagination
Items []SavedEpisode `json:"items"`
}
// Get a list of the episodes saved in the current Spotify user's library.
//
// This API endpoint is in beta and could change without warning. Please share any feedback that you have, or issues that you discover, in our developer community forum. (https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer)
func (c *Client) GetUsersSavedEpisodes(params *GetUsersSavedEpisodesParams) (*GetUsersSavedEpisodesResponse, error) {
episodes := GetUsersSavedEpisodesResponse{}
var spotifyErr *SpotifyError
_, err := c.get("/me/episodes").QueryStruct(params).Receive(&episodes, &spotifyErr)
if err != nil {
return nil, err
}
if spotifyErr != nil {
return nil, spotifyErr
}
return &episodes, nil
}
type SaveEpisodesForCurrentUserBody struct {
// A JSON array of the Spotify IDs. A maximum of 50 items can be specified in one request.
IDs []string `json:"ids"`
}
// Save one or more episodes to the current user's library.
//
// Required scope: user-library-modify
//
// This API endpoint is in beta and could change without warning. Please share any feedback that you have, or issues that you discover, in our developer community forum. (https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer)
func (c *Client) SaveEpisodesForCurrentUser(ids []string) error {
var res struct{}
var spotifyErr *SpotifyError
payload := SaveEpisodesForCurrentUserBody{
IDs: ids,
}
_, err := c.put("/me/episodes").BodyJSON(payload).Receive(&res, &spotifyErr)
if err != nil {
return err
}
if spotifyErr != nil {
return spotifyErr
}
return nil
}
type RemoveUsersSavedEpisodesBody struct {
// A JSON array of the Spotify IDs. A maximum of 50 items can be specified in one request.
IDs []string `json:"ids"`
}
// Remove one or more episodes from the current user's library.
//
// Required scope: user-library-modify
//
// This API endpoint is in beta and could change without warning. Please share any feedback that you have, or issues that you discover, in our developer community forum. (https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer)
func (c *Client) RemoveUsersSavedEpisodes(episodeIds []string) error {
var res struct{}
var spotifyErr *SpotifyError
payload := RemoveUsersSavedEpisodesBody{
IDs: episodeIds,
}
_, err := c.delete("/me/episodes").BodyJSON(payload).Receive(&res, &spotifyErr)
if err != nil {
return err
}
if spotifyErr != nil {
return spotifyErr
}
return nil
}
type CheckUsersSavedEpisodesParams struct {
// A comma-separated list of the Spotify IDs. Maximum: 50 IDs.
IDs string `url:"ids"`
}
// Check if one or more episodes is already saved in the current Spotify user's 'Your Episodes' library.
//
// Required scope: user-library-read
//
// This API endpoint is in beta and could change without warning. Please share any feedback that you have, or issues that you discover, in our developer community forum. (https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer)
func (c *Client) CheckUsersSavedEpisodes(episodeIds []string) ([]bool, error) {
var res []bool
var spotifyErr *SpotifyError
params := CheckUsersSavedEpisodesParams{
IDs: strings.Join(episodeIds, ","),
}
_, err := c.get("/me/episodes/contains").QueryStruct(params).Receive(&res, &spotifyErr)
if err != nil {
return nil, err
}
if spotifyErr != nil {
return nil, spotifyErr
}
return res, nil
}