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