This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
forked from tvtio/tmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
season.go
106 lines (102 loc) · 3.37 KB
/
season.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
98
99
100
101
102
103
104
105
106
// 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"
)
// Season type represents The Movie's Database TV Show Season
type Season struct {
ID int `json:"id"`
Name string `json:"name"`
Overview string `json:"overview"`
PosterPath string `json:"poster_path"`
SeasonNumber int `json:"season_number"`
AirDate string `json:"air_date"`
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"`
Episodes []struct {
AirDate string `json:"air_date"`
Crew []struct {
CreditID string `json:"credit_id"`
Department string `json:"department"`
ID int `json:"id"`
Job string `json:"job"`
Name string `json:"name"`
ProfilePath interface{} `json:"profile_path"`
} `json:"crew"`
EpisodeNumber int `json:"episode_number"`
GuestStars []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:"guest_stars"`
ID int `json:"id"`
Name string `json:"name"`
Overview string `json:"overview"`
ProductionCode interface{} `json:"production_code"`
SeasonNumber int `json:"season_number"`
StillPath string `json:"still_path"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
} `json:"episodes"`
ExternalIds struct {
FreebaseID string `json:"freebase_id"`
FreebaseMid string `json:"freebase_mid"`
TvdbID interface{} `json:"tvdb_id"`
TvrageID interface{} `json:"tvrage_id"`
} `json:"external_ids"`
Images struct {
Posters []struct {
AspectRatio float64 `json:"aspect_ratio"`
FilePath string `json:"file_path"`
Height int `json:"height"`
Iso639_1 interface{} `json:"iso_639_1"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
Width int `json:"width"`
} `json:"posters"`
} `json:"images"`
Videos struct {
Results []interface{} `json:"results"`
} `json:"videos"`
}
// GetSeason ...
func (tmdb *TMDB) GetSeason(id string, snumber string) (result Season, err error) {
s := fmt.Sprintf("%stv/%s/season/%s?api_key=%s&append_to_response=credits,external_ids,images,videos", tmdb.BaseURL, id, snumber, 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
}