This repository has been archived by the owner on Sep 29, 2024. It is now read-only.
forked from cyruzin/golang-tmdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tv_seasons.go
323 lines (306 loc) · 8.77 KB
/
tv_seasons.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package tmdb
import "fmt"
// TVSeasonDetails is a struct for details JSON response.
type TVSeasonDetails struct {
IDString string `json:"_id"`
AirDate string `json:"air_date"`
Episodes []struct {
AirDate string `json:"air_date"`
EpisodeNumber int `json:"episode_number"`
ID int64 `json:"id"`
Name string `json:"name"`
Overview string `json:"overview"`
ProductionCode string `json:"production_code"`
SeasonNumber int `json:"season_number"`
ShowID int64 `json:"show_id"`
StillPath string `json:"still_path"`
VoteAverage float32 `json:"vote_average"`
VoteCount int64 `json:"vote_count"`
Crew []struct {
ID int64 `json:"id"`
CreditID string `json:"credit_id"`
Name string `json:"name"`
Department string `json:"department"`
Job string `json:"job"`
Gender int `json:"gender"`
ProfilePath string `json:"profile_path"`
} `json:"crew"`
GuestStars []struct {
ID int64 `json:"id"`
Name string `json:"name"`
CreditID string `json:"credit_id"`
Character string `json:"character"`
Order int `json:"order"`
Gender int `json:"gender"`
ProfilePath string `json:"profile_path"`
} `json:"guest_stars"`
} `json:"episodes"`
Name string `json:"name"`
Overview string `json:"overview"`
ID int64 `json:"id"`
PosterPath string `json:"poster_path"`
SeasonNumber int `json:"season_number"`
*TVSeasonCreditsAppend
*TVSeasonExternalIDsAppend
*TVSeasonImagesAppend
*TVSeasonVideosAppend
}
// TVSeasonCreditsAppend type is a struct
// for credits in append to response.
type TVSeasonCreditsAppend struct {
Credits *TVSeasonCredits `json:"credits,omitempty"`
}
// TVSeasonExternalIDsAppend type is a struct
// for external ids in append to response.
type TVSeasonExternalIDsAppend struct {
ExternalIDs *TVSeasonExternalIDs `json:"external_ids,omitempty"`
}
// TVSeasonImagesAppend type is a struct
// for images in append to response.
type TVSeasonImagesAppend struct {
Images *TVSeasonImages `json:"images,omitempty"`
}
// TVSeasonVideosAppend type is a struct
// for videos in append to response.
type TVSeasonVideosAppend struct {
Videos struct {
*TVSeasonVideos
} `json:"videos,omitempty"`
}
// GetTVSeasonDetails get the TV season details by id.
//
// Supports append_to_response.
//
// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-details
func (c *Client) GetTVSeasonDetails(
id int,
seasonNumber int,
urlOptions map[string]string,
) (*TVSeasonDetails, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d%s%d?api_key=%s%s",
baseURL,
tvURL,
id,
tvSeasonURL,
seasonNumber,
c.apiKey,
options,
)
tvSeasonDetails := TVSeasonDetails{}
if err := c.get(tmdbURL, &tvSeasonDetails); err != nil {
return nil, err
}
return &tvSeasonDetails, nil
}
// TVSeasonChanges is a struct for changes JSON response.
type TVSeasonChanges struct {
Changes []struct {
Items []struct {
ID string `json:"id"`
Action string `json:"action"`
Time string `json:"time"`
Iso639_1 string `json:"iso_639_1"`
Iso3166_1 string `json:"iso_3166_1"`
Value struct {
EpisodeID int64 `json:"episode_id"`
EpisodeNumber int `json:"episode_number"`
} `json:"value"`
} `json:"items"`
Key string `json:"key"`
} `json:"changes"`
}
// GetTVSeasonChanges get the changes for a TV season.
// By default only the last 24 hours are returned.
//
// You can query up to 14 days in a single query by using
// the start_date and end_date query parameters.
//
// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-changes
func (c *Client) GetTVSeasonChanges(
id int,
urlOptions map[string]string,
) (*TVSeasonChanges, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%sseason/%d/changes?api_key=%s%s",
baseURL,
tvURL,
id,
c.apiKey,
options,
)
tvSeasonChanges := TVSeasonChanges{}
if err := c.get(tmdbURL, &tvSeasonChanges); err != nil {
return nil, err
}
return &tvSeasonChanges, nil
}
// TVSeasonCredits type is a struct for credits JSON response.
type TVSeasonCredits struct {
Cast []struct {
Character string `json:"character"`
CreditID string `json:"credit_id"`
Gender int `json:"gender"`
ID int64 `json:"id"`
Name string `json:"name"`
Order int `json:"order"`
ProfilePath string `json:"profile_path"`
} `json:"cast"`
Crew []struct {
CreditID string `json:"credit_id"`
Department string `json:"department"`
Gender int `json:"gender"`
ID int64 `json:"id"`
Job string `json:"job"`
Name string `json:"name"`
ProfilePath string `json:"profile_path"`
} `json:"crew"`
ID int `json:"id"`
}
// GetTVSeasonCredits get the credits for TV season.
//
// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-credits
func (c *Client) GetTVSeasonCredits(
id int,
seasonNumber int,
urlOptions map[string]string,
) (*TVSeasonCredits, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d%s%d/credits?api_key=%s%s",
baseURL,
tvURL,
id,
tvSeasonURL,
seasonNumber,
c.apiKey,
options,
)
tVSeasonCredits := TVSeasonCredits{}
if err := c.get(tmdbURL, &tVSeasonCredits); err != nil {
return nil, err
}
return &tVSeasonCredits, nil
}
// TVSeasonExternalIDs type is a struct for external ids JSON response.
type TVSeasonExternalIDs struct {
FreebaseMID string `json:"freebase_mid"`
FreebaseID string `json:"freebase_id"`
TVDBID int64 `json:"tvdb_id"`
TVRageID int64 `json:"tvrage_id"`
ID int64 `json:"id,omitempty"`
}
// GetTVSeasonExternalIDs get the external ids for a TV season.
// We currently support the following external sources.
//
// Media Databases: TVDB ID, Freebase MID*, Freebase ID* TVRage ID*.
//
// *Defunct or no longer available as a service.
//
// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-external-ids
func (c *Client) GetTVSeasonExternalIDs(
id int,
seasonNumber int,
urlOptions map[string]string,
) (*TVSeasonExternalIDs, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d%s%d/external_ids?api_key=%s%s",
baseURL,
tvURL,
id,
tvSeasonURL,
seasonNumber,
c.apiKey,
options,
)
tvSeasonExternalIDs := TVSeasonExternalIDs{}
if err := c.get(tmdbURL, &tvSeasonExternalIDs); err != nil {
return nil, err
}
return &tvSeasonExternalIDs, nil
}
// TVSeasonImages type is a struct for images JSON response.
type TVSeasonImages struct {
ID int64 `json:"id,omitempty"`
Posters []struct {
AspectRatio float32 `json:"aspect_ratio"`
FilePath string `json:"file_path"`
Height int `json:"height"`
Iso639_1 string `json:"iso_639_1"`
VoteAverage float32 `json:"vote_average"`
VoteCount int64 `json:"vote_count"`
Width int `json:"width"`
} `json:"posters"`
}
// GetTVSeasonImages get the images that belong to a TV season.
//
// Querying images with a language parameter will filter the results.
// If you want to include a fallback language (especially useful for backdrops)
// you can use the include_image_language parameter.
// This should be a comma separated value like so: include_image_language=en,null.
//
// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-images
func (c *Client) GetTVSeasonImages(
id int,
seasonNumber int,
urlOptions map[string]string,
) (*TVSeasonImages, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d%s%d/images?api_key=%s%s",
baseURL,
tvURL,
id,
tvSeasonURL,
seasonNumber,
c.apiKey,
options,
)
tvSeasonImages := TVSeasonImages{}
if err := c.get(tmdbURL, &tvSeasonImages); err != nil {
return nil, err
}
return &tvSeasonImages, nil
}
// TVSeasonVideos type is a struct for videos JSON response.
type TVSeasonVideos struct {
ID int64 `json:"id,omitempty"`
Results []struct {
ID string `json:"id"`
Iso639_1 string `json:"iso_639_1"`
Iso3166_1 string `json:"iso_3166_1"`
Key string `json:"key"`
Name string `json:"name"`
Site string `json:"site"`
Size int `json:"size"`
Type string `json:"type"`
} `json:"results"`
}
// GetTVSeasonVideos get the videos that have been added to a TV season.
//
// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-videos
func (c *Client) GetTVSeasonVideos(
id int,
seasonNumber int,
urlOptions map[string]string,
) (*TVSeasonVideos, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d%s%d/videos?api_key=%s%s",
baseURL,
tvURL,
id,
tvSeasonURL,
seasonNumber,
c.apiKey,
options,
)
tvSeasonVideos := TVSeasonVideos{}
if err := c.get(tmdbURL, &tvSeasonVideos); err != nil {
return nil, err
}
return &tvSeasonVideos, nil
}