tvdb - series.go
1 package tvdb
2
3 import (
4 "fmt"
5 "net/url"
6 "strconv"
7 )
8
9 // Series represents all of the information about a particular show.
10 type Series struct {
11 ID uint64 `json:"id"`
12 Name string `json:"seriesName"`
13 Aliases []string `json:"aliases"`
14 Banner string `json:"banner"`
15 SeriesID string `json:"seriesId"`
16 Status string `json:"status"`
17 FirstAired string `json:"firstAired"`
18 Network string `json:"network"`
19 NetworkID string `json:"networkId"`
20 Runtime string `json:"runtime"`
21 Genre []string `json:"genre"`
22 Overview string `json:"overview"`
23 LastUpdated uint64 `json:"lastUpdated"`
24 AirsDayOfWeek string `json:"airsDayOfWeek"`
25 AirsTime string `json:"airsTime"`
26 Rating string `json:"rating"`
27 IMDBID string `json:"imdbId"`
28 Zap2ItID string `json:"zap2ItId"`
29 Added string `json:"added"`
30 SiteRating float32 `json:"siteRating"`
31 SiteRatingCount uint64 `json:"siteRatingCount"`
32 }
33
34 // Series retrieves the information about a particular series by its ID.
35 func (c *Conn) Series(id uint64) (*Series, error) {
36 var r struct {
37 Data *Series `json:"data"`
38 Error requestErrors `json:"error"`
39 }
40
41 if err := c.get(makeURL(fmt.Sprintf("/series/%d", id), ""), &r); err != nil {
42 return nil, err
43 }
44
45 return r.Data, nil
46 }
47
48 // Actor represents all of the information about an actor in a show.
49 type Actor struct {
50 ID uint64 `json:"id"`
51 SeriesID uint64 `json:"seriesId"`
52 Name string `json:"name"`
53 Role string `json:"role"`
54 SortOrder uint `json:"sortOrder"`
55 Image string `json:"image"`
56 ImageAuthor uint64 `json:"imageAuthor"`
57 ImageAdded string `json:"imageAdded"`
58 LastUpdated string `json:"lastUpdated"`
59 }
60
61 // Actors returns information about the actors in a show, denoted by its ID.
62 func (c *Conn) Actors(id uint64) ([]Actor, error) {
63 var r struct {
64 Data []Actor `json:"data"`
65 Error requestErrors `json:"error"`
66 }
67
68 if err := c.get(makeURL(fmt.Sprintf("/series/%d/actors", id), ""), &r); err != nil {
69 return nil, err
70 }
71
72 return r.Data, nil
73 }
74
75 // SeriesEpisode represents all of the information about a particular episode
76 // of a show.
77 type SeriesEpisode struct {
78 AbsoluteNumber uint `json:"absoluteNumber"`
79 AiredEpisodeNumber uint `json:"airedEpisodeNumber"`
80 AiredSeason uint `json:"airedSeason"`
81 DVDEpisodeNumber float32 `json:"dvdEpisodeNumber"`
82 DVDSeason uint `json:"dvdSeason"`
83 Name string `json:"episodeName"`
84 ID uint64 `json:"id"`
85 Overview string `json:"overview"`
86 FirstAired string `json:"firstAired"`
87 LastUpdated uint64 `json:"lastUpdated"`
88 }
89
90 // Episodes returns a paginated view (100 per page) of the episodes in a
91 // particular series.
92 func (c *Conn) Episodes(id uint64, page uint64) ([]SeriesEpisode, error) {
93 return c.episodes(id, make(url.Values), page)
94 }
95
96 func (c *Conn) episodes(id uint64, v url.Values, page uint64) ([]SeriesEpisode, error) {
97 path := "/series/%d/episodes/query"
98
99 if len(v) == 0 {
100 path = "/series/%d/episodes"
101 }
102
103 if page > 0 {
104 v.Set("page", strconv.FormatUint(page, 10))
105 }
106
107 var r struct {
108 Data []SeriesEpisode `json:"data"`
109 Error requestErrors `json:"error"`
110 }
111
112 if err := c.get(makeURL(fmt.Sprintf(path, id), v.Encode()), &r); err != nil {
113 return nil, err
114 }
115
116 return r.Data, nil
117 }
118
119 // SeasonEpisodes returns a paginated view (100 per page) of the episodes in a
120 // season of a show.
121 func (c *Conn) SeasonEpisodes(id uint64, season uint64, page uint64) ([]SeriesEpisode, error) {
122 v := make(url.Values)
123
124 v.Set("airedSeason", strconv.FormatUint(season, 10))
125
126 return c.episodes(id, v, page)
127 }
128
129 // DVDSeasonEpisodes returns a paginatied view (100 per page) of the episodes
130 // in the DVD season of a show.
131 func (c *Conn) DVDSeasonEpisodes(id uint64, season uint64, page uint64) ([]SeriesEpisode, error) {
132 v := make(url.Values)
133
134 v.Set("dvdSeason", strconv.FormatUint(season, 10))
135
136 return c.episodes(id, v, page)
137 }
138
139 // SeriesEpisode returns the information about a particular episode in a series
140 // denoted by its absolute episode number.
141 func (c *Conn) SeriesEpisode(id uint64, abs uint64) (*SeriesEpisode, error) {
142 v := make(url.Values)
143
144 v.Set("absoluteNumber", strconv.FormatUint(abs, 10))
145
146 se, err := c.episodes(id, v, 0)
147 if err != nil || len(se) == 0 {
148 return nil, err
149 }
150
151 return &se[0], nil
152 }
153
154 // SeasonEpisode returns the information about a particular episode in a series
155 // denoted by its season and episode numbers.
156 func (c *Conn) SeasonEpisode(id uint64, season, episode uint64) (*SeriesEpisode, error) {
157 v := make(url.Values)
158
159 v.Set("airedSeason", strconv.FormatUint(season, 10))
160 v.Set("airedEpisode", strconv.FormatUint(episode, 10))
161
162 se, err := c.episodes(id, v, 0)
163 if err != nil || len(se) == 0 {
164 return nil, err
165 }
166
167 return &se[0], nil
168 }
169
170 // DVDSeasonEpisode returns the information about a particular episode in a
171 // series denoted by its DVD season and episode numbers.
172 func (c *Conn) DVDSeasonEpisode(id uint64, season, episode uint64) (*SeriesEpisode, error) {
173 v := make(url.Values)
174
175 v.Set("dvdSeason", strconv.FormatUint(season, 10))
176 v.Set("dvdEpisode", strconv.FormatUint(episode, 10))
177
178 se, err := c.episodes(id, v, 0)
179 if err != nil || len(se) == 0 {
180 return nil, err
181 }
182
183 return &se[0], nil
184 }
185
186 // Summary represents the information about episodes for a particular show.
187 type Summary struct {
188 AiredSeasons []string `json:"airedSeasons"`
189 AiredEpisodes string `json:"airedEpisodes"`
190 DVDSeasons []string `json:"dvdSeasons"`
191 DVDEpisodes string `json:"dvdEpisodes"`
192 }
193
194 // SeriesSummary returns the summary information about episodes for a tv show.
195 func (c *Conn) SeriesSummary(id uint) (*Summary, error) {
196 var r struct {
197 Data *Summary `json:"data"`
198 Error requestErrors `json:"error"`
199 }
200
201 if err := c.get(makeURL(fmt.Sprintf("/series/%d/episodes/summary", id), ""), &r); err != nil {
202 return nil, err
203 }
204
205 return r.Data, nil
206 }
207