Skip to content

Commit 3d13d52

Browse files
authored
feat(quark): add transcoding link api (#470)
1 parent 103abc9 commit 3d13d52

File tree

4 files changed

+197
-34
lines changed

4 files changed

+197
-34
lines changed

drivers/quark_uc/driver.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,18 @@ func (d *QuarkOrUC) List(ctx context.Context, dir model.Obj, args model.ListArgs
4848
if err != nil {
4949
return nil, err
5050
}
51-
return utils.SliceConvert(files, func(src File) (model.Obj, error) {
52-
return fileToObj(src), nil
53-
})
51+
52+
return files, nil
5453
}
5554

5655
func (d *QuarkOrUC) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
57-
data := base.Json{
58-
"fids": []string{file.GetID()},
59-
}
60-
var resp DownResp
61-
ua := d.conf.ua
62-
_, err := d.request("/file/download", http.MethodPost, func(req *resty.Request) {
63-
req.SetHeader("User-Agent", ua).
64-
SetBody(data)
65-
}, &resp)
66-
if err != nil {
67-
return nil, err
56+
f := file.(*File)
57+
58+
if d.UseTransCodingAddress && d.config.Name == "Quark" && f.Category == 1 && f.Size > 0 {
59+
return d.getTranscodingLink(file)
6860
}
6961

70-
return &model.Link{
71-
URL: resp.Data[0].DownloadUrl,
72-
Header: http.Header{
73-
"Cookie": []string{d.Cookie},
74-
"Referer": []string{d.conf.referer},
75-
"User-Agent": []string{ua},
76-
},
77-
Concurrency: 3,
78-
PartSize: 10 * utils.MB,
79-
}, nil
62+
return d.getDownloadLink(file)
8063
}
8164

8265
func (d *QuarkOrUC) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {

drivers/quark_uc/meta.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88
type Addition struct {
99
Cookie string `json:"cookie" required:"true"`
1010
driver.RootID
11-
OrderBy string `json:"order_by" type:"select" options:"none,file_type,file_name,updated_at" default:"none"`
12-
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
11+
OrderBy string `json:"order_by" type:"select" options:"none,file_type,file_name,updated_at" default:"none"`
12+
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
13+
UseTransCodingAddress bool `json:"use_transcoding_address" help:"You can watch the transcoded video and support 302 redirection" required:"true" default:"false"`
14+
OnlyListVideoFile bool `json:"only_list_video_file" default:"false"`
1315
}
1416

1517
type Conf struct {
@@ -24,7 +26,7 @@ func init() {
2426
return &QuarkOrUC{
2527
config: driver.Config{
2628
Name: "Quark",
27-
OnlyLocal: true,
29+
OnlyLocal: false,
2830
DefaultRoot: "0",
2931
NoOverwriteUpload: true,
3032
},

drivers/quark_uc/types.go

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package quark
22

33
import (
4+
"github.com/OpenListTeam/OpenList/pkg/utils"
45
"time"
56

67
"github.com/OpenListTeam/OpenList/internal/model"
@@ -14,26 +15,28 @@ type Resp struct {
1415
//Timestamp int `json:"timestamp"`
1516
}
1617

18+
var _ model.Obj = (*File)(nil)
19+
1720
type File struct {
1821
Fid string `json:"fid"`
1922
FileName string `json:"file_name"`
2023
//PdirFid string `json:"pdir_fid"`
21-
//Category int `json:"category"`
24+
Category int `json:"category"`
2225
//FileType int `json:"file_type"`
2326
Size int64 `json:"size"`
2427
//FormatType string `json:"format_type"`
2528
//Status int `json:"status"`
2629
//Tags string `json:"tags,omitempty"`
27-
//LCreatedAt int64 `json:"l_created_at"`
30+
LCreatedAt int64 `json:"l_created_at"`
2831
LUpdatedAt int64 `json:"l_updated_at"`
2932
//NameSpace int `json:"name_space"`
3033
//IncludeItems int `json:"include_items,omitempty"`
3134
//RiskType int `json:"risk_type"`
3235
//BackupSign int `json:"backup_sign"`
3336
//Duration int `json:"duration"`
3437
//FileSource string `json:"file_source"`
35-
File bool `json:"file"`
36-
//CreatedAt int64 `json:"created_at"`
38+
File bool `json:"file"`
39+
CreatedAt int64 `json:"created_at"`
3740
UpdatedAt int64 `json:"updated_at"`
3841
//PrivateExtra struct {} `json:"_private_extra"`
3942
//ObjCategory string `json:"obj_category,omitempty"`
@@ -46,10 +49,43 @@ func fileToObj(f File) *model.Object {
4649
Name: f.FileName,
4750
Size: f.Size,
4851
Modified: time.UnixMilli(f.UpdatedAt),
52+
Ctime: time.UnixMilli(f.CreatedAt),
4953
IsFolder: !f.File,
5054
}
5155
}
5256

57+
func (f *File) GetSize() int64 {
58+
return f.Size
59+
}
60+
61+
func (f *File) GetName() string {
62+
return f.FileName
63+
}
64+
65+
func (f *File) ModTime() time.Time {
66+
return time.UnixMilli(f.UpdatedAt)
67+
}
68+
69+
func (f *File) CreateTime() time.Time {
70+
return time.UnixMilli(f.CreatedAt)
71+
}
72+
73+
func (f *File) IsDir() bool {
74+
return !f.File
75+
}
76+
77+
func (f *File) GetHash() utils.HashInfo {
78+
return utils.HashInfo{}
79+
}
80+
81+
func (f *File) GetID() string {
82+
return f.Fid
83+
}
84+
85+
func (f *File) GetPath() string {
86+
return ""
87+
}
88+
5389
type SortResp struct {
5490
Resp
5591
Data struct {
@@ -100,6 +136,82 @@ type DownResp struct {
100136
//} `json:"metadata"`
101137
}
102138

139+
type TranscodingResp struct {
140+
Resp
141+
Data struct {
142+
DefaultResolution string `json:"default_resolution"`
143+
OriginDefaultResolution string `json:"origin_default_resolution"`
144+
VideoList []struct {
145+
Resolution string `json:"resolution"`
146+
VideoInfo struct {
147+
Duration int `json:"duration"`
148+
Size int64 `json:"size"`
149+
Format string `json:"format"`
150+
Width int `json:"width"`
151+
Height int `json:"height"`
152+
Bitrate float64 `json:"bitrate"`
153+
Codec string `json:"codec"`
154+
Fps float64 `json:"fps"`
155+
Rotate int `json:"rotate"`
156+
Audio struct {
157+
Duration int `json:"duration"`
158+
Bitrate float64 `json:"bitrate"`
159+
Codec string `json:"codec"`
160+
Channels int `json:"channels"`
161+
} `json:"audio"`
162+
UpdateTime int `json:"update_time"`
163+
URL string `json:"url"`
164+
Resolution string `json:"resolution"`
165+
HlsType string `json:"hls_type"`
166+
Finish bool `json:"finish"`
167+
Resoultion string `json:"resoultion"`
168+
Success bool `json:"success"`
169+
} `json:"video_info,omitempty"`
170+
//Right string `json:"right"`
171+
//MemberRight string `json:"member_right"`
172+
//TransStatus string `json:"trans_status"`
173+
//Accessable bool `json:"accessable"`
174+
//SupportsFormat string `json:"supports_format"`
175+
//VideoFuncType string `json:"video_func_type,omitempty"`
176+
} `json:"video_list"`
177+
//AudioList []interface{} `json:"audio_list"`
178+
FileName string `json:"file_name"`
179+
NameSpace int `json:"name_space"`
180+
Size int64 `json:"size"`
181+
Thumbnail string `json:"thumbnail"`
182+
//LastPlayInfo struct {
183+
// Time int `json:"time"`
184+
//} `json:"last_play_info"`
185+
//SeekPreviewData struct {
186+
// TotalFrameCount int `json:"total_frame_count"`
187+
// TotalSpriteCount int `json:"total_sprite_count"`
188+
// FrameWidth int `json:"frame_width"`
189+
// FrameHeight int `json:"frame_height"`
190+
// SpriteRow int `json:"sprite_row"`
191+
// SpriteColumn int `json:"sprite_column"`
192+
// PreviewSpriteInfos []struct {
193+
// URL string `json:"url"`
194+
// FrameCount int `json:"frame_count"`
195+
// Times []int `json:"times"`
196+
// } `json:"preview_sprite_infos"`
197+
//} `json:"seek_preview_data"`
198+
//ObjKey string `json:"obj_key"`
199+
//Meta struct {
200+
// Duration int `json:"duration"`
201+
// Size int64 `json:"size"`
202+
// Format string `json:"format"`
203+
// Width int `json:"width"`
204+
// Height int `json:"height"`
205+
// Bitrate float64 `json:"bitrate"`
206+
// Codec string `json:"codec"`
207+
// Fps float64 `json:"fps"`
208+
// Rotate int `json:"rotate"`
209+
//} `json:"meta"`
210+
//PreloadLevel int `json:"preload_level"`
211+
//HasSeekPreviewData bool `json:"has_seek_preview_data"`
212+
} `json:"data"`
213+
}
214+
103215
type UpPreResp struct {
104216
Resp
105217
Data struct {

drivers/quark_uc/util.go

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,23 @@ func (d *QuarkOrUC) request(pathname string, method string, callback base.ReqCal
5050
d.Cookie = cookie.SetStr(d.Cookie, "__puus", __puus.Value)
5151
op.MustSaveDriverStorage(d)
5252
}
53+
54+
if d.UseTransCodingAddress && d.config.Name == "Quark" {
55+
__pus := cookie.GetCookie(res.Cookies(), "__pus")
56+
if __pus != nil {
57+
d.Cookie = cookie.SetStr(d.Cookie, "__pus", __pus.Value)
58+
op.MustSaveDriverStorage(d)
59+
}
60+
}
61+
5362
if e.Status >= 400 || e.Code != 0 {
5463
return nil, errors.New(e.Message)
5564
}
5665
return res.Body(), nil
5766
}
5867

59-
func (d *QuarkOrUC) GetFiles(parent string) ([]File, error) {
60-
files := make([]File, 0)
68+
func (d *QuarkOrUC) GetFiles(parent string) ([]model.Obj, error) {
69+
files := make([]model.Obj, 0)
6170
page := 1
6271
size := 100
6372
query := map[string]string{
@@ -77,15 +86,72 @@ func (d *QuarkOrUC) GetFiles(parent string) ([]File, error) {
7786
if err != nil {
7887
return nil, err
7988
}
80-
files = append(files, resp.Data.List...)
89+
for _, file := range resp.Data.List {
90+
if d.OnlyListVideoFile {
91+
// 开启后 只列出视频文件和文件夹
92+
if file.IsDir() || file.Category == 1 {
93+
files = append(files, &file)
94+
}
95+
} else {
96+
files = append(files, &file)
97+
}
98+
}
99+
81100
if page*size >= resp.Metadata.Total {
82101
break
83102
}
84103
page++
85104
}
105+
86106
return files, nil
87107
}
88108

109+
func (d *QuarkOrUC) getDownloadLink(file model.Obj) (*model.Link, error) {
110+
data := base.Json{
111+
"fids": []string{file.GetID()},
112+
}
113+
var resp DownResp
114+
ua := d.conf.ua
115+
_, err := d.request("/file/download", http.MethodPost, func(req *resty.Request) {
116+
req.SetHeader("User-Agent", ua).
117+
SetBody(data)
118+
}, &resp)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
return &model.Link{
124+
URL: resp.Data[0].DownloadUrl,
125+
Header: http.Header{
126+
"Cookie": []string{d.Cookie},
127+
"Referer": []string{d.conf.referer},
128+
"User-Agent": []string{ua},
129+
},
130+
Concurrency: 3,
131+
PartSize: 10 * utils.MB,
132+
}, nil
133+
}
134+
135+
func (d *QuarkOrUC) getTranscodingLink(file model.Obj) (*model.Link, error) {
136+
data := base.Json{
137+
"fid": file.GetID(),
138+
"resolutions": "low,normal,high,super,2k,4k",
139+
"supports": "fmp4_av,m3u8,dolby_vision",
140+
}
141+
var resp TranscodingResp
142+
ua := d.conf.ua
143+
144+
_, err := d.request("/file/v2/play/project", http.MethodPost, func(req *resty.Request) {
145+
req.SetHeader("User-Agent", ua).
146+
SetBody(data)
147+
}, &resp)
148+
if err != nil {
149+
return nil, err
150+
}
151+
152+
return &model.Link{URL: resp.Data.VideoList[0].VideoInfo.URL}, nil
153+
}
154+
89155
func (d *QuarkOrUC) upPre(file model.FileStreamer, parentId string) (UpPreResp, error) {
90156
now := time.Now()
91157
data := base.Json{

0 commit comments

Comments
 (0)