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
This commit is contained in:
parent
38a0539096
commit
6859c04772
2 changed files with 26 additions and 7 deletions
|
@ -227,9 +227,10 @@ type Media struct {
|
||||||
Duration int64 `json:"duration,omitempty"`
|
Duration int64 `json:"duration,omitempty"`
|
||||||
BitRate int `json:"bit_rate,omitempty"`
|
BitRate int `json:"bit_rate,omitempty"`
|
||||||
FrameRate int `json:"frame_rate,omitempty"`
|
FrameRate int `json:"frame_rate,omitempty"`
|
||||||
VideoCodec string `json:"video_codec,omitempty"`
|
VideoCodec string `json:"video_codec,omitempty"` // "h264", "hevc"
|
||||||
AudioCodec string `json:"audio_codec,omitempty"`
|
AudioCodec string `json:"audio_codec,omitempty"` // "pcm_bluray", "aac"
|
||||||
VideoType string `json:"video_type,omitempty"`
|
VideoType string `json:"video_type,omitempty"` // "mpegts"
|
||||||
|
HdrType string `json:"hdr_type,omitempty"`
|
||||||
} `json:"video,omitempty"`
|
} `json:"video,omitempty"`
|
||||||
Link *Link `json:"link,omitempty"`
|
Link *Link `json:"link,omitempty"`
|
||||||
NeedMoreQuota bool `json:"need_more_quota,omitempty"`
|
NeedMoreQuota bool `json:"need_more_quota,omitempty"`
|
||||||
|
|
|
@ -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
|
// setMetaData sets the metadata from info
|
||||||
func (o *Object) setMetaData(info *api.File) (err error) {
|
func (o *Object) setMetaData(info *api.File) (err error) {
|
||||||
if info.Kind == api.KindOfFolder {
|
if info.Kind == api.KindOfFolder {
|
||||||
|
@ -1432,10 +1442,18 @@ func (o *Object) setMetaData(info *api.File) (err error) {
|
||||||
o.md5sum = info.Md5Checksum
|
o.md5sum = info.Md5Checksum
|
||||||
if info.Links.ApplicationOctetStream != nil {
|
if info.Links.ApplicationOctetStream != nil {
|
||||||
o.link = info.Links.ApplicationOctetStream
|
o.link = info.Links.ApplicationOctetStream
|
||||||
}
|
if fid := parseFileID(o.link.URL); fid != "" {
|
||||||
if len(info.Medias) > 0 && info.Medias[0].Link != nil {
|
for mid, media := range info.Medias {
|
||||||
fs.Debugf(o, "Using a media link")
|
if media.Link == nil {
|
||||||
o.link = info.Medias[0].Link
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue