tmdb - search.go
1 package tmdb
2
3 import (
4 "net/url"
5 )
6
7 // Search stores the pages fields for a returned search.
8 type Search struct {
9 Page int64 `json:"page"`
10 TotalResults int64 `json:"total_results"`
11 TotalPages int64 `json:"total_pages"`
12 }
13
14 // CompanyResult stores a single result of a company search.
15 type CompanyResult struct {
16 ID int64 `json:"id"`
17 LogoPath *string `json:"logo_path"`
18 Name string `json:"name"`
19 }
20
21 // SearchCompany is the results returned from a Company search.
22 type SearchCompany struct {
23 Search
24 Results []CompanyResult `json:"results"`
25 }
26
27 // SearchCompany searches the TMDB Movie database for the name given.
28 func (t *TMDB) SearchCompany(query string, params ...option) (*SearchCompany, error) {
29 s := new(SearchCompany)
30
31 if err := t.get(s, "/3/search/company", url.Values{"query": []string{query}}, params...); err != nil {
32 return nil, err
33 }
34
35 return s, nil
36 }
37
38 // CollectionResult stores a single result of a collection search.
39 type CollectionResult struct {
40 ID int64 `json:"id"`
41 BackdropPath *string `json:"backdrop_path"`
42 Name string `json:"name"`
43 PosterPath *string `json:"poster_path"`
44 }
45
46 // SearchCollection is the results returned from a Collection search.
47 type SearchCollection struct {
48 Search
49 Results []CollectionResult `json:"results"`
50 }
51
52 // SearchCollection searches the TMDB Movie database for the name given.
53 func (t *TMDB) SearchCollection(query string, params ...option) (*SearchCollection, error) {
54 s := new(SearchCollection)
55
56 if err := t.get(s, "/3/search/collection", url.Values{"query": []string{query}}, params...); err != nil {
57 return nil, err
58 }
59
60 return s, nil
61 }
62
63 // SearchKeywords is the results returned from a Keyword search.
64 type SearchKeywords struct {
65 Search
66 Results []Keyword `json:"results"`
67 }
68
69 // SearchKeywords search the TMDB database for the tersm given.
70 func (t *TMDB) SearchKeywords(query string, params ...option) (*SearchKeywords, error) {
71 s := new(SearchKeywords)
72
73 if err := t.get(s, "/3/search/keyword", url.Values{"query": []string{query}}, params...); err != nil {
74 return nil, err
75 }
76
77 return s, nil
78 }
79
80 // MovieResult stores a single result of a movie search.
81 type MovieResult struct {
82 PosterPath *string `json:"poster_path"`
83 Adult bool `json:"adult"`
84 Overview string `json:"overview"`
85 ReleaseDate string `json:"release_date"`
86 GenreIDs []int64 `json:"genre_ids"`
87 ID int64 `json:"id"`
88 OriginalTitle string `json:"original_title"`
89 OriginalLanguage string `json:"original_language"`
90 Title string `json:"title"`
91 BackdropPath *string `json:"backdrop_path"`
92 Popularity float64 `json:"popularity"`
93 VoteCount int64 `json:"vote_count"`
94 Video bool `json:"video"`
95 VoteAverage float64 `json:"vote_average"`
96 }
97
98 // SearchMovie is the results returned from a Movie search.
99 type SearchMovie struct {
100 Search
101 Results []MovieResult `json:"results"`
102 }
103
104 // SearchMovie searches the TMDB Movie database for the name given.
105 func (t *TMDB) SearchMovie(query string, params ...option) (*SearchMovie, error) {
106 s := new(SearchMovie)
107
108 if err := t.get(s, "/3/search/movie", url.Values{"query": []string{query}}, params...); err != nil {
109 return nil, err
110 }
111
112 return s, nil
113 }
114
115 // TVOrMovie contains information which could be for either a TV show or a movie.
116 type TVOrMovie struct {
117 PosterPath *string `json:"poster_path"`
118 Adult bool `json:"adult"`
119 Overview string `json:"overview"`
120 ReleaseDate string `json:"release_date"`
121 OriginalTitle string `json:"original_title"`
122 GenreIDs []int64 `json:"genre_ids"`
123 ID int64 `json:"id"`
124 OriginalLanguage string `json:"original_language"`
125 Title string `json:"title"`
126 BackdropPath *string `json:"backdrop_path"`
127 Popularity float64 `json:"popularity"`
128 VoteCount int64 `json:"vote_count"`
129 Video bool `json:"video"`
130 VoteAverage float64 `json:"vote_average"`
131 FirstAirDate string `json:"first_air_date"`
132 OriginCountry []string `json:"origin_country"`
133 Name string `json:"name"`
134 OriginalName string `json:"original_name"`
135 }
136
137 // PeopleResult stores a single result of a people search.
138 type PeopleResult struct {
139 ProfilePath *string `json:"profile_path"`
140 Adult bool `json:"adult"`
141 ID int64 `json:"id"`
142 KnownFor struct {
143 TVOrMovie
144 MediaType string `json:"media_type"`
145 } `json:"known_for"`
146 Name string `json:"name"`
147 Popularity float64 `json:"popularity"`
148 }
149
150 // SearchPeople searc the TMDB People database for the name given.
151 type SearchPeople struct {
152 Search
153 Results []PeopleResult `json:"results"`
154 }
155
156 // SearchPerson searches the TMDB people database for the name given.
157 func (t *TMDB) SearchPerson(query string, params ...option) (*SearchPeople, error) {
158 s := new(SearchPeople)
159
160 if err := t.get(s, "/3/search/person", url.Values{"query": []string{query}}, params...); err != nil {
161 return nil, err
162 }
163
164 return s, nil
165 }
166
167 // TVResult stores a single result of a TV search.
168 type TVResult struct {
169 PosterPath *string `json:"poster_path"`
170 Popularity float64 `json:"popularity"`
171 ID int64 `json:"id"`
172 BackdropPath string `json:"backdrop_path"`
173 VoteAverage float64 `json:"vote_average"`
174 Overview string `json:"overview"`
175 FirstAirDate string `json:"first_air_date"`
176 OriginCountry []string `json:"origin_country"`
177 GenreIDs []int64 `json:"genre_ids"`
178 OriginalLanguage string `json:"original_language"`
179 VoteCount int64 `json:"vote_count"`
180 Name string `json:"name"`
181 OriginalName string `json:"original_name"`
182 }
183
184 // SearchTV is the results returned from a TV search.
185 type SearchTV struct {
186 Search
187 Results []TVResult `json:"results"`
188 }
189
190 // SearchTV searches the TMDB TV show database for the name given.
191 func (t *TMDB) SearchTV(query string, params ...option) (*SearchTV, error) {
192 s := new(SearchTV)
193
194 if err := t.get(s, "/3/search/tv", url.Values{"query": []string{query}}, params...); err != nil {
195 return nil, err
196 }
197
198 return s, nil
199 }
200