tmdb - movie.go
1 package tmdb
2
3 import (
4 "encoding/json"
5 "fmt"
6 "net/url"
7 )
8
9 // ProductionCompany contains information about the production company of a movie/show.
10 type ProductionCompany struct {
11 Name string `json:"name"`
12 ID int64 `json:"id"`
13 LogoPath *string `json:"logo_path"`
14 OriginCountry string `json:"origin_country"`
15 }
16
17 // MovieDetails contains all of the details of a particular movie.
18 type MovieDetails struct {
19 Adult bool `json:"adult"`
20 BackdropPath *string `json:"backdrop_path"`
21 BelongsToCollection json.RawMessage `json:"belongs_to_collection"`
22 Budget int64 `json:"budget"`
23 Genres Genres `json:"genres"`
24 Homepage *string `json:"homepage"`
25 ID int64 `json:"id"`
26 IMDBID *string `json:"imdb_id"`
27 OriginalLanguage string `json:"original_language"`
28 OriginalTitle string `json:"original_title"`
29 Overview *string `json:"overview"`
30 Popularity float64 `json:"popularity"`
31 PosterPath *string `json:"poster_path"`
32 ProductionCompanies []ProductionCompany `json:"production_companies"`
33 ProductionCountries []struct {
34 Country string `json:"iso_3166_1"`
35 Name string `json:"name"`
36 } `json:"production_countries"`
37 ReleaseDate string `json:"release_date"`
38 Revenue int64 `json:"revenue"`
39 Runtime *int64 `json:"runtime"`
40 SpokenLanguages []struct {
41 Language string `json:"iso_639_1"`
42 Name string `json:"name"`
43 } `json:"spoken_languages"`
44 Status string `json:"status"`
45 Tagline *string `json:"tagline"`
46 Title string `json:"title"`
47 Video bool `json:"video"`
48 VoteAverage float64 `json:"vote_average"`
49 VoteCount int64 `json:"vote_count"`
50 }
51
52 // MovieDetails retrieves movie information based on the ID specified.
53 func (t *TMDB) MovieDetails(id int64, params ...option) (*MovieDetails, error) {
54 m := new(MovieDetails)
55
56 if err := t.get(m, fmt.Sprintf("/3/movie/%d", id), url.Values{}, params...); err != nil {
57 return nil, err
58 }
59
60 return m, nil
61 }
62
63 // AlternativeTitles is a list of the alternative titles for a movie.
64 type AlternativeTitles struct {
65 ID int64 `json:"id"`
66 Titles []struct {
67 Country string `json:"iso_3166_1"`
68 Title string `json:"title"`
69 Type string `json:"type"`
70 } `json:"titles"`
71 }
72
73 // MovieAlternativeTitles returns all of the alternative titles for a movie.
74 func (t *TMDB) MovieAlternativeTitles(id int64, params ...option) (*AlternativeTitles, error) {
75 a := new(AlternativeTitles)
76
77 if err := t.get(a, fmt.Sprintf("/3/movie/%d/alternative_titles", id), url.Values{}, params...); err != nil {
78 return nil, err
79 }
80
81 return a, nil
82 }
83
84 // EntryChanges lists changes to a movie entry.
85 type EntryChanges []struct {
86 Key string `json:"key"`
87 Items []struct {
88 ID string `json:"id"`
89 Action string `json:"action"`
90 Time string `json:"time"`
91 Language string `json:"iso_639_1"`
92 Value string `json:"value"`
93 OriginalValue string `json:"original_value"`
94 }
95 }
96
97 // MovieChanges returns changes to a movie entry.
98 func (t *TMDB) MovieChanges(id int64, params ...option) (*EntryChanges, error) {
99 e := new(EntryChanges)
100
101 if err := t.get(e, fmt.Sprintf("/3/movie/%d/changes", id), url.Values{}, params...); err != nil {
102 return nil, err
103 }
104
105 return e, nil
106 }
107
108 // CreditShared represents the shared information for crediting either a cast or crew member.
109 type CreditShared struct {
110 Adult *bool `json:"adult"`
111 Gender *int64 `json:"gender"`
112 ID int64 `json:"id"`
113 KnownForDepartment string `json:"known_for_department"`
114 Name string `json:"name"`
115 OriginalName string `json:"original_name"`
116 Popularity float64 `json:"popularity"`
117 ProfilePath *string `json:"profile_path"`
118 }
119
120 // CastCredit represents the credit information for a cast member.
121 type CastCredit struct {
122 CreditShared
123 CreditID int64 `json:"credit_id"`
124 Character string `json:"character"`
125 CastID string `json:"cast_id"`
126 Order int64 `json:"order"`
127 }
128
129 // CrewCredit represents the credit information for a crew member.
130 type CrewCredit struct {
131 CreditShared
132 CreditID int64 `json:"credit_id"`
133 Department string `json:"department"`
134 Job string `json:"job"`
135 }
136
137 // Credits contains all of the credits for a movie.
138 type Credits struct {
139 ID int64
140 Cast []CastCredit `json:"cast"`
141 Crew []CrewCredit `json:"crew"`
142 }
143
144 // MovieCredits retrieves all of the credits for a movie.
145 func (t *TMDB) MovieCredits(id int64, params ...option) (*Credits, error) {
146 c := new(Credits)
147
148 if err := t.get(c, fmt.Sprintf("/3/movie/%d/credits", id), url.Values{}, params...); err != nil {
149 return nil, err
150 }
151
152 return c, nil
153 }
154
155 // MovieExternalIDs contains all known external IDs for a movie.
156 type MovieExternalIDs struct {
157 IMDB *string `json:"imdb_id"`
158 Facebook *string `json:"facebook_id"`
159 Instagram *string `json:"instagram_id"`
160 Twitter *string `json:"twitter_id"`
161 ID int64 `json:"id"`
162 }
163
164 // MovieExternalIDs retrieves all known external IDs for a movie.
165 func (t *TMDB) MovieExternalIDs(id int64) (*MovieExternalIDs, error) {
166 m := new(MovieExternalIDs)
167
168 if err := t.get(m, fmt.Sprintf("/3/movie/%d/external_ids", id), url.Values{}); err != nil {
169 return nil, err
170 }
171
172 return m, nil
173 }
174
175 // Images contains all linked images for a movie.
176 type Images struct {
177 ID int64 `json:"id"`
178 Backdrops []Image `json:"backdrops"`
179 Posters []Image `json:"posters"`
180 }
181
182 // MovieImages retrieves all linked images for an entry.
183 func (t *TMDB) MovieImages(id int64, params ...option) (*Images, error) {
184 i := new(Images)
185
186 if err := t.get(i, fmt.Sprintf("/3/movie/%d/images", id), url.Values{}, params...); err != nil {
187 return nil, err
188 }
189
190 return i, nil
191 }
192
193 // Keywords contains all of an entry's keywords.
194 type Keywords struct {
195 ID int64 `json:"id"`
196 Keywords []Keyword `json:"keywords"`
197 }
198
199 // MovieKeywords retrieves all of the keywords for a movie.
200 func (t *TMDB) MovieKeywords(id int64) (*Keywords, error) {
201 k := new(Keywords)
202
203 if err := t.get(k, fmt.Sprintf("/3/movie/%d/keywords", id), url.Values{}); err != nil {
204 return nil, err
205 }
206
207 return k, nil
208 }
209
210 // MovieLists contains a list of lists that belong to a specific movie.
211 type MovieLists struct {
212 ID int64 `json:"id"`
213 Search
214 Results []struct {
215 Description string `json:"description"`
216 FavoriteCount int64 `json:"favorite_count"`
217 ID int64 `json:"id"`
218 ItemCount int64 `json:"item_count"`
219 Language string `json:"iso_639_1"`
220 ListType string `json:"list_type"`
221 Name string `json:"name"`
222 PosterPath *string `json:"poster_path"`
223 } `json:"results"`
224 }
225
226 // MovieLists retrieves a list of lists that belong to the specified movie.
227 func (t *TMDB) MovieLists(id int64, params ...option) (*MovieLists, error) {
228 m := new(MovieLists)
229
230 if err := t.get(m, fmt.Sprintf("/3/movie/%d/lists", id), url.Values{}, params...); err != nil {
231 return nil, err
232 }
233
234 return m, nil
235 }
236
237 // MovieRecommendations retrieves a list of recommended movies for a movie.
238 func (t *TMDB) MovieRecommendations(id int64, params ...option) (*SearchMovie, error) {
239 s := new(SearchMovie)
240
241 if err := t.get(s, fmt.Sprintf("/3/movie/%d/recommendations", id), url.Values{}, params...); err != nil {
242 return nil, err
243 }
244
245 return s, nil
246 }
247
248 // MovieReleaseDates contains a list of release dates, by country, for a movie.
249 type MovieReleaseDates struct {
250 ID int64 `json:"id"`
251 Results []struct {
252 Country string `json:"iso_3166_1"`
253 ReleaseDates []struct {
254 Certification string `json:"certification"`
255 Language string `json:"iso_639_1"`
256 Type int64 `json:"type"`
257 Note string `json:"note"`
258 } `json:"release_dates"`
259 } `json:"results"`
260 }
261
262 // MovieReleaseDates retrieves a list of release dates, by country, for the given movie.
263 func (t *TMDB) MovieReleaseDates(id int64) (*MovieReleaseDates, error) {
264 m := new(MovieReleaseDates)
265
266 if err := t.get(m, fmt.Sprintf("/3/movie/%d/release_dates", id), url.Values{}); err != nil {
267 return nil, err
268 }
269
270 return m, nil
271 }
272
273 // Reviews contains user reviews for an entry.
274 type Reviews struct {
275 ID int64 `json:"id"`
276 Search
277 Results []struct {
278 Author string `json:"author"`
279 AuthorDetails struct {
280 Name string `json:"name"`
281 Username string `json:"username"`
282 AvatarPath *string `json:"avatar_path"`
283 Rating *int64 `json:"rating"`
284 } `json:"author_details"`
285 Content string `json:"content"`
286 CreatedAt string `json:"created_at"`
287 ID string `json:"id"`
288 UpdatedAt string `json:"updated_at"`
289 URL string `json:"url"`
290 } `json:"results"`
291 }
292
293 // MovieReviews returns a list of reviews for the specified movie.
294 func (t *TMDB) MovieReviews(id int64, params ...option) (*Reviews, error) {
295 r := new(Reviews)
296
297 if err := t.get(r, fmt.Sprintf("/3/movie/%d/reviews", id), url.Values{}, params...); err != nil {
298 return nil, err
299 }
300
301 return r, nil
302 }
303
304 // MovieSimilar retrieves a list of recommended movies for a movie.
305 func (t *TMDB) MovieSimilar(id int64, params ...option) (*SearchMovie, error) {
306 s := new(SearchMovie)
307
308 if err := t.get(s, fmt.Sprintf("/3/movie/%d/similar", id), url.Values{}, params...); err != nil {
309 return nil, err
310 }
311
312 return s, nil
313 }
314
315 // MovieTranslations retrieves all of the translations for a movie.
316 func (t *TMDB) MovieTranslations(id int64) (*Translations, error) {
317 tr := new(Translations)
318
319 if err := t.get(t, fmt.Sprintf("/3/movie/%d/translations", id), url.Values{}); err != nil {
320 return nil, err
321 }
322
323 return tr, nil
324 }
325
326 // Videos contains all of the videos related to a movie.
327 type Videos struct {
328 ID int64 `json:"id"`
329 Results []struct {
330 ID string `json:"id"`
331 Language string `json:"iso_639_1"`
332 Country string `json:"iso_3166_1"`
333 Key string `json:"key"`
334 Name string `json:"name"`
335 Site string `json:"site"`
336 Size int64 `json:"size"`
337 Type string `json:"type"`
338 } `json:"results"`
339 }
340
341 // MovieVideos retrieves all of the videos related to a movie.
342 func (t *TMDB) MovieVideos(id int64, params ...option) (*Videos, error) {
343 v := new(Videos)
344
345 if err := t.get(v, fmt.Sprintf("/3/movie/%d/videos", id), url.Values{}, params...); err != nil {
346 return nil, err
347 }
348
349 return v, nil
350 }
351
352 // WatchProviderData contains information about the provider of a video service.
353 type WatchProviderData struct {
354 DisplayPriority int64 `json:"display_priority"`
355 LogoPath string `json:"logo_path"`
356 ProviderID int64 `json:"provider_id"`
357 ProviderName string `json:"provider_name"`
358 }
359
360 // WatchProviders contains all of the information about where and how to watch a movie.
361 type WatchProviders struct {
362 ID int64 `json:"id"`
363 Results struct {
364 AR, AT, AU, BE, BR, CA, CH, CL, CO, CZ, DE, DK, EC, EE, ES, FI, FR, GB, GR, HU, ID, IE, IN, IT, JP, KR, LT, LV, MX, MY, NL, NO, NZ, PE, PH, PL, PT, RO, RU, SE, SG, TH, TR, US, VE, ZA struct {
365 Link string `json:"link"`
366 Flatrate WatchProviderData `json:"flatrate"`
367 Rent WatchProviderData `json:"rent"`
368 But WatchProviderData `json:"buy"`
369 }
370 } `json:"results"`
371 }
372
373 // MovieWatchProviders retrieves all of the ways to watch a movie.
374 func (t *TMDB) MovieWatchProviders(id int64) (*WatchProviders, error) {
375 m := new(WatchProviders)
376
377 if err := t.get(m, fmt.Sprintf("/3/movie/%d/watch/providers", id), url.Values{}); err != nil {
378 return nil, err
379 }
380
381 return m, nil
382 }
383
384 // MovieLatest returns the latest movie added to the database.
385 func (t *TMDB) MovieLatest(params ...option) (*MovieDetails, error) {
386 m := new(MovieDetails)
387
388 if err := t.get(m, "/3/movie/latest", url.Values{}, params...); err != nil {
389 return nil, err
390 }
391
392 return m, nil
393 }
394
395 // MoviesWithDates contains a list of movies and the minimum and maximum play dates.
396 type MoviesWithDates struct {
397 Search
398 Results []MovieResult `json:"results"`
399 Dates struct {
400 Maximum string `json:"maximum"`
401 Minimum string `json:"minimum"`
402 }
403 }
404
405 // MovieNowPlaying retrives a list of currently playing movies.
406 func (t *TMDB) MovieNowPlaying(params ...option) (*MoviesWithDates, error) {
407 m := new(MoviesWithDates)
408
409 if err := t.get(m, "/3/movie/now_playing", url.Values{}, params...); err != nil {
410 return nil, err
411 }
412
413 return m, nil
414 }
415
416 // MoviePopular retrieves a list of popular movies.
417 func (t *TMDB) MoviePopular(params ...option) (*SearchMovie, error) {
418 s := new(SearchMovie)
419
420 if err := t.get(s, "/3/movie/popular", url.Values{}, params...); err != nil {
421 return nil, err
422 }
423
424 return s, nil
425 }
426
427 // MovieTopRated retrieves a list of top-rated movies.
428 func (t *TMDB) MovieTopRated(params ...option) (*SearchMovie, error) {
429 s := new(SearchMovie)
430
431 if err := t.get(s, "/3/movie/top_rated", url.Values{}, params...); err != nil {
432 return nil, err
433 }
434
435 return s, nil
436 }
437
438 // MovieUpcoming retrieves a list of upcoming movies.
439 func (t *TMDB) MovieUpcoming(params ...option) (*MoviesWithDates, error) {
440 m := new(MoviesWithDates)
441
442 if err := t.get(m, "/3/movie/upcoming", url.Values{}, params...); err != nil {
443 return nil, err
444 }
445
446 return m, nil
447 }
448