-
Notifications
You must be signed in to change notification settings - Fork 1
/
tv.go
97 lines (93 loc) · 2.98 KB
/
tv.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
// Copyright 2016 The tmdb Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package tmdb
import (
"encoding/json"
"errors"
"fmt"
"net/url"
)
// TV type represents The Movie's Database TV Show
type TV struct {
BackdropPath string `json:"backdrop_path"`
CreatedBy []struct {
ID int `json:"id"`
Name string `json:"name"`
ProfilePath string `json:"profile_path"`
} `json:"created_by"`
Credits struct {
Cast []struct {
Character string `json:"character"`
CreditID string `json:"credit_id"`
ID int `json:"id"`
Name string `json:"name"`
Order int `json:"order"`
ProfilePath string `json:"profile_path"`
} `json:"cast"`
Crew []struct {
CreditID string `json:"credit_id"`
Department string `json:"department"`
ID int `json:"id"`
Job string `json:"job"`
Name string `json:"name"`
ProfilePath string `json:"profile_path"`
} `json:"crew"`
} `json:"credits"`
EpisodeRunTime []int `json:"episode_run_time"`
FirstAirDate string `json:"first_air_date"`
Genres []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"genres"`
Homepage string `json:"homepage"`
ID int `json:"id"`
InProduction bool `json:"in_production"`
Languages []string `json:"languages"`
LastAirDate string `json:"last_air_date"`
Name string `json:"name"`
Networks []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"networks"`
NumberOfEpisodes int `json:"number_of_episodes"`
NumberOfSeasons int `json:"number_of_seasons"`
OriginCountry []string `json:"origin_country"`
OriginalLanguage string `json:"original_language"`
OriginalName string `json:"original_name"`
Overview string `json:"overview"`
Popularity float64 `json:"popularity"`
PosterPath string `json:"poster_path"`
ProductionCompanies []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"production_companies"`
Seasons []struct {
AirDate interface{} `json:"air_date"`
EpisodeCount int `json:"episode_count"`
ID int `json:"id"`
PosterPath string `json:"poster_path"`
SeasonNumber int `json:"season_number"`
} `json:"seasons"`
Status string `json:"status"`
Type string `json:"type"`
VoteAverage float32 `json:"vote_average"`
VoteCount int `json:"vote_count"`
}
// GetTV ...
func (tmdb *TMDB) GetTV(id string) (result TV, err error) {
s := fmt.Sprintf("%stv/%s?api_key=%s&append_to_response=credits", tmdb.BaseURL, id, tmdb.APIKey)
u, err := url.Parse(s)
if err != nil {
return result, err
}
body, resp, err := tmdb.FetchContent(u)
if err != nil {
return result, err
}
if resp.StatusCode != 200 {
return result, errors.New(resp.Status)
}
err = json.Unmarshal(body, &result)
return result, err
}