From 1fc33cf9ba8141e4260f147b1e9466882449f1f4 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Wed, 1 Nov 2023 22:21:21 +0800 Subject: [PATCH] Fix: default quality --- internal/model/movie.go | 8 ++++---- vendors/bilibili/movie.go | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/model/movie.go b/internal/model/movie.go index a850312..8e69bd8 100644 --- a/internal/model/movie.go +++ b/internal/model/movie.go @@ -150,8 +150,8 @@ type VendorInfo struct { } type BilibiliVendorInfo struct { - Bvid string `json:"bvid"` - Cid uint `json:"cid"` - Epid uint `json:"epid"` - Quality uint `json:"quality"` + Bvid string `json:"bvid,omitempty"` + Cid uint `json:"cid,omitempty"` + Epid uint `json:"epid,omitempty"` + Quality uint `json:"quality,omitempty"` } diff --git a/vendors/bilibili/movie.go b/vendors/bilibili/movie.go index 2fc95cd..e094737 100644 --- a/vendors/bilibili/movie.go +++ b/vendors/bilibili/movie.go @@ -91,6 +91,12 @@ type GetVideoURLConf struct { Quality uint } +func (c *GetVideoURLConf) fix() { + if c.Quality == 0 { + c.Quality = Q1080PP + } +} + type GetVideoURLConfig func(*GetVideoURLConf) func WithQuality(q uint) GetVideoURLConfig { @@ -107,6 +113,8 @@ func (c *Client) GetVideoURL(aid uint, bvid string, cid uint, conf ...GetVideoUR for _, v := range conf { v(config) } + config.fix() + var url string if aid != 0 { url = fmt.Sprintf("https://api.bilibili.com/x/player/wbi/playurl?aid=%d&cid=%d&qn=%d&platform=html5&high_quality=1", aid, cid, config.Quality) @@ -234,6 +242,7 @@ func (c *Client) GetPGCURL(ep_id, cid uint, conf ...GetVideoURLConfig) (*VideoUR for _, v := range conf { v(config) } + config.fix() var url string if ep_id != 0 {