From 0d012f85cb101165b37689f3d0eba7fa7ee7e579 Mon Sep 17 00:00:00 2001 From: foxxorcat Date: Thu, 15 Sep 2022 22:50:27 +0800 Subject: [PATCH] feat: Add thunderExpert priority video url switch --- drivers/thunder/driver.go | 11 +++++++++++ drivers/thunder/meta.go | 3 +++ drivers/thunder/types.go | 39 +++++++++++++++++++++++---------------- drivers/thunder/util.go | 1 + 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/thunder/driver.go b/drivers/thunder/driver.go index 89158f84909..f75eb991899 100644 --- a/drivers/thunder/driver.go +++ b/drivers/thunder/driver.go @@ -146,6 +146,7 @@ func (x *ThunderExpert) Init(ctx context.Context, storage model.Storage) (err er PackageName: x.PackageName, UserAgent: x.UserAgent, DownloadUserAgent: x.DownloadUserAgent, + UseVideoUrl: x.UseVideoUrl, }, } @@ -209,6 +210,7 @@ func (x *ThunderExpert) Init(ctx context.Context, storage model.Storage) (err er } x.XunLeiCommon.UserAgent = x.UserAgent x.XunLeiCommon.DownloadUserAgent = x.DownloadUserAgent + x.XunLeiCommon.UseVideoUrl = x.UseVideoUrl } return nil } @@ -252,6 +254,15 @@ func (xc *XunLeiCommon) Link(ctx context.Context, file model.Obj, args model.Lin }, } + if xc.UseVideoUrl { + for _, media := range lFile.Medias { + if media.Link.URL != "" { + link.URL = media.Link.URL + break + } + } + } + /* strs := regexp.MustCompile(`e=([0-9]*)`).FindStringSubmatch(lFile.WebContentLink) if len(strs) == 2 { diff --git a/drivers/thunder/meta.go b/drivers/thunder/meta.go index 1561e318187..b24bb8b3237 100644 --- a/drivers/thunder/meta.go +++ b/drivers/thunder/meta.go @@ -41,6 +41,9 @@ type ExpertAddition struct { //不影响登录,影响下载速度 UserAgent string `json:"user_agent" required:"true" default:"ANDROID-com.xunlei.downloadprovider/7.51.0.8196 netWorkType/4G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/220200 Oauth2Client/0.9 (Linux 4_14_186-perf-gdcf98eab238b) (JAVA 0)"` DownloadUserAgent string `json:"download_user_agent" required:"true" default:"Dalvik/2.1.0 (Linux; U; Android 12; M2004J7AC Build/SP1A.210812.016)"` + + //优先使用视频链接代替下载链接 + UseVideoUrl bool `json:"use_video_url"` } // 登录特征,用于判断是否重新登录 diff --git a/drivers/thunder/types.go b/drivers/thunder/types.go index b55afba1eb2..0c60dc5642b 100644 --- a/drivers/thunder/types.go +++ b/drivers/thunder/types.go @@ -77,6 +77,13 @@ type FileList struct { VersionOutdated bool `json:"version_outdated"` } +type Link struct { + URL string `json:"url"` + Token string `json:"token"` + Expire time.Time `json:"expire"` + Type string `json:"type"` +} + type Files struct { Kind string `json:"kind"` ID string `json:"id"` @@ -95,26 +102,26 @@ type Files struct { ThumbnailLink string `json:"thumbnail_link"` //Md5Checksum string `json:"md5_checksum"` //Hash string `json:"hash"` - //Links struct{} `json:"links"` - Phase string `json:"phase"` + Links map[string]Link `json:"links"` + Phase string `json:"phase"` Audit struct { Status string `json:"status"` Message string `json:"message"` Title string `json:"title"` } `json:"audit"` - /* Medias []struct { - Category string `json:"category"` - IconLink string `json:"icon_link"` - IsDefault bool `json:"is_default"` - IsOrigin bool `json:"is_origin"` - IsVisible bool `json:"is_visible"` - //Link interface{} `json:"link"` - MediaID string `json:"media_id"` - MediaName string `json:"media_name"` - NeedMoreQuota bool `json:"need_more_quota"` - Priority int `json:"priority"` - RedirectLink string `json:"redirect_link"` - ResolutionName string `json:"resolution_name"` + Medias []struct { + Category string `json:"category"` + IconLink string `json:"icon_link"` + IsDefault bool `json:"is_default"` + IsOrigin bool `json:"is_origin"` + IsVisible bool `json:"is_visible"` + Link Link `json:"link"` + MediaID string `json:"media_id"` + MediaName string `json:"media_name"` + NeedMoreQuota bool `json:"need_more_quota"` + Priority int `json:"priority"` + RedirectLink string `json:"redirect_link"` + ResolutionName string `json:"resolution_name"` Video struct { AudioCodec string `json:"audio_codec"` BitRate int `json:"bit_rate"` @@ -126,7 +133,7 @@ type Files struct { Width int `json:"width"` } `json:"video"` VipTypes []string `json:"vip_types"` - } `json:"medias"` */ + } `json:"medias"` Trashed bool `json:"trashed"` DeleteTime string `json:"delete_time"` OriginalURL string `json:"original_url"` diff --git a/drivers/thunder/util.go b/drivers/thunder/util.go index 88d1a1871d6..3c586b992fb 100644 --- a/drivers/thunder/util.go +++ b/drivers/thunder/util.go @@ -52,6 +52,7 @@ type Common struct { PackageName string UserAgent string DownloadUserAgent string + UseVideoUrl bool } func (c *Common) SetCaptchaToken(captchaToken string) {