Browse Source

Merge remote-tracking branch 'origin/master'

master v0.0.6
RealXLFD 3 months ago
parent
commit
c70ea81120
  1. 65
      tmdb/details.go
  2. 2
      tmdb/request.go
  3. 13
      tmdb/search.go
  4. 2
      tmdb/setter.go
  5. 1
      tmdb/static.go

65
tmdb/details.go

@ -1,16 +1,22 @@
package tmdb
import (
"encoding/json"
"errors"
"git.realxlfd.cc/RealXLFD/golib/urlbuilder"
"strconv"
)
type RespTVDetails struct {
Id string `json:"_id"`
AirDate string `json:"air_date"`
Episodes []struct {
} `json:"episodes"`
Name string `json:"name"`
Overview string `json:"overview"`
Id1 int `json:"id"`
PosterPath string `json:"poster_path"`
SeasonNumber int `json:"season_number"`
VoteAverage int `json:"vote_average"`
Id string `json:"_id"`
AirDate string `json:"air_date"`
Episodes []RespTVEpisodeDetails `json:"episodes"`
Name string `json:"name"`
Overview string `json:"overview"`
Id1 int `json:"id"`
PosterPath string `json:"poster_path"`
SeasonNumber int `json:"season_number"`
VoteAverage float32 `json:"vote_average"`
}
type RespTVEpisodeDetails struct {
@ -25,7 +31,7 @@ type RespTVEpisodeDetails struct {
SeasonNumber int `json:"season_number"`
ShowId int `json:"show_id"`
StillPath interface{} `json:"still_path"`
VoteAverage int `json:"vote_average"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
Crew []struct {
Department string `json:"department"`
@ -55,6 +61,39 @@ type RespTVEpisodeDetails struct {
} `json:"guest_stars"`
}
func ListTVEpisodes(id int) (*RespTVDetails, []error) {
func ListTVEpisodes(id, season int) (*RespTVDetails, []error) {
targetURL, _ := urlbuilder.New(baseURL.String()).AddPath(
strconv.Itoa(
ApiVersion,
),
).AddPath(path_TV).AddPath(strconv.Itoa(id)).AddPath(`season`).AddPath(strconv.Itoa(season)).AddQuery(
`language`,
string(ZH_CN),
).AddQuery(
`api_key`,
api_key,
).Get()
content, errs := sendRequest(targetURL)
if errs != nil {
if content != nil {
errMsg := &RespErrorInfo{}
_ = json.Unmarshal(
content,
errMsg,
)
return nil, []error{
errors.New(errMsg.StatusMessage),
}
}
return nil, errs
}
result := &RespTVDetails{}
err := json.Unmarshal(
content,
result,
)
if err != nil {
return nil, []error{err}
}
return result, nil
}

2
tmdb/request.go

@ -16,7 +16,7 @@ func sendRequest(target *url.URL) ([]byte, []error) {
return nil, errs
}
if resp.StatusCode != 200 {
return nil, []error{
return []byte(body), []error{
errors.New(`server error`),
}
}

13
tmdb/search.go

@ -2,8 +2,9 @@ package tmdb
import (
"encoding/json"
"errors"
"git.realxlfd.cc/RealXLFD/golib/urlbuilder"
"strconv"
"test/urlbuilder"
)
// RespSearchTV 搜索节目响应
@ -55,6 +56,16 @@ func SearchTV(name string) (*RespSearchTV, []error) {
).Get()
content, errs := sendRequest(targetURL)
if errs != nil {
if content != nil {
errMsg := &RespErrorInfo{}
_ = json.Unmarshal(
content,
errMsg,
)
return nil, []error{
errors.New(errMsg.StatusMessage),
}
}
return nil, errs
}
result := &RespSearchTV{}

2
tmdb/setter.go

@ -3,10 +3,10 @@ package tmdb
import (
"encoding/json"
"errors"
"git.realxlfd.cc/RealXLFD/golib/urlbuilder"
"github.com/parnurzeal/gorequest"
"net/url"
"strconv"
"test/urlbuilder"
)
// SetBase 设置api代理

1
tmdb/static.go

@ -25,4 +25,5 @@ const (
ApiVersion = 3
path_searchTV = `/search/tv`
path_auth = `/authentication`
path_TV = `/tv`
)

Loading…
Cancel
Save