forked from ryanbradynd05/go-tmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
people.go
329 lines (307 loc) · 11.1 KB
/
people.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
324
325
326
327
328
329
package tmdb
import (
"fmt"
)
// Person struct
type Person struct {
ID int `json:"id"`
Name string `json:"name"`
Overview string `json:"overview"`
Adult bool `json:"adult"`
Biography string `json:"biography"`
Birthday string `json:"birthday"`
Deathday string `json:"deathday"`
Gender int `json:"gender"`
ImdbID string `json:"imdb_id"`
Homepage string `json:"homepage"`
AlsoKnownAs []string `json:"also_known_as"`
PlaceOfBirth string `json:"place_of_birth"`
ProfilePath string `json:"profile_path"`
Changes *PersonChanges `json:",omitempty"`
MovieCredits *PersonMovieCredits `json:"movie_credits,omitempty"`
TvCredits *PersonTvCredits `json:"tv_credits,omitempty"`
CombinedCredits *PersonCombinedCredits `json:"combined_credits,omitempty"`
ExternalIds *TvExternalIds `json:"external_ids,omitempty"`
Images *PersonImages `json:",omitempty"`
TaggedImages *PersonTaggedImages `json:"tagged_images,omitempty"`
Translations *PersonTranslations `json:"translations,omitempty"`
}
// PersonTranslations struct
type PersonTranslations struct {
ID int
Translations []struct {
Iso639_1 string `json:"iso_639_1"`
Name string `json:"name"`
EnglishName string `json:"english_name"`
Data struct {
Title string `json:"title,omitempty"`
Overview string `json:"overview,omitempty"`
Homepage string `json:"homepage,omitempty"`
} `json:"data"`
}
}
// PersonShort struct
type PersonShort struct {
Adult bool
ID int
Name string
Popularity float32
ProfilePath string `json:"profile_path"`
KnownFor []MovieShort `json:"known_for"`
}
// PersonChanges struct
type PersonChanges struct {
Changes []struct {
Key string
Items []struct {
ID string
Action string
Time string
}
}
}
// PersonCombinedCredits struct
type PersonCombinedCredits struct {
ID int
Cast []struct {
Adult bool
Character string
CreditID string `json:"credit_id"`
ID int
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string
MediaType string `json:"media_type"`
}
Crew []struct {
Adult bool
CreditID string `json:"credit_id"`
Department string
ID int
Job string
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string
MediaType string `json:"media_type"`
}
}
// PersonImages struct
type PersonImages struct {
ID int
Profiles []struct {
AspectRatio float32 `json:"aspect_ratio"`
FilePath string `json:"file_path"`
ID string `json:"id"`
Width int `json:"width"`
Height int `json:"height"`
Iso639_1 string `json:"iso_639_1"`
VoteAverage float32 `json:"vote_average"`
VoteCount int `json:"vote_count"`
}
}
// PersonLatest struct
type PersonLatest struct {
ID int
Name string
Adult bool
Biography string
Birthday string
Deathday string
Homepage string
AlsoKnownAs []string `json:"also_known_as"`
PlaceOfBirth string `json:"place_of_birth"`
ProfilePath string `json:"profile_path"`
}
// PersonMovieCredits struct
type PersonMovieCredits struct {
ID int
Cast []struct {
Adult bool
Character string
CreditID string `json:"credit_id"`
ID int
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string
}
Crew []struct {
Adult bool
CreditID string `json:"credit_id"`
Department string
ID int
Job string
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string
}
}
// PersonPopular struct
type PersonPopular struct {
Page int
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
Results []PersonShort
}
// PersonTaggedImages struct
type PersonTaggedImages struct {
ID int
Page int
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
Results []struct {
AspectRatio float32 `json:"aspect_ratio"`
FilePath string `json:"file_path"`
ID string
Width int
Height int
Iso639_1 string `json:"iso_639_1"`
VoteAverage float32 `json:"vote_average"`
VoteCount int `json:"vote_count"`
ImageType string `json:"image_type"`
MediaType string `json:"media_type"`
Media struct {
Adult bool
BackdropPath string `json:"backdrop_path"`
ID int
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string
Popularity float32
}
}
}
// PersonTvCredits struct
type PersonTvCredits struct {
ID int
Cast []struct {
Character string
CreditID string `json:"credit_id"`
EpisodeCount int `json:"episode_count"`
FirstAirDate string `json:"first_air_date"`
ID int
Name string
OriginalName string `json:"original_name"`
PosterPath string `json:"poster_path"`
}
Crew []struct {
CreditID string `json:"credit_id"`
Department string
FirstAirDate string `json:"first_air_date"`
ID int
Job string
Name string
OriginalName string `json:"original_name"`
PosterPath string `json:"poster_path"`
}
}
// GetPersonInfo gets the general person information for a specific id
// https://developers.themoviedb.org/3/people/get-person-details
func (tmdb *TMDb) GetPersonInfo(id int, options map[string]string) (*Person, error) {
var availableOptions = map[string]struct{}{
"append_to_response": {}}
var personInfo Person
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/%v?api_key=%s%s", baseURL, id, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &personInfo)
return result.(*Person), err
}
// GetPersonChanges for a specific person id
// https://developers.themoviedb.org/3/people/get-person-changes
func (tmdb *TMDb) GetPersonChanges(id int, options map[string]string) (*PersonChanges, error) {
var availableOptions = map[string]struct{}{
"start_date": {},
"end_date": {}}
var changes PersonChanges
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/%v/changes?api_key=%s%s", baseURL, id, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &changes)
return result.(*PersonChanges), err
}
// GetPersonCombinedCredits gets the combined (movie and TV) credits for a specific person id
// https://developers.themoviedb.org/3/people/get-person-combined-credits
func (tmdb *TMDb) GetPersonCombinedCredits(id int, options map[string]string) (*PersonCombinedCredits, error) {
var availableOptions = map[string]struct{}{
"language": {},
"append_to_response": {}}
var credits PersonCombinedCredits
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/%v/combined_credits?api_key=%s%s", baseURL, id, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &credits)
return result.(*PersonCombinedCredits), err
}
// GetPersonExternalIds gets the external ids for a specific person id
// https://developers.themoviedb.org/3/people/get-person-external-ids
func (tmdb *TMDb) GetPersonExternalIds(id int) (*TvExternalIds, error) {
var ids TvExternalIds
uri := fmt.Sprintf("%s/person/%v/external_ids?api_key=%s", baseURL, id, tmdb.apiKey)
result, err := getTmdb(uri, &ids)
return result.(*TvExternalIds), err
}
// GetPersonImages gets the images for a specific person id
// https://developers.themoviedb.org/3/people/get-person-images
func (tmdb *TMDb) GetPersonImages(id int) (*PersonImages, error) {
var images PersonImages
uri := fmt.Sprintf("%s/person/%v/images?api_key=%s", baseURL, id, tmdb.apiKey)
result, err := getTmdb(uri, &images)
return result.(*PersonImages), err
}
// GetPersonLatest gets the latest person id
// https://developers.themoviedb.org/3/people/get-latest-person
func (tmdb *TMDb) GetPersonLatest() (*PersonLatest, error) {
var latest PersonLatest
uri := fmt.Sprintf("%s/person/latest?api_key=%s", baseURL, tmdb.apiKey)
result, err := getTmdb(uri, &latest)
return result.(*PersonLatest), err
}
// GetPersonMovieCredits gets the movie credits for a specific person id
// https://developers.themoviedb.org/3/people/get-person-movie-credits
func (tmdb *TMDb) GetPersonMovieCredits(id int, options map[string]string) (*PersonMovieCredits, error) {
var availableOptions = map[string]struct{}{
"language": {},
"append_to_response": {}}
var credits PersonMovieCredits
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/%v/movie_credits?api_key=%s%s", baseURL, id, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &credits)
return result.(*PersonMovieCredits), err
}
// GetPersonPopular gets the list of popular people on The Movie Database
// https://developers.themoviedb.org/3/people/get-popular-people
func (tmdb *TMDb) GetPersonPopular(options map[string]string) (*PersonPopular, error) {
var availableOptions = map[string]struct{}{
"page": {}}
var popular PersonPopular
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/popular?api_key=%s%s", baseURL, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &popular)
return result.(*PersonPopular), err
}
// GetPersonTaggedImages gets the images that have been tagged with a specific person id
// https://developers.themoviedb.org/3/people/get-tagged-images
func (tmdb *TMDb) GetPersonTaggedImages(id int, options map[string]string) (*PersonTaggedImages, error) {
var availableOptions = map[string]struct{}{
"language": {},
"page": {}}
var images PersonTaggedImages
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/%v/tagged_images?api_key=%s%s", baseURL, id, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &images)
return result.(*PersonTaggedImages), err
}
// GetPersonTvCredits gets the TV credits for a specific person id
// https://developers.themoviedb.org/3/people/get-person-tv-credits
func (tmdb *TMDb) GetPersonTvCredits(id int, options map[string]string) (*PersonTvCredits, error) {
var availableOptions = map[string]struct{}{
"language": {},
"append_to_response": {}}
var credits PersonTvCredits
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/person/%v/tv_credits?api_key=%s%s", baseURL, id, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &credits)
return result.(*PersonTvCredits), err
}