forked from ryanbradynd05/go-tmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
253 lines (236 loc) · 8.62 KB
/
search.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
package tmdb
import (
"fmt"
"net/url"
)
// CollectionSearchResults struct
type CollectionSearchResults struct {
Page int
Results []struct {
ID int
BackdropPath string `json:"backdrop_path"`
Name string
PosterPath string `json:"poster_path"`
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// CompanySearchResults struct
type CompanySearchResults struct {
Page int
Results []struct {
ID int
LogoPath string `json:"logo_path"`
Name string
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// KeywordSearchResults struct
type KeywordSearchResults struct {
Page int
Results []struct {
ID int
Name string
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// ListSearchResults struct
type ListSearchResults struct {
Page int
Results []struct {
Description string
FavoriteCount int `json:"favorite_count"`
ID string
ItemCount int `json:"item_count"`
Iso639_1 string `json:"iso_639_1"`
ListType string `json:"list_type"`
Name string
PosterPath string `json:"poster_path"`
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// MovieSearchResults struct
type MovieSearchResults struct {
Page int
Results []MovieShort
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// MultiSearchResults struct
type MultiSearchResults struct {
Page int
Results []struct {
BackdropPath string `json:"backdrop_path"`
ID int
OriginalName string `json:"original_name"`
OriginalTitle string `json:"original_title"`
Overview string `json:"overview"`
FirstAirDate string `json:"first_air_date"`
OriginCountry []string `json:"origin_country"`
PosterPath string `json:"poster_path"`
Popularity float32
Name string
VoteAverage float32 `json:"vote_average"`
VoteCount uint32 `json:"vote_count"`
MediaType string `json:"media_type"`
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// PersonSearchResults struct
type PersonSearchResults struct {
Page int
Results []struct {
Adult bool
ID int
Name string
Popularity float32
PosterPath string `json:"poster_path"`
KnownFor []struct {
Adult bool
BackdropPath string `json:"backdrop_path"`
ID int
OriginalTitle string `json:"original_title"`
ReleaseDate string `json:"release_date"`
PosterPath string `json:"poster_path"`
Popularity float32
Title string
VoteAverage float32 `json:"vote_average"`
VoteCount uint32 `json:"vote_count"`
MediaType string `json:"media_type"`
} `json:"known_for"`
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// TvSearchResults struct
type TvSearchResults struct {
Page int
Results []struct {
BackdropPath string `json:"backdrop_path"`
ID int
OriginalName string `json:"original_name"`
FirstAirDate string `json:"first_air_date"`
OriginCountry []string `json:"origin_country"`
PosterPath string `json:"poster_path"`
Popularity float32
Name string
VoteAverage float32 `json:"vote_average"`
VoteCount uint32 `json:"vote_count"`
}
TotalPages int `json:"total_pages"`
TotalResults int `json:"total_results"`
}
// SearchCollection searches for collections by name
// http://docs.themoviedb.apiary.io/#reference/search/searchcollection/get
func (tmdb *TMDb) SearchCollection(name string, options map[string]string) (*CollectionSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {},
"language": {}}
var collections CollectionSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/collection?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &collections)
return result.(*CollectionSearchResults), err
}
// SearchCompany searches for companies by name
// http://docs.themoviedb.apiary.io/#reference/search/searchcompany/get
func (tmdb *TMDb) SearchCompany(name string, options map[string]string) (*CompanySearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {}}
var companies CompanySearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/company?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &companies)
return result.(*CompanySearchResults), err
}
// SearchKeyword searches for keywords by name
// http://docs.themoviedb.apiary.io/#reference/search/searchkeyword/get
func (tmdb *TMDb) SearchKeyword(name string, options map[string]string) (*KeywordSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {}}
var keywords KeywordSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/keyword?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &keywords)
return result.(*KeywordSearchResults), err
}
// SearchList searches for lists by name and description
// http://docs.themoviedb.apiary.io/#reference/search/searchlist/get
func (tmdb *TMDb) SearchList(name string, options map[string]string) (*ListSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {},
"include_adult": {}}
var lists ListSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/list?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &lists)
return result.(*ListSearchResults), err
}
// SearchMovie searches for movies by title
// http://docs.themoviedb.apiary.io/#reference/search/searchmovie/get
func (tmdb *TMDb) SearchMovie(name string, options map[string]string) (*MovieSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {},
"language": {},
"include_adult": {},
"year": {},
"primary_release_year": {},
"search_type": {}}
var movies MovieSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/movie?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &movies)
return result.(*MovieSearchResults), err
}
// SearchMulti searches the movie, tv show and person collections with a single query
// http://docs.themoviedb.apiary.io/#reference/search/searchmulti/get
func (tmdb *TMDb) SearchMulti(name string, options map[string]string) (*MultiSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {},
"language": {},
"include_adult": {}}
var multis MultiSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/multi?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &multis)
return result.(*MultiSearchResults), err
}
// SearchPerson searches for people by name
// http://docs.themoviedb.apiary.io/#reference/search/searchperson/get
func (tmdb *TMDb) SearchPerson(name string, options map[string]string) (*PersonSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {},
"search_type": {},
"include_adult": {}}
var people PersonSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/person?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &people)
return result.(*PersonSearchResults), err
}
// SearchTv searches for TV shows by title
// http://docs.themoviedb.apiary.io/#reference/search/searchtv/get
func (tmdb *TMDb) SearchTv(name string, options map[string]string) (*TvSearchResults, error) {
var availableOptions = map[string]struct{}{
"page": {},
"language": {},
"search_type": {},
"first_air_date_year": {}}
var shows TvSearchResults
safeName := url.QueryEscape(name)
optionsString := getOptionsString(options, availableOptions)
uri := fmt.Sprintf("%s/search/tv?query=%s&api_key=%s%s", baseURL, safeName, tmdb.apiKey, optionsString)
result, err := getTmdb(uri, &shows)
return result.(*TvSearchResults), err
}