Skip to content

Commit e8d4539

Browse files
authored
feat(quark_uc_tv): add streaming link api (#728)
1 parent 0c46199 commit e8d4539

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed

drivers/quark_uc_tv/driver.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,13 @@ func (d *QuarkUCTV) List(ctx context.Context, dir model.Obj, args model.ListArgs
126126
}
127127

128128
func (d *QuarkUCTV) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
129-
var fileLink FileLink
130-
_, err := d.request(ctx, "/file", "GET", func(req *resty.Request) {
131-
req.SetQueryParams(map[string]string{
132-
"method": "download",
133-
"group_by": "source",
134-
"fid": file.GetID(),
135-
"resolution": "low,normal,high,super,2k,4k",
136-
"support": "dolby_vision",
137-
})
138-
}, &fileLink)
139-
if err != nil {
140-
return nil, err
129+
f := file.(*Files)
130+
131+
if d.Addition.VideoLinkMethod == "streaming" && f.Category == 1 && f.Size > 0 {
132+
return d.getTranscodingLink(ctx, file)
141133
}
142134

143-
return &model.Link{
144-
URL: fileLink.Data.DownloadURL,
145-
Concurrency: 3,
146-
PartSize: 10 * utils.MB,
147-
}, nil
135+
return d.getDownloadLink(ctx, file)
148136
}
149137

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

drivers/quark_uc_tv/meta.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type Addition struct {
1414
DeviceID string `json:"device_id" required:"false" default:""`
1515
// 登陆所用的数据 无需手动填写
1616
QueryToken string `json:"query_token" required:"false" default:"" help:"don't edit'"`
17+
// 视频文件链接获取方式 download(可获取源视频) or streaming(获取转码后的视频)
18+
VideoLinkMethod string `json:"link_method" required:"true" type:"select" options:"download,streaming" default:"download"`
1719
}
1820

1921
type Conf struct {
@@ -38,8 +40,8 @@ func init() {
3840
api: "https://open-api-drive.quark.cn",
3941
clientID: "d3194e61504e493eb6222857bccfed94",
4042
signKey: "kw2dvtd7p4t3pjl2d9ed9yc8yej8kw2d",
41-
appVer: "1.5.6",
42-
channel: "CP",
43+
appVer: "1.8.2.2",
44+
channel: "GENERAL",
4345
codeApi: "http://api.extscreen.com/quarkdrive",
4446
},
4547
}
@@ -56,7 +58,7 @@ func init() {
5658
api: "https://open-api-drive.uc.cn",
5759
clientID: "5acf882d27b74502b7040b0c65519aa7",
5860
signKey: "l3srvtd7p42l0d0x1u8d7yc8ye9kki4d",
59-
appVer: "1.6.5",
61+
appVer: "1.7.2.2",
6062
channel: "UCTVOFFICIALWEB",
6163
codeApi: "http://api.extscreen.com/ucdrive",
6264
},

drivers/quark_uc_tv/types.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,32 @@ type FilesData struct {
9292
} `json:"data"`
9393
}
9494

95-
type FileLink struct {
95+
type StreamingFileLink struct {
96+
CommonRsp
97+
Data struct {
98+
DefaultResolution string `json:"default_resolution"`
99+
LastPlayTime int `json:"last_play_time"`
100+
VideoInfo []struct {
101+
Resolution string `json:"resolution"`
102+
Accessable int `json:"accessable"`
103+
TransStatus string `json:"trans_status"`
104+
Duration int `json:"duration,omitempty"`
105+
Size int64 `json:"size,omitempty"`
106+
Format string `json:"format,omitempty"`
107+
Width int `json:"width,omitempty"`
108+
Height int `json:"height,omitempty"`
109+
URL string `json:"url,omitempty"`
110+
Bitrate float64 `json:"bitrate,omitempty"`
111+
DolbyVision struct {
112+
Profile int `json:"profile"`
113+
Level int `json:"level"`
114+
} `json:"dolby_vision,omitempty"`
115+
} `json:"video_info"`
116+
AudioInfo []interface{} `json:"audio_info"`
117+
} `json:"data"`
118+
}
119+
120+
type DownloadFileLink struct {
96121
CommonRsp
97122
Data struct {
98123
Fid string `json:"fid"`

drivers/quark_uc_tv/util.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/sha256"
77
"encoding/hex"
88
"errors"
9+
"github.com/OpenListTeam/OpenList/v4/internal/model"
910
"net/http"
1011
"strconv"
1112
"time"
@@ -210,3 +211,47 @@ func (d *QuarkUCTV) generateReqSign(method string, pathname string, key string)
210211

211212
return timestamp, xPanTokenHex, reqIDHex
212213
}
214+
215+
func (d *QuarkUCTV) getTranscodingLink(ctx context.Context, file model.Obj) (*model.Link, error) {
216+
var fileLink StreamingFileLink
217+
_, err := d.request(ctx, "/file", "GET", func(req *resty.Request) {
218+
req.SetQueryParams(map[string]string{
219+
"method": "streaming",
220+
"group_by": "source",
221+
"fid": file.GetID(),
222+
"resolution": "low,normal,high,super,2k,4k",
223+
"support": "dolby_vision",
224+
})
225+
}, &fileLink)
226+
if err != nil {
227+
return nil, err
228+
}
229+
230+
return &model.Link{
231+
URL: fileLink.Data.VideoInfo[0].URL,
232+
Concurrency: 3,
233+
PartSize: 10 * utils.MB,
234+
}, nil
235+
}
236+
237+
func (d *QuarkUCTV) getDownloadLink(ctx context.Context, file model.Obj) (*model.Link, error) {
238+
var fileLink DownloadFileLink
239+
_, err := d.request(ctx, "/file", "GET", func(req *resty.Request) {
240+
req.SetQueryParams(map[string]string{
241+
"method": "download",
242+
"group_by": "source",
243+
"fid": file.GetID(),
244+
"resolution": "low,normal,high,super,2k,4k",
245+
"support": "dolby_vision",
246+
})
247+
}, &fileLink)
248+
if err != nil {
249+
return nil, err
250+
}
251+
252+
return &model.Link{
253+
URL: fileLink.Data.DownloadURL,
254+
Concurrency: 3,
255+
PartSize: 10 * utils.MB,
256+
}, nil
257+
}

0 commit comments

Comments
 (0)