Skip to content

Commit 632a856

Browse files
committed
fix: 修复抖音视频下载302重定向问题
- 在 SubmitDownload 和 RetryTask 方法中添加 aria2 重定向支持 - 配置最大重试次数为5次,支持多连接下载 - 设置文件分块下载提升下载稳定性 - 解决抖音视频 URL 重定向导致下载 HTML 而非视频的问题
1 parent f8f935b commit 632a856

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

backend/service/download_service.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import (
1919
)
2020

2121
type DownloadService struct {
22-
db *gorm.DB
23-
downloader downloader.Downloader
22+
db *gorm.DB
23+
downloader downloader.Downloader
2424
configService *SystemConfigService
2525
}
2626

2727
func NewDownloadService(db *gorm.DB, dl downloader.Downloader) *DownloadService {
2828
return &DownloadService{
29-
db: db,
30-
downloader: dl,
29+
db: db,
30+
downloader: dl,
3131
configService: NewSystemConfigService(db),
3232
}
3333
}
@@ -108,6 +108,12 @@ func (s *DownloadService) SubmitDownload(ctx context.Context, req types.Download
108108
// BT/Magnet 下载完成后不做种
109109
options["seed-time"] = 0
110110

111+
// 支持 HTTP 重定向(如抖音的 302 重定向)
112+
options["max-tries"] = 5
113+
options["max-connection-per-server"] = 5
114+
options["split"] = 5
115+
options["min-split-size"] = "1M"
116+
111117
if downloadPath != "" {
112118
if strings.HasSuffix(downloadPath, "/") {
113119
// 只有目录,让 aria2 自动命名
@@ -189,12 +195,12 @@ func (s *DownloadService) ListTasks(ctx context.Context) ([]*model.DownloadTask,
189195

190196
// TaskQueryParams 任务查询参数
191197
type TaskQueryParams struct {
192-
Page int
193-
PageSize int
194-
Statuses []string
195-
PluginName string
196-
Category string
197-
Filename string
198+
Page int
199+
PageSize int
200+
Statuses []string
201+
PluginName string
202+
Category string
203+
Filename string
198204
}
199205

200206
// TaskQueryResult 任务查询结果
@@ -228,7 +234,6 @@ func (s *DownloadService) ListTasksWithPagination(ctx context.Context, params Ta
228234
query = query.Where("filename ILIKE ?", "%"+params.Filename+"%")
229235
}
230236

231-
232237
// 计算总数
233238
var total int64
234239
if err := query.Count(&total).Error; err != nil {
@@ -270,6 +275,12 @@ func (s *DownloadService) RetryTask(ctx context.Context, id uint) error {
270275
options["out"] = task.Filename
271276
}
272277

278+
// 添加重定向和防盗链支持
279+
options["max-tries"] = 5
280+
options["max-connection-per-server"] = 5
281+
options["split"] = 5
282+
options["min-split-size"] = "1M"
283+
273284
gid, err := s.downloader.AddURI(ctx, []string{task.URL}, options)
274285
if err != nil {
275286
return fmt.Errorf("failed to retry download: %w", err)
@@ -532,4 +543,4 @@ func (s *DownloadService) GetTaskFiles(ctx context.Context, task *model.Download
532543
}
533544

534545
return files
535-
}
546+
}

0 commit comments

Comments
 (0)