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
/
movie.go
115 lines (111 loc) · 3.69 KB
/
movie.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
107
108
109
110
111
112
113
114
115
// 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"
)
// Movie type represents The Movie's Database Movie
type Movie struct {
Adult bool `json:"adult"`
BackdropPath string `json:"backdrop_path"`
Budget int `json:"budget"`
Homepage string `json:"homepage"`
ID int `json:"id"`
ImdbID string `json:"imdb_id"`
OriginalLanguage string `json:"original_language"`
OriginalTitle string `json:"original_title"`
Overview string `json:"overview"`
Popularity float64 `json:"popularity"`
PosterPath string `json:"poster_path"`
Revenue int `json:"revenue"`
ReleaseDate string `json:"release_date"`
Runtime int `json:"runtime"`
Status string `json:"status"`
Tagline string `json:"tagline"`
Title string `json:"title"`
Video bool `json:"video"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
BelongsToCollection struct {
BackdropPath string `json:"backdrop_path"`
ID int `json:"id"`
Name string `json:"name"`
PosterPath string `json:"poster_path"`
} `json:"belongs_to_collection"`
Credits struct {
Cast []struct {
CastID int `json:"cast_id"`
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"`
Genres []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"genres"`
Images struct {
Backdrops []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:"backdrops"`
Posters []struct {
AspectRatio float64 `json:"aspect_ratio"`
FilePath string `json:"file_path"`
Height int `json:"height"`
Iso639_1 string `json:"iso_639_1"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
Width int `json:"width"`
} `json:"posters"`
} `json:"images"`
ProductionCompanies []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"production_companies"`
ProductionCountries []struct {
Iso3166_1 string `json:"iso_3166_1"`
Name string `json:"name"`
} `json:"production_countries"`
SpokenLanguages []struct {
Iso639_1 string `json:"iso_639_1"`
Name string `json:"name"`
} `json:"spoken_languages"`
}
// GetMovie ...
func (tmdb *TMDB) GetMovie(id string) (result Movie, err error) {
s := fmt.Sprintf("%smovie/%s?api_key=%s&append_to_response=credits,images", 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
}