Skip to content

Commit 60009b4

Browse files
committed
feat(quark_uc): make ranged download concurrency and part size configurable
1 parent aead76e commit 60009b4

3 files changed

Lines changed: 38 additions & 14 deletions

File tree

drivers/quark_uc/driver.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ func (d *QuarkOrUC) GetAddition() driver.Additional {
3838

3939
func (d *QuarkOrUC) Init(ctx context.Context) error {
4040
_, err := d.request("/config", http.MethodGet, nil, nil)
41-
if err == nil && d.AdditionVersion != 2 {
42-
d.AdditionVersion = 2
43-
if !d.UseTransCodingAddress && len(d.DownProxyUrl) == 0 {
44-
d.WebProxy = true
45-
d.WebdavPolicy = "native_proxy"
41+
if err == nil && d.AdditionVersion != 3 {
42+
if d.AdditionVersion < 2 {
43+
if !d.UseTransCodingAddress && len(d.DownProxyUrl) == 0 {
44+
d.WebProxy = true
45+
d.WebdavPolicy = "native_proxy"
46+
}
4647
}
48+
// 老存储没有这两个字段,补成原来的固定值,保持行为不变
49+
if d.DownConcurrency <= 0 {
50+
d.DownConcurrency = 3
51+
}
52+
if d.DownPartSize <= 0 {
53+
d.DownPartSize = 10
54+
}
55+
d.AdditionVersion = 3
4756
op.MustSaveDriverStorage(d)
4857
}
4958
return err

drivers/quark_uc/meta.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type Addition struct {
1212
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
1313
UseTransCodingAddress bool `json:"use_transcoding_address" help:"You can watch the transcoded video and support 302 redirection" required:"true" default:"false"`
1414
OnlyListVideoFile bool `json:"only_list_video_file" default:"false"`
15+
DownConcurrency int `json:"down_concurrency" type:"number" default:"3" help:"concurrency of ranged download, 0 to disable ranged download"`
16+
DownPartSize int `json:"down_part_size" type:"number" default:"10" help:"part size (MB) of ranged download"`
1517
AdditionVersion int
1618
}
1719

drivers/quark_uc/util.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,29 @@ func (d *QuarkOrUC) getDownloadLink(file model.Obj) (*model.Link, error) {
119119
return nil, err
120120
}
121121

122-
return &model.Link{
122+
link := &model.Link{
123123
URL: resp.Data[0].DownloadUrl,
124124
Header: http.Header{
125125
"Cookie": []string{d.Cookie},
126126
"Referer": []string{d.conf.referer},
127127
"User-Agent": []string{ua},
128128
},
129-
Concurrency: 3,
130-
PartSize: 10 * utils.MB,
131-
}, nil
129+
}
130+
d.applyLinkLimit(link)
131+
return link, nil
132+
}
133+
134+
// applyLinkLimit 按存储配置设置分片下载参数,DownConcurrency 为 0 时不强制分片下载
135+
func (d *QuarkOrUC) applyLinkLimit(link *model.Link) {
136+
if d.DownConcurrency <= 0 {
137+
return
138+
}
139+
partSize := d.DownPartSize
140+
if partSize <= 0 {
141+
partSize = 10
142+
}
143+
link.Concurrency = d.DownConcurrency
144+
link.PartSize = partSize * utils.MB
132145
}
133146

134147
func (d *QuarkOrUC) getTranscodingLink(file model.Obj) (*model.Link, error) {
@@ -150,11 +163,11 @@ func (d *QuarkOrUC) getTranscodingLink(file model.Obj) (*model.Link, error) {
150163

151164
for _, info := range resp.Data.VideoList {
152165
if info.VideoInfo.URL != "" {
153-
return &model.Link{
154-
URL: info.VideoInfo.URL,
155-
Concurrency: 3,
156-
PartSize: 10 * utils.MB,
157-
}, nil
166+
link := &model.Link{
167+
URL: info.VideoInfo.URL,
168+
}
169+
d.applyLinkLimit(link)
170+
return link, nil
158171
}
159172
}
160173

0 commit comments

Comments
 (0)