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 if err := t.get(m, fmt.Sprintf("/3/movie/%d", id), url.Values{}, params...); err != nil {
56 return nil, err
57 }
58 return m, nil
59 }
60
61 // AlternativeTitles is a list of the alternative titles for a movie
62 type AlternativeTitles struct {
63 ID int64 `json:"id"`
64 Titles []struct {
65 Country string `json:"iso_3166_1"`
66 Title string `json:"title"`
67 Type string `json:"type"`
68 } `json:"titles"`
69 }
70
71 // MovieAlternativeTitles returns all of the alternative titles for a movie
72 func (t *TMDB) MovieAlternativeTitles(id int64, params ...option) (*AlternativeTitles, error) {
73 a := new(AlternativeTitles)
74 if err := t.get(a, fmt.Sprintf("/3/movie/%d/alternative_titles", id), url.Values{}, params...); err != nil {
75 return nil, err
76 }
77 return a, nil
78 }
79
80 // EntryChanges lists changes to a movie entry
81 type EntryChanges []struct {
82 Key string `json:"key"`
83 Items []struct {
84 ID string `json:"id"`
85 Action string `json:"action"`
86 Time string `json:"time"`
87 Language string `json:"iso_639_1"`
88 Value string `json:"value"`
89 OriginalValue string `json:"original_value"`
90 }
91 }
92
93 // MovieChanges returns changes to a movie entry
94 func (t *TMDB) MovieChanges(id int64, params ...option) (*EntryChanges, error) {
95 e := new(EntryChanges)
96 if err := t.get(e, fmt.Sprintf("/3/movie/%d/changes", id), url.Values{}, params...); err != nil {
97 return nil, err
98 }
99 return e, nil
100 }
101
102 // CreditShared represents the shared information for crediting either a cast or crew member
103 type CreditShared struct {
104 Adult *bool `json:"adult"`
105 Gender *int64 `json:"gender"`
106 ID int64 `json:"id"`
107 KnownForDepartment string `json:"known_for_department"`
108 Name string `json:"name"`
109 OriginalName string `json:"original_name"`
110 Popularity float64 `json:"popularity"`
111 ProfilePath *string `json:"profile_path"`
112 }
113
114 // CastCredit represents the credit information for a cast member
115 type CastCredit struct {
116 CreditShared
117 CreditID int64 `json:"credit_id"`
118 Character string `json:"character"`
119 CastID string `json:"cast_id"`
120 Order int64 `json:"order"`
121 }
122
123 // CrewCredit represents the credit information for a crew memeber
124 type CrewCredit struct {
125 CreditShared
126 CreditID int64 `json:"credit_id"`
127 Department string `json:"department"`
128 Job string `json:"job"`
129 }
130
131 // Credits contains all of the credits for a movie
132 type Credits struct {
133 ID int64
134 Cast []CastCredit `json:"cast"`
135 Crew []CrewCredit `json:"crew"`
136 }
137
138 // MovieCredits retrieves all of the credits for a movie
139 func (t *TMDB) MovieCredits(id int64, params ...option) (*Credits, error) {
140 c := new(Credits)
141 if err := t.get(c, fmt.Sprintf("/3/movie/%d/credits", id), url.Values{}, params...); err != nil {
142 return nil, err
143 }
144 return c, nil
145 }
146
147 // MovieExternalIDs contains all known external IDs for a movie
148 type MovieExternalIDs struct {
149 IMDB *string `json:"imdb_id"`
150 Facebook *string `json:"facebook_id"`
151 Instagram *string `json:"instagram_id"`
152 Twitter *string `json:"twitter_id"`
153 ID int64 `json:"id"`
154 }
155
156 // MovieExternalIDs retrieves all known external IDs for a movie
157 func (t *TMDB) MovieExternalIDs(id int64) (*MovieExternalIDs, error) {
158 m := new(MovieExternalIDs)
159 if err := t.get(m, fmt.Sprintf("/3/movie/%d/external_ids", id), url.Values{}); err != nil {
160 return nil, err
161 }
162 return m, nil
163 }
164
165 // Images contains all linked images for a movie
166 type Images struct {
167 ID int64 `json:"id"`
168 Backdrops []Image `json:"backdrops"`
169 Posters []Image `json:"posters"`
170 }
171
172 // MovieImages retrieves all linked images for an entry
173 func (t *TMDB) MovieImages(id int64, params ...option) (*Images, error) {
174 i := new(Images)
175 if err := t.get(i, fmt.Sprintf("/3/movie/%d/images", id), url.Values{}, params...); err != nil {
176 return nil, err
177 }
178 return i, nil
179 }
180
181 // Keywords contains all of an entry's keywords
182 type Keywords struct {
183 ID int64 `json:"id"`
184 Keywords []Keyword `json:"keywords"`
185 }
186
187 // MovieKeywords retrieves all of the keywords for a movie
188 func (t *TMDB) MovieKeywords(id int64) (*Keywords, error) {
189 k := new(Keywords)
190 if err := t.get(k, fmt.Sprintf("/3/movie/%d/keywords", id), url.Values{}); err != nil {
191 return nil, err
192 }
193 return k, nil
194 }
195
196 // MovieLists contains a list of lists that belong to a specific movie
197 type MovieLists struct {
198 ID int64 `json:"id"`
199 Search
200 Results []struct {
201 Description string `json:"description"`
202 FavoriteCount int64 `json:"favorite_count"`
203 ID int64 `json:"id"`
204 ItemCount int64 `json:"item_count"`
205 Language string `json:"iso_639_1"`
206 ListType string `json:"list_type"`
207 Name string `json:"name"`
208 PosterPath *string `json:"poster_path"`
209 } `json:"results"`
210 }
211
212 // MovieLists retrieves a list of lists that belong to the specified movie
213 func (t *TMDB) MovieLists(id int64, params ...option) (*MovieLists, error) {
214 m := new(MovieLists)
215 if err := t.get(m, fmt.Sprintf("/3/movie/%d/lists", id), url.Values{}, params...); err != nil {
216 return nil, err
217 }
218 return m, nil
219 }
220
221 // MovieRecommendations retrieves a list of recommended movies for a movie
222 func (t *TMDB) MovieRecommendations(id int64, params ...option) (*SearchMovie, error) {
223 s := new(SearchMovie)
224 if err := t.get(s, fmt.Sprintf("/3/movie/%d/recommendations", id), url.Values{}, params...); err != nil {
225 return nil, err
226 }
227 return s, nil
228 }
229
230 // MovieReleaseDates contains a list of release dates, by country, for a movie
231 type MovieReleaseDates struct {
232 ID int64 `json:"id"`
233 Results []struct {
234 Country string `json:"iso_3166_1"`
235 ReleaseDates []struct {
236 Certification string `json:"certification"`
237 Language string `json:"iso_639_1"`
238 Type int64 `json:"type"`
239 Note string `json:"note"`
240 } `json:"release_dates"`
241 } `json:"results"`
242 }
243
244 // MovieReleaseDates retrieves a list of release dates, by country, for the given movie
245 func (t *TMDB) MovieReleaseDates(id int64) (*MovieReleaseDates, error) {
246 m := new(MovieReleaseDates)
247 if err := t.get(m, fmt.Sprintf("/3/movie/%d/release_dates", id), url.Values{}); err != nil {
248 return nil, err
249 }
250 return m, nil
251 }
252
253 // Reviews contains user reviews for an entry
254 type Reviews struct {
255 ID int64 `json:"id"`
256 Search
257 Results []struct {
258 Author string `json:"author"`
259 AuthorDetails struct {
260 Name string `json:"name"`
261 Username string `json:"username"`
262 AvatarPath *string `json:"avatar_path"`
263 Rating *int64 `json:"rating"`
264 } `json:"author_details"`
265 Content string `json:"content"`
266 CreatedAt string `json:"created_at"`
267 ID string `json:"id"`
268 UpdatedAt string `json:"updated_at"`
269 URL string `json:"url"`
270 } `json:"results"`
271 }
272
273 // MovieReviews returns a list of reviews for the specified movie
274 func (t *TMDB) MovieReviews(id int64, params ...option) (*Reviews, error) {
275 r := new(Reviews)
276 if err := t.get(r, fmt.Sprintf("/3/movie/%d/reviews", id), url.Values{}, params...); err != nil {
277 return nil, err
278 }
279 return r, nil
280 }
281
282 // MovieSimilar retrieves a list of recommended movies for a movie
283 func (t *TMDB) MovieSimilar(id int64, params ...option) (*SearchMovie, error) {
284 s := new(SearchMovie)
285 if err := t.get(s, fmt.Sprintf("/3/movie/%d/similar", id), url.Values{}, params...); err != nil {
286 return nil, err
287 }
288 return s, nil
289 }
290
291 // MovieTranslations retrieves all of the translations for a movie
292 func (t *TMDB) MovieTranslations(id int64) (*Translations, error) {
293 tr := new(Translations)
294 if err := t.get(t, fmt.Sprintf("/3/movie/%d/translations", id), url.Values{}); err != nil {
295 return nil, err
296 }
297 return tr, nil
298 }
299
300 // Videos contains all of the videos related to a movie
301 type Videos struct {
302 ID int64 `json:"id"`
303 Results []struct {
304 ID string `json:"id"`
305 Language string `json:"iso_639_1"`
306 Country string `json:"iso_3166_1"`
307 Key string `json:"key"`
308 Name string `json:"name"`
309 Site string `json:"site"`
310 Size int64 `json:"size"`
311 Type string `json:"type"`
312 } `json:"results"`
313 }
314
315 // MovieVideos retrieves all of the videos related to a movie
316 func (t *TMDB) MovieVideos(id int64, params ...option) (*Videos, error) {
317 v := new(Videos)
318 if err := t.get(v, fmt.Sprintf("/3/movie/%d/videos", id), url.Values{}, params...); err != nil {
319 return nil, err
320 }
321 return v, nil
322 }
323
324 // WatchProviderData contains information about the provider of a video service
325 type WatchProviderData struct {
326 DisplayPriority int64 `json:"display_priority"`
327 LogoPath string `json:"logo_path"`
328 ProviderID int64 `json:"provider_id"`
329 ProviderName string `json:"provider_name"`
330 }
331
332 // WatchProviders contains all of the information about where and how to watch a movie
333 type WatchProviders struct {
334 ID int64 `json:"id"`
335 Results struct {
336 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 {
337 Link string `json:"link"`
338 Flatrate WatchProviderData `json:"flatrate"`
339 Rent WatchProviderData `json:"rent"`
340 But WatchProviderData `json:"buy"`
341 }
342 } `json:"results"`
343 }
344
345 // MovieWatchProviders retrieves all of the ways to watch a movie
346 func (t *TMDB) MovieWatchProviders(id int64) (*WatchProviders, error) {
347 m := new(WatchProviders)
348 if err := t.get(m, fmt.Sprintf("/3/movie/%d/watch/providers", id), url.Values{}); err != nil {
349 return nil, err
350 }
351 return m, nil
352 }
353
354 // MovieLatest returns the latest movie added to the database
355 func (t *TMDB) MovieLatest(params ...option) (*MovieDetails, error) {
356 m := new(MovieDetails)
357 if err := t.get(m, "/3/movie/latest", url.Values{}, params...); err != nil {
358 return nil, err
359 }
360 return m, nil
361 }
362
363 // MoviesWithDates contains a list of movies and the minimum and maximum play dates
364 type MoviesWithDates struct {
365 Search
366 Results []MovieResult `json:"results"`
367 Dates struct {
368 Maximum string `json:"maximum"`
369 Minimum string `json:"minimum"`
370 }
371 }
372
373 // MovieNowPlaying retrives a list of currently playing movies
374 func (t *TMDB) MovieNowPlaying(params ...option) (*MoviesWithDates, error) {
375 m := new(MoviesWithDates)
376 if err := t.get(m, "/3/movie/now_playing", url.Values{}, params...); err != nil {
377 return nil, err
378 }
379 return m, nil
380 }
381
382 // MoviePopular retrieves a list of popular movies
383 func (t *TMDB) MoviePopular(params ...option) (*SearchMovie, error) {
384 s := new(SearchMovie)
385 if err := t.get(s, "/3/movie/popular", url.Values{}, params...); err != nil {
386 return nil, err
387 }
388 return s, nil
389 }
390
391 // MovieTopRated retrieves a list of top-rated movies
392 func (t *TMDB) MovieTopRated(params ...option) (*SearchMovie, error) {
393 s := new(SearchMovie)
394 if err := t.get(s, "/3/movie/top_rated", url.Values{}, params...); err != nil {
395 return nil, err
396 }
397 return s, nil
398 }
399
400 // MovieUpcoming retrieves a list of upcoming movies
401 func (t *TMDB) MovieUpcoming(params ...option) (*MoviesWithDates, error) {
402 m := new(MoviesWithDates)
403 if err := t.get(m, "/3/movie/upcoming", url.Values{}, params...); err != nil {
404 return nil, err
405 }
406 return m, nil
407 }