Skip to content

Commit ab68fae

Browse files
anobodysanobodys
andauthored
fix(baidu_netdisk): add another video crack api (#8275)
Co-authored-by: anobodys <anobodys@gmail.com>
1 parent 2e21df0 commit ab68fae

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

drivers/baidu_netdisk/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func (d *BaiduNetdisk) List(ctx context.Context, dir model.Obj, args model.ListA
7878
func (d *BaiduNetdisk) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
7979
if d.DownloadAPI == "crack" {
8080
return d.linkCrack(file, args)
81+
} else if d.DownloadAPI == "crack_video" {
82+
return d.linkCrackVideo(file, args)
8183
}
8284
return d.linkOfficial(file, args)
8385
}

drivers/baidu_netdisk/meta.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Addition struct {
1010
driver.RootPath
1111
OrderBy string `json:"order_by" type:"select" options:"name,time,size" default:"name"`
1212
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
13-
DownloadAPI string `json:"download_api" type:"select" options:"official,crack" default:"official"`
13+
DownloadAPI string `json:"download_api" type:"select" options:"official,crack,crack_video" default:"official"`
1414
ClientID string `json:"client_id" required:"true" default:"iYCeC9g08h5vuP9UqvPHKKSVrKFXGa1v"`
1515
ClientSecret string `json:"client_secret" required:"true" default:"jXiFMOPVPCWlO2M5CwWQzffpNPaGTRBG"`
1616
CustomCrackUA string `json:"custom_crack_ua" required:"true" default:"netdisk"`
@@ -19,6 +19,7 @@ type Addition struct {
1919
UploadAPI string `json:"upload_api" default:"https://d.pcs.baidu.com"`
2020
CustomUploadPartSize int64 `json:"custom_upload_part_size" type:"number" default:"0" help:"0 for auto"`
2121
LowBandwithUploadMode bool `json:"low_bandwith_upload_mode" default:"false"`
22+
OnlyListVideoFile bool `json:"only_list_video_file" default:"false"`
2223
}
2324

2425
var config = driver.Config{

drivers/baidu_netdisk/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type TokenErrResp struct {
1717
type File struct {
1818
//TkbindId int `json:"tkbind_id"`
1919
//OwnerType int `json:"owner_type"`
20-
//Category int `json:"category"`
20+
Category int `json:"category"`
2121
//RealCategory string `json:"real_category"`
2222
FsId int64 `json:"fs_id"`
2323
//OperId int `json:"oper_id"`

drivers/baidu_netdisk/util.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ func (d *BaiduNetdisk) request(furl string, method string, callback base.ReqCall
7979
return retry.Unrecoverable(err2)
8080
}
8181
}
82+
83+
if 31023 == errno && d.DownloadAPI == "crack_video" {
84+
result = res.Body()
85+
return nil
86+
}
87+
8288
return fmt.Errorf("req: [%s] ,errno: %d, refer to https://pan.baidu.com/union/doc/", furl, errno)
8389
}
8490
result = res.Body()
@@ -131,7 +137,16 @@ func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
131137
if len(resp.List) == 0 {
132138
break
133139
}
134-
res = append(res, resp.List...)
140+
141+
if d.OnlyListVideoFile {
142+
for _, file := range resp.List {
143+
if file.Isdir == 1 || file.Category == 1 {
144+
res = append(res, file)
145+
}
146+
}
147+
} else {
148+
res = append(res, resp.List...)
149+
}
135150
}
136151
return res, nil
137152
}
@@ -187,6 +202,34 @@ func (d *BaiduNetdisk) linkCrack(file model.Obj, _ model.LinkArgs) (*model.Link,
187202
}, nil
188203
}
189204

205+
func (d *BaiduNetdisk) linkCrackVideo(file model.Obj, _ model.LinkArgs) (*model.Link, error) {
206+
param := map[string]string{
207+
"type": "VideoURL",
208+
"path": fmt.Sprintf("%s", file.GetPath()),
209+
"fs_id": file.GetID(),
210+
"devuid": "0%1",
211+
"clienttype": "1",
212+
"channel": "android_15_25010PN30C_bd-netdisk_1523a",
213+
"nom3u8": "1",
214+
"dlink": "1",
215+
"media": "1",
216+
"origin": "dlna",
217+
}
218+
resp, err := d.request("https://pan.baidu.com/api/mediainfo", http.MethodGet, func(req *resty.Request) {
219+
req.SetQueryParams(param)
220+
}, nil)
221+
if err != nil {
222+
return nil, err
223+
}
224+
225+
return &model.Link{
226+
URL: utils.Json.Get(resp, "info", "dlink").ToString(),
227+
Header: http.Header{
228+
"User-Agent": []string{d.CustomCrackUA},
229+
},
230+
}, nil
231+
}
232+
190233
func (d *BaiduNetdisk) manage(opera string, filelist any) ([]byte, error) {
191234
params := map[string]string{
192235
"method": "filemanager",

0 commit comments

Comments
 (0)