From 6859c047722bc9835ae80f4cfbd934bd710893c5 Mon Sep 17 00:00:00 2001 From: wiserain Date: Sat, 13 May 2023 03:41:59 +0900 Subject: [PATCH] pikpak: add validity check when using a media link Before this change, the Pikpak backend would always download the first media item whenever possible, regardless of whether or not it was the original contents. Now we check the validity of a media link using the `fid` parameter in the link URL. Fixes #6992 --- backend/pikpak/api/types.go | 7 ++++--- backend/pikpak/pikpak.go | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/backend/pikpak/api/types.go b/backend/pikpak/api/types.go index e5a3ee0f5..fab6951eb 100644 --- a/backend/pikpak/api/types.go +++ b/backend/pikpak/api/types.go @@ -227,9 +227,10 @@ type Media struct { Duration int64 `json:"duration,omitempty"` BitRate int `json:"bit_rate,omitempty"` FrameRate int `json:"frame_rate,omitempty"` - VideoCodec string `json:"video_codec,omitempty"` - AudioCodec string `json:"audio_codec,omitempty"` - VideoType string `json:"video_type,omitempty"` + VideoCodec string `json:"video_codec,omitempty"` // "h264", "hevc" + AudioCodec string `json:"audio_codec,omitempty"` // "pcm_bluray", "aac" + VideoType string `json:"video_type,omitempty"` // "mpegts" + HdrType string `json:"hdr_type,omitempty"` } `json:"video,omitempty"` Link *Link `json:"link,omitempty"` NeedMoreQuota bool `json:"need_more_quota,omitempty"` diff --git a/backend/pikpak/pikpak.go b/backend/pikpak/pikpak.go index 616f62607..1f9790a1c 100644 --- a/backend/pikpak/pikpak.go +++ b/backend/pikpak/pikpak.go @@ -1411,6 +1411,16 @@ func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[str // ------------------------------------------------------------ +// parseFileID gets fid parameter from url query +func parseFileID(s string) string { + if u, err := url.Parse(s); err == nil { + if q, err := url.ParseQuery(u.RawQuery); err == nil { + return q.Get("fid") + } + } + return "" +} + // setMetaData sets the metadata from info func (o *Object) setMetaData(info *api.File) (err error) { if info.Kind == api.KindOfFolder { @@ -1432,10 +1442,18 @@ func (o *Object) setMetaData(info *api.File) (err error) { o.md5sum = info.Md5Checksum if info.Links.ApplicationOctetStream != nil { o.link = info.Links.ApplicationOctetStream - } - if len(info.Medias) > 0 && info.Medias[0].Link != nil { - fs.Debugf(o, "Using a media link") - o.link = info.Medias[0].Link + if fid := parseFileID(o.link.URL); fid != "" { + for mid, media := range info.Medias { + if media.Link == nil { + continue + } + if mfid := parseFileID(media.Link.URL); fid == mfid { + fs.Debugf(o, "Using a media link from Medias[%d]", mid) + o.link = media.Link + break + } + } + } } return nil }