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 if err := c.get(makeURL(fmt.Sprintf("/series/%d", id), ""), &r); err != nil {
41 return nil, err
42 }
43 return r.Data, nil
44 }
45
46 // Actor represents all of the information about an actor in a show
47 type Actor struct {
48 ID uint64 `json:"id"`
49 SeriesID uint64 `json:"seriesId"`
50 Name string `json:"name"`
51 Role string `json:"role"`
52 SortOrder uint `json:"sortOrder"`
53 Image string `json:"image"`
54 ImageAuthor uint64 `json:"imageAuthor"`
55 ImageAdded string `json:"imageAdded"`
56 LastUpdated string `json:"lastUpdated"`
57 }
58
59 // Actors returns information about the actors in a show, denoted by its ID
60 func (c *Conn) Actors(id uint64) ([]Actor, error) {
61 var r struct {
62 Data []Actor `json:"data"`
63 Error requestErrors `json:"error"`
64 }
65 if err := c.get(makeURL(fmt.Sprintf("/series/%d/actors", id), ""), &r); err != nil {
66 return nil, err
67 }
68 return r.Data, nil
69 }
70
71 // SeriesEpisode represents all of the information about a particular episode
72 // of a show
73 type SeriesEpisode struct {
74 AbsoluteNumber uint `json:"absoluteNumber"`
75 AiredEpisodeNumber uint `json:"airedEpisodeNumber"`
76 AiredSeason uint `json:"airedSeason"`
77 DVDEpisodeNumber float32 `json:"dvdEpisodeNumber"`
78 DVDSeason uint `json:"dvdSeason"`
79 Name string `json:"episodeName"`
80 ID uint64 `json:"id"`
81 Overview string `json:"overview"`
82 FirstAired string `json:"firstAired"`
83 LastUpdated uint64 `json:"lastUpdated"`
84 }
85
86 // Episodes returns a paginated view (100 per page) of the episodes in a
87 // particular series
88 func (c *Conn) Episodes(id uint64, page uint64) ([]SeriesEpisode, error) {
89 return c.episodes(id, make(url.Values), page)
90 }
91
92 func (c *Conn) episodes(id uint64, v url.Values, page uint64) ([]SeriesEpisode, error) {
93 path := "/series/%d/episodes/query"
94 if len(v) == 0 {
95 path = "/series/%d/episodes"
96 }
97 if page > 0 {
98 v.Set("page", strconv.FormatUint(page, 10))
99 }
100 var r struct {
101 Data []SeriesEpisode `json:"data"`
102 Error requestErrors `json:"error"`
103 }
104 if err := c.get(makeURL(fmt.Sprintf(path, id), v.Encode()), &r); err != nil {
105 return nil, err
106 }
107 return r.Data, nil
108 }
109
110 // SeasonEpisodes returns a paginated view (100 per page) of the episodes in a
111 // season of a show
112 func (c *Conn) SeasonEpisodes(id uint64, season uint64, page uint64) ([]SeriesEpisode, error) {
113 v := make(url.Values)
114 v.Set("airedSeason", strconv.FormatUint(season, 10))
115 return c.episodes(id, v, page)
116 }
117
118 // DVDSeasonEpisodes returns a paginatied view (100 per page) of the episodes
119 // in the DVD season of a show
120 func (c *Conn) DVDSeasonEpisodes(id uint64, season uint64, page uint64) ([]SeriesEpisode, error) {
121 v := make(url.Values)
122 v.Set("dvdSeason", strconv.FormatUint(season, 10))
123 return c.episodes(id, v, page)
124 }
125
126 // SeriesEpisode returns the information about a particular episode in a series
127 // denoted by its absolute episode number
128 func (c *Conn) SeriesEpisode(id uint64, abs uint64) (*SeriesEpisode, error) {
129 v := make(url.Values)
130 v.Set("absoluteNumber", strconv.FormatUint(abs, 10))
131 se, err := c.episodes(id, v, 0)
132 if err != nil || len(se) == 0 {
133 return nil, err
134 }
135 return &se[0], nil
136 }
137
138 // SeasonEpisode returns the information about a particular episode in a series
139 // denoted by its season and episode numbers
140 func (c *Conn) SeasonEpisode(id uint64, season, episode uint64) (*SeriesEpisode, error) {
141 v := make(url.Values)
142 v.Set("airedSeason", strconv.FormatUint(season, 10))
143 v.Set("airedEpisode", strconv.FormatUint(episode, 10))
144 se, err := c.episodes(id, v, 0)
145 if err != nil || len(se) == 0 {
146 return nil, err
147 }
148 return &se[0], nil
149 }
150
151 // DVDSeasonEpisode returns the information about a particular episode in a
152 // series denoted by its DVD season and episode numbers
153 func (c *Conn) DVDSeasonEpisode(id uint64, season, episode uint64) (*SeriesEpisode, error) {
154 v := make(url.Values)
155 v.Set("dvdSeason", strconv.FormatUint(season, 10))
156 v.Set("dvdEpisode", strconv.FormatUint(episode, 10))
157 se, err := c.episodes(id, v, 0)
158 if err != nil || len(se) == 0 {
159 return nil, err
160 }
161 return &se[0], nil
162 }
163
164 // Summary represents the information about episodes for a particular show
165 type Summary struct {
166 AiredSeasons []string `json:"airedSeasons"`
167 AiredEpisodes string `json:"airedEpisodes"`
168 DVDSeasons []string `json:"dvdSeasons"`
169 DVDEpisodes string `json:"dvdEpisodes"`
170 }
171
172 // SeriesSummary returns the summary information about episodes for a tv show
173 func (c *Conn) SeriesSummary(id uint) (*Summary, error) {
174 var r struct {
175 Data *Summary `json:"data"`
176 Error requestErrors `json:"error"`
177 }
178 if err := c.get(makeURL(fmt.Sprintf("/series/%d/episodes/summary", id), ""), &r); err != nil {
179 return nil, err
180 }
181 return r.Data, nil
182 }