Skip to content

Commit b2b91a9

Browse files
authored
feat(doubao): add get_download_info API and download_api option (#8428)
1 parent f541489 commit b2b91a9

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

drivers/doubao/driver.go

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package doubao
33
import (
44
"context"
55
"errors"
6+
"net/http"
7+
"strconv"
8+
"strings"
9+
"time"
10+
611
"github.com/alist-org/alist/v3/drivers/base"
712
"github.com/alist-org/alist/v3/internal/driver"
813
"github.com/alist-org/alist/v3/internal/errs"
914
"github.com/alist-org/alist/v3/internal/model"
1015
"github.com/alist-org/alist/v3/pkg/utils"
1116
"github.com/go-resty/resty/v2"
1217
"github.com/google/uuid"
13-
"net/http"
14-
"strconv"
15-
"strings"
16-
"time"
1718
)
1819

1920
type Doubao struct {
@@ -97,33 +98,50 @@ func (d *Doubao) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
9798
var downloadUrl string
9899

99100
if u, ok := file.(*Object); ok {
100-
switch u.NodeType {
101-
case VideoType, AudioType:
102-
var r GetVideoFileUrlResp
103-
_, err := d.request("/samantha/media/get_play_info", http.MethodPost, func(req *resty.Request) {
101+
switch d.DownloadApi {
102+
case "get_download_info":
103+
var r GetDownloadInfoResp
104+
_, err := d.request("/samantha/aispace/get_download_info", http.MethodPost, func(req *resty.Request) {
104105
req.SetBody(base.Json{
105-
"key": u.Key,
106-
"node_id": file.GetID(),
106+
"requests": []base.Json{{"node_id": file.GetID()}},
107107
})
108108
}, &r)
109109
if err != nil {
110110
return nil, err
111111
}
112112

113-
downloadUrl = r.Data.OriginalMediaInfo.MainURL
114-
default:
115-
var r GetFileUrlResp
116-
_, err := d.request("/alice/message/get_file_url", http.MethodPost, func(req *resty.Request) {
117-
req.SetBody(base.Json{
118-
"uris": []string{u.Key},
119-
"type": FileNodeType[u.NodeType],
120-
})
121-
}, &r)
122-
if err != nil {
123-
return nil, err
113+
downloadUrl = r.Data.DownloadInfos[0].MainURL
114+
case "get_file_url":
115+
switch u.NodeType {
116+
case VideoType, AudioType:
117+
var r GetVideoFileUrlResp
118+
_, err := d.request("/samantha/media/get_play_info", http.MethodPost, func(req *resty.Request) {
119+
req.SetBody(base.Json{
120+
"key": u.Key,
121+
"node_id": file.GetID(),
122+
})
123+
}, &r)
124+
if err != nil {
125+
return nil, err
126+
}
127+
128+
downloadUrl = r.Data.OriginalMediaInfo.MainURL
129+
default:
130+
var r GetFileUrlResp
131+
_, err := d.request("/alice/message/get_file_url", http.MethodPost, func(req *resty.Request) {
132+
req.SetBody(base.Json{
133+
"uris": []string{u.Key},
134+
"type": FileNodeType[u.NodeType],
135+
})
136+
}, &r)
137+
if err != nil {
138+
return nil, err
139+
}
140+
141+
downloadUrl = r.Data.FileUrls[0].MainURL
124142
}
125-
126-
downloadUrl = r.Data.FileUrls[0].MainURL
143+
default:
144+
return nil, errs.NotImplement
127145
}
128146

129147
// 生成标准的Content-Disposition

drivers/doubao/meta.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Addition struct {
1212
// define other
1313
Cookie string `json:"cookie" type:"text"`
1414
UploadThread string `json:"upload_thread" default:"3"`
15+
DownloadApi string `json:"download_api" type:"select" options:"get_file_url,get_download_info" default:"get_file_url"`
1516
}
1617

1718
var config = driver.Config{

drivers/doubao/types.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package doubao
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/alist-org/alist/v3/internal/model"
76
"time"
7+
8+
"github.com/alist-org/alist/v3/internal/model"
89
)
910

1011
type BaseResp struct {
@@ -38,6 +39,17 @@ type File struct {
3839
UpdateTime int64 `json:"update_time"`
3940
}
4041

42+
type GetDownloadInfoResp struct {
43+
BaseResp
44+
Data struct {
45+
DownloadInfos []struct {
46+
NodeID string `json:"node_id"`
47+
MainURL string `json:"main_url"`
48+
BackupURL string `json:"backup_url"`
49+
} `json:"download_infos"`
50+
} `json:"data"`
51+
}
52+
4153
type GetFileUrlResp struct {
4254
BaseResp
4355
Data struct {

0 commit comments

Comments
 (0)