-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie.go
186 lines (145 loc) · 3.91 KB
/
movie.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
package trakt
import (
"encoding/json"
"time"
)
type ReleaseType string
const (
ReleaseTypeUnknown ReleaseType = "unknown"
ReleaseTypePremiere ReleaseType = "premiere"
ReleaseTypeLimited ReleaseType = "limited"
ReleaseTypeTheatrical ReleaseType = "theatrical"
ReleaseTypeDigital ReleaseType = "digital"
ReleaseTypePhysical ReleaseType = "physical"
ReleaseTypeTV ReleaseType = "tv"
)
type TimePeriodListParams struct {
BasicListParams
Filters
Period TimePeriod `url:"-" json:"-"`
Extended ExtendedType `url:"extended" json:"-"`
}
type BoxOfficeListParams = ExtendedParams
type RecentlyUpdatedListParams struct {
BasicListParams
StartDate time.Time `json:"-" url:"-"`
Extended ExtendedType `url:"extended" json:"-"`
}
type ReleaseListParams struct {
BasicListParams
Country string `json:"-" url:"-"`
}
type Movie struct {
commonElements `json:",inline"`
Year int64 `json:"-"`
Tagline string `json:"tagline"`
Released time.Time `json:"released"`
Certification string `json:"certification"`
Country string `json:"country"`
TrailerURL string `json:"trailer"`
HomepageURL string `json:"homepage"`
Status Status `json:"status"`
Genres []string `json:"genre"`
Language string `json:"language"`
}
func (m *Movie) UnmarshalJSON(bytes []byte) error {
type B Movie
type A struct {
B
Released string `json:"released"`
Year interface{} `json:"year"`
}
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return err
}
if len(a.Released) > 0 {
a.B.Released, err = time.Parse(`2006-01-02`, a.Released)
}
a.B.Year, err = parseYear(a.Year)
if err != nil {
return err
}
*m = Movie(a.B)
return err
}
type MovieIterator struct{ Iterator }
func (m *MovieIterator) Movie() (*Movie, error) {
rcv := &Movie{}
return rcv, m.Scan(rcv)
}
type Release struct {
Country string `json:"country"`
Certification string `json:"certification"`
ReleaseDate time.Time `json:"-"`
ReleaseType ReleaseType `json:"release_type"`
Note string `json:"note"`
}
func (r *Release) UnmarshalJSON(bytes []byte) error {
type B Release
type A struct {
B
Released string `json:"release_date"`
}
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return err
}
if len(a.Released) > 0 {
a.B.ReleaseDate, err = time.Parse(`2006-01-02`, a.Released)
}
*r = Release(a.B)
return err
}
type ReleaseIterator struct{ BasicIterator }
func (r *ReleaseIterator) Release() (*Release, error) {
rcv := &Release{}
return rcv, r.Scan(rcv)
}
type TrendingMovie struct {
Movie `json:"movie"`
Watchers int64 `json:"watchers"`
}
type TrendingMovieIterator struct{ Iterator }
func (t *TrendingMovieIterator) Trending() (*TrendingMovie, error) {
rcv := &TrendingMovie{}
return rcv, t.Scan(rcv)
}
type RecentlyUpdatedMovie struct {
Movie `json:"movie"`
UpdatedAt time.Time `json:"updated_at"`
}
type RecentlyUpdatedMovieIterator struct{ Iterator }
func (m *RecentlyUpdatedMovieIterator) Movie() (*RecentlyUpdatedMovie, error) {
rcv := &RecentlyUpdatedMovie{}
return rcv, m.Scan(rcv)
}
type MovieWithStatistics struct {
statistics
Movie `json:"movie"`
}
type MovieWithStatisticsIterator struct{ Iterator }
func (m *MovieWithStatisticsIterator) Movie() (*MovieWithStatistics, error) {
rcv := &MovieWithStatistics{}
return rcv, m.Scan(rcv)
}
type AnticipatedMovie struct {
ListCount int64 `json:"list_count"`
Movie `json:"movie"`
}
type AnticipatedMovieIterator struct{ Iterator }
func (a *AnticipatedMovieIterator) Movie() (*AnticipatedMovie, error) {
rcv := &AnticipatedMovie{}
return rcv, a.Scan(rcv)
}
type BoxOfficeMovie struct {
Revenue int64 `json:"revenue"`
Movie `json:"movie"`
}
type BoxOfficeMovieIterator struct{ BasicIterator }
func (m *BoxOfficeMovieIterator) Movie() (*BoxOfficeMovie, error) {
rcv := &BoxOfficeMovie{}
return rcv, m.Scan(rcv)
}