Fix: when proxy, hide vendor url and hide header

pull/24/head
zijiren233 1 year ago
parent ea6b8717b8
commit 1a0a02040f

@ -59,6 +59,10 @@ func MovieList(ctx *gin.Context) {
mresp := make([]model.MoviesResp, len(m)) mresp := make([]model.MoviesResp, len(m))
for i, v := range m { for i, v := range m {
// hide headers when proxy
if m[i].Base.Proxy {
m[i].Base.Headers = nil
}
mresp[i] = model.MoviesResp{ mresp[i] = model.MoviesResp{
Id: v.ID, Id: v.ID,
Base: m[i].Base, Base: m[i].Base,
@ -83,12 +87,16 @@ func MovieList(ctx *gin.Context) {
func genCurrent(current *op.Current, userID string) (*op.Current, error) { func genCurrent(current *op.Current, userID string) (*op.Current, error) {
if current.Movie.Base.Vendor != "" { if current.Movie.Base.Vendor != "" {
return current, parse2VendorMovie(userID, &current.Movie) return current, parse2VendorMovie(userID, &current.Movie, !current.Movie.Base.Proxy)
} }
return current, nil return current, nil
} }
func genCurrentResp(current *op.Current) *model.CurrentMovieResp { func genCurrentResp(current *op.Current) *model.CurrentMovieResp {
// hide headers when proxy
if current.Movie.Base.Proxy {
current.Movie.Base.Headers = nil
}
return &model.CurrentMovieResp{ return &model.CurrentMovieResp{
Status: current.Status, Status: current.Status,
Movie: model.MoviesResp{ Movie: model.MoviesResp{
@ -130,6 +138,10 @@ func Movies(ctx *gin.Context) {
mresp := make([]model.MoviesResp, len(m)) mresp := make([]model.MoviesResp, len(m))
for i, v := range m { for i, v := range m {
// hide headers when proxy
if m[i].Base.Proxy {
m[i].Base.Headers = nil
}
mresp[i] = model.MoviesResp{ mresp[i] = model.MoviesResp{
Id: v.ID, Id: v.ID,
Base: m[i].Base, Base: m[i].Base,
@ -420,7 +432,7 @@ func ProxyMovie(ctx *gin.Context) {
} }
if m.Base.VendorInfo.Vendor != "" { if m.Base.VendorInfo.Vendor != "" {
err = parse2VendorMovie(m.Movie.CreatorID, m.Movie) err = parse2VendorMovie(m.Movie.CreatorID, m.Movie, true)
if err != nil { if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorResp(err)) ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorResp(err))
return return
@ -492,7 +504,7 @@ func JoinLive(ctx *gin.Context) {
} }
} }
func parse2VendorMovie(userID string, movie *dbModel.Movie) (err error) { func parse2VendorMovie(userID string, movie *dbModel.Movie, getUrl bool) (err error) {
if movie.Base.VendorInfo.Shared { if movie.Base.VendorInfo.Shared {
userID = movie.CreatorID userID = movie.CreatorID
} }
@ -507,18 +519,20 @@ func parse2VendorMovie(userID string, movie *dbModel.Movie) (err error) {
} }
cli := bilibili.NewClient(vendor.Cookies) cli := bilibili.NewClient(vendor.Cookies)
var mu *bilibili.VideoURL if getUrl {
if info.Bvid != "" { var mu *bilibili.VideoURL
mu, err = cli.GetVideoURL(0, info.Bvid, info.Cid, bilibili.WithQuality(info.Quality)) if info.Bvid != "" {
} else if info.Epid != 0 { mu, err = cli.GetVideoURL(0, info.Bvid, info.Cid, bilibili.WithQuality(info.Quality))
mu, err = cli.GetPGCURL(info.Epid, 0, bilibili.WithQuality(info.Quality)) } else if info.Epid != 0 {
} else { mu, err = cli.GetPGCURL(info.Epid, 0, bilibili.WithQuality(info.Quality))
err = errors.New("bvid and epid are empty") } else {
} err = errors.New("bvid and epid are empty")
if err != nil { }
return err if err != nil {
return err
}
movie.Base.Url = mu.URL
} }
movie.Base.Url = mu.URL
return nil return nil

Loading…
Cancel
Save