tvdb - search.go
1 package tvdb
2
3 import "net/url"
4
5 // Search is a representation of the data returned from a tv show search
6 type Search struct {
7 Aliases []string `json:"aliases"`
8 Banner string `json:"banner"`
9 FirstAired string `json:"firstAired"`
10 ID uint64 `json:"id"`
11 Network string `json:"network"`
12 Overview string `json:"overview"`
13 Name string `json:"seriesName"`
14 Status string `json:"status"`
15 }
16
17 func (c *Conn) search(key, value string) ([]Search, error) {
18 var r struct {
19 Data []Search `json:"data"`
20 Error requestErrors `json:"error"`
21 }
22 if err := c.get(makeURL("/search/series", key+"="+url.QueryEscape(value)), &r); err != nil {
23 if err == ErrNotFound {
24 return []Search{}, nil
25 }
26 return nil, err
27 }
28 return r.Data, nil
29 }
30
31 // Search searches the TVDB database for shows with the given name
32 func (c *Conn) Search(name string) ([]Search, error) {
33 return c.search("name", name)
34 }
35
36 // SearchIMDB searches the TVDB database for the show corrensponding to the
37 // given IMDB ID
38 func (c *Conn) SearchIMDB(imdb string) (*Search, error) {
39 ss, err := c.search("imdbId", imdb)
40 if err != nil || len(ss) == 0 {
41 if err == ErrNotFound {
42 return nil, nil
43 }
44 return nil, err
45 }
46 return &ss[0], nil
47 }
48
49 // SearchZap2It searches the TVDB database for the show corrensponding to the
50 // given Zap2It ID
51 func (c *Conn) SearchZap2It(zapit string) (*Search, error) {
52 ss, err := c.search("zap2itId", zapit)
53 if err != nil || len(ss) == 0 {
54 if err == ErrNotFound {
55 return nil, nil
56 }
57 return nil, err
58 }
59 return &ss[0], nil
60 }