2 changed files with 107 additions and 0 deletions
@ -0,0 +1,74 @@
|
||||
package TVDB |
||||
|
||||
import ( |
||||
"net/http" |
||||
"io/ioutil" |
||||
"encoding/xml" |
||||
"strconv" |
||||
) |
||||
|
||||
const API_KEY = "F1288743E87CEF50" |
||||
|
||||
|
||||
//Will ALWAYS return a slice of Series structs.
|
||||
//If an error is encountered when searching it will
|
||||
//return an empty slice
|
||||
func SearchShow(s string) []Series { |
||||
|
||||
if len(s) < 1 { |
||||
return make ([]Series, 0) |
||||
} |
||||
res,err := http.Get("http://thetvdb.com/api/GetSeries.php?seriesname=" + s) |
||||
defer res.Body.Close() |
||||
if err != nil { |
||||
return make([]Series, 0) |
||||
} |
||||
|
||||
body, err := ioutil.ReadAll(res.Body) |
||||
data := new(Data) |
||||
xml.Unmarshal(body, &data) |
||||
return data.Series |
||||
} |
||||
|
||||
func GetAllSeriesInfo(id int) (*Series, []Episode, error) { |
||||
|
||||
res, err := http.Get("http://thetvdb.com/api/" + API_KEY + "/series/" + strconv.Itoa(id) + "/all/en.xml") |
||||
defer res.Body.Close() |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
body, err := ioutil.ReadAll(res.Body) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
data := new(Data) |
||||
xml.Unmarshal(body, &data) |
||||
|
||||
|
||||
return &data.Series[0], data.Episode, nil |
||||
} |
||||
|
||||
func GetSeriesInfo(id int) (*Series, error) { |
||||
res, err := http.Get("http://thetvdb.com/api/" + API_KEY + "/series/" + strconv.Itoa(id) + "/en.xml") |
||||
defer res.Body.Close() |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
body, err := ioutil.ReadAll(res.Body) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
data := new(Data) |
||||
xml.Unmarshal(body, &data) |
||||
|
||||
|
||||
return &data.Series[0], nil |
||||
} |
||||
|
||||
func SearchEpisodes(id int) []Episode { |
||||
|
||||
|
||||
|
||||
|
||||
return nil |
||||
} |
@ -0,0 +1,33 @@
|
||||
package TVDB |
||||
|
||||
|
||||
type Series struct { |
||||
SeriesId int `xml:"seriesid"` |
||||
AirsDayOfWeek string `xml:"Airs_DayOfWeek"` |
||||
AirsTime string `xml:"Airs_Time"` |
||||
Language string `xml:"language"` |
||||
SeriesName string `xml:"SeriesName"` |
||||
AliasNames string `xml:"AliasNames"` |
||||
Overview string `xml:"Overview"` |
||||
FirstAired string `xml:"FirstAired"` |
||||
Network string `xml:"Network"` |
||||
IMDB_ID string `xml:"IMDB_ID"` |
||||
Id int `xml:"id"` |
||||
LastUpdated int64 `xml:"lastupdated"` |
||||
} |
||||
|
||||
type Episode struct { |
||||
Id int `xml:"id"` |
||||
CombinedSeason int `xml:"Combined_season"` |
||||
EpisodeName string `xml:"EpisodeName"` |
||||
EpisodeNumber int `xml:"EpisodeNumber"` |
||||
FirstAired string `xml:"FirstAired"` |
||||
Overview string `xml:"Overview"` |
||||
LastUpdated int64 `xml:"lastupdated"` |
||||
SeriesId int `xml:"seriesid"` |
||||
} |
||||
|
||||
type Data struct { |
||||
Series []Series `xml:"Series"` |
||||
Episode []Episode `xml:"Episode"` |
||||
} |
Loading…
Reference in new issue