Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ const (
ApiFsRbRevert = ApiBaseURL + "/open/rb/revert"
ApiFsRbDelete = ApiBaseURL + "/open/rb/del"

ApiAddOffline = ApiBaseURL + "/open/offline/add_task_urls"
ApiDeleteOffline = ApiBaseURL + "/open/offline/del_task"
ApiOfflineList = ApiBaseURL + "/open/offline/get_task_list"
ApiAddOffline = ApiBaseURL + "/open/offline/add_task_urls"
ApiDeleteOffline = ApiBaseURL + "/open/offline/del_task"
ApiOfflineList = ApiBaseURL + "/open/offline/get_task_list"
ApiOfflineQuotaInfo = ApiBaseURL + "/open/offline/get_quota_info"
ApiOfflineTorrent = ApiBaseURL + "/open/offline/torrent"
ApiAddOfflineBT = ApiBaseURL + "/open/offline/add_task_bt"
ApiClearOffline = ApiBaseURL + "/open/offline/clear_task"
)

// Video API
const (
ApiVideoPlay = ApiBaseURL + "/open/video/play"
ApiVideoHistory = ApiBaseURL + "/open/video/history"
ApiVideoSubtitle = ApiBaseURL + "/open/video/subtitle"
ApiVideoPush = ApiBaseURL + "/open/video/video_push"
)

// VIP API
const (
ApiVipQrURL = ApiBaseURL + "/open/vip/qr_url"
)
9 changes: 5 additions & 4 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ func (c *Client) DownURL(ctx context.Context, pickCode string, ua string) (DownU
}

type UpdateFileReq struct {
FileID string `json:"file_id"` // 需要更改名字的文件(夹)ID
FileNma string `json:"file_name"` // 新的文件(夹)名字(文件夹名称限制255字节)
Star string `json:"star"` // 是否星标;1:星标;0;取消星标
FileID string `json:"file_id"` // 需要更改名字的文件(夹)ID
FileName string `json:"file_name"` // 新的文件(夹)名字(文件夹名称限制255字节)
Star string `json:"star"` // 是否星标;1:星标;0;取消星标
}

type UpdateFileResp struct {
Expand All @@ -306,7 +306,7 @@ func (c *Client) UpdateFile(ctx context.Context, req *UpdateFileReq) (*UpdateFil
var resp UpdateFileResp
_, err := c.AuthRequest(ctx, ApiFsUpdate, http.MethodPost, &resp, ReqWithForm(Form{
"file_id": req.FileID,
"file_name": req.FileNma,
"file_name": req.FileName,
"star": req.Star,
}))
if err != nil {
Expand Down Expand Up @@ -376,6 +376,7 @@ func (c *Client) RbList(ctx context.Context, limit, offset int64) (*RbListResp,
if err != nil {
return nil, err
}
resp.Files = make(map[string]RbListResp_FileInfo)
for key, value := range rawFiles {
if SliceContains([]string{"offset", "limit", "count", "rb_pass"}, key) {
continue
Expand Down
89 changes: 89 additions & 0 deletions offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,92 @@ func (c *Client) OfflineTaskList(ctx context.Context, page int64) (*OfflineTaskL
}))
return &resp, err
}

type OfflineQuotaExpireInfo struct {
Surplus int `json:"surplus"`
ExpireTime int64 `json:"expire_time"`
}

type OfflineQuotaPackage struct {
Surplus int `json:"surplus"`
Used int `json:"used"`
Count int `json:"count"`
Name string `json:"name"`
ExpireInfo []OfflineQuotaExpireInfo `json:"expire_info"`
}

type OfflineQuotaInfoResp struct {
Package []OfflineQuotaPackage `json:"package"`
Count int `json:"count"`
Surplus int `json:"surplus"`
Used int `json:"used"`
}

// OfflineQuotaInfo https://www.yuque.com/115yun/open/gif2n3smh54kyg0p
func (c *Client) OfflineQuotaInfo(ctx context.Context) (*OfflineQuotaInfoResp, error) {
var resp OfflineQuotaInfoResp
_, err := c.AuthRequest(ctx, ApiOfflineQuotaInfo, http.MethodGet, &resp)
if err != nil {
return nil, err
}
return &resp, err
}

type TorrentFileItem struct {
Size int64 `json:"size"`
Path string `json:"path"`
Wanted int `json:"wanted"`
}

type TorrentInfoResp struct {
FileSize int64 `json:"file_size"`
TorrentName string `json:"torrent_name"`
FileCount int `json:"file_count"`
InfoHash string `json:"info_hash"`
TorrentFileList []TorrentFileItem `json:"torrent_filelist"`
}

// ParseTorrent https://www.yuque.com/115yun/open/evez3u50cemoict1
func (c *Client) ParseTorrent(ctx context.Context, torrentSha1, pickCode string) (*TorrentInfoResp, error) {
var resp TorrentInfoResp
_, err := c.AuthRequest(ctx, ApiOfflineTorrent, http.MethodPost, &resp, ReqWithForm(Form{
"torrent_sha1": torrentSha1,
"pick_code": pickCode,
}))
if err != nil {
return nil, err
}
return &resp, err
}

type AddOfflineTaskBTReq struct {
InfoHash string `json:"info_hash"`
Wanted string `json:"wanted"`
SavePath string `json:"save_path"`
TorrentSha1 string `json:"torrent_sha1"`
PickCode string `json:"pick_code"`
WpPathID string `json:"wp_path_id"`
}

// AddOfflineTaskBT https://www.yuque.com/115yun/open/svfe4unlhayvluly
func (c *Client) AddOfflineTaskBT(ctx context.Context, req *AddOfflineTaskBTReq) error {
var resp any
_, err := c.AuthRequest(ctx, ApiAddOfflineBT, http.MethodPost, &resp, ReqWithForm(Form{
"info_hash": req.InfoHash,
"wanted": req.Wanted,
"save_path": req.SavePath,
"torrent_sha1": req.TorrentSha1,
"pick_code": req.PickCode,
"wp_path_id": req.WpPathID,
}))
return err
}

// ClearOfflineTask https://www.yuque.com/115yun/open/uu5i4urb5ylqwfy4
func (c *Client) ClearOfflineTask(ctx context.Context, flag int) error {
var resp any
_, err := c.AuthRequest(ctx, ApiClearOffline, http.MethodPost, &resp, ReqWithForm(Form{
"flag": strconv.Itoa(flag),
}))
return err
}
123 changes: 123 additions & 0 deletions video.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package sdk

import (
"context"
"net/http"
"strconv"
)

type VideoPlayURL struct {
URL string `json:"url"`
Definition int `json:"definition"`
Desc string `json:"desc"`
}

type VideoPlayResp struct {
FileID string `json:"file_id"`
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
Duration int64 `json:"duration"`
Width int `json:"width"`
Height int `json:"height"`
VideoURL []VideoPlayURL `json:"video_url"`
}

// VideoPlay https://www.yuque.com/115yun/open/hqglxv3cedi3p9dz
func (c *Client) VideoPlay(ctx context.Context, pickCode string) (*VideoPlayResp, error) {
var resp VideoPlayResp
_, err := c.AuthRequest(ctx, ApiVideoPlay, http.MethodGet, &resp, ReqWithQuery(Form{
"pick_code": pickCode,
}))
if err != nil {
return nil, err
}
return &resp, err
}

type VideoHistoryResp struct {
AddTime int64 `json:"add_time"`
FileID string `json:"file_id"`
FileName string `json:"file_name"`
Hash string `json:"hash"`
PickCode string `json:"pick_code"`
Time string `json:"time"`
}

// GetVideoHistory https://www.yuque.com/115yun/open/gssqdrsq6vfqigag
func (c *Client) GetVideoHistory(ctx context.Context, pickCode string) (*VideoHistoryResp, error) {
var resp VideoHistoryResp
_, err := c.AuthRequest(ctx, ApiVideoHistory, http.MethodGet, &resp, ReqWithQuery(Form{
"pick_code": pickCode,
}))
if err != nil {
return nil, err
}
return &resp, err
}

type SetVideoHistoryReq struct {
PickCode string `json:"pick_code"`
Time int `json:"time"`
WatchEnd int `json:"watch_end"`
}

// SetVideoHistory https://www.yuque.com/115yun/open/bshagbxv1gzqglg4
func (c *Client) SetVideoHistory(ctx context.Context, req *SetVideoHistoryReq) error {
var resp any
_, err := c.AuthRequest(ctx, ApiVideoHistory, http.MethodPost, &resp, ReqWithForm(Form{
"pick_code": req.PickCode,
"time": strconv.Itoa(req.Time),
"watch_end": strconv.Itoa(req.WatchEnd),
}))
return err
}

type SubtitleItem struct {
SID string `json:"sid"`
Language string `json:"language"`
Title string `json:"title"`
URL string `json:"url"`
Type string `json:"type"`
Sha1 string `json:"sha1"`
FileID string `json:"file_id"`
FileName string `json:"file_name"`
PickCode string `json:"pick_code"`
CaptionMapID string `json:"caption_map_id"`
IsCaptionMap int `json:"is_caption_map"`
SyncTime int `json:"sync_time"`
}

type SubtitleAutoload struct {
SID string `json:"sid"`
Language string `json:"language"`
Title string `json:"title"`
URL string `json:"url"`
Type string `json:"type"`
}

type VideoSubtitleResp struct {
Autoload *SubtitleAutoload `json:"autoload"`
List []SubtitleItem `json:"list"`
}

// VideoSubtitle https://www.yuque.com/115yun/open/nx076h3glapoyh7u
func (c *Client) VideoSubtitle(ctx context.Context, pickCode string) (*VideoSubtitleResp, error) {
var resp VideoSubtitleResp
_, err := c.AuthRequest(ctx, ApiVideoSubtitle, http.MethodGet, &resp, ReqWithQuery(Form{
"pick_code": pickCode,
}))
if err != nil {
return nil, err
}
return &resp, err
}

// VideoPush https://www.yuque.com/115yun/open/nxt8r1qcktmg3oan
func (c *Client) VideoPush(ctx context.Context, pickCode, op string) error {
var resp any
_, err := c.AuthRequest(ctx, ApiVideoPush, http.MethodPost, &resp, ReqWithForm(Form{
"pick_code": pickCode,
"op": op,
}))
return err
}
30 changes: 30 additions & 0 deletions vip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sdk

import (
"context"
"net/http"
)

type VipQrURLReq struct {
DefaultProductID string `json:"default_product_id"`
OpenDevice string `json:"open_device"`
HideTitle string `json:"hide_title"`
}

type VipQrURLResp struct {
QrcodeURL string `json:"qrcode_url"`
}

// VipQrURL https://www.yuque.com/115yun/open/cguk6qshgapwg4qn#oByvI
func (c *Client) VipQrURL(ctx context.Context, req *VipQrURLReq) (*VipQrURLResp, error) {
var resp VipQrURLResp
_, err := c.AuthRequest(ctx, ApiVipQrURL, http.MethodGet, &resp, ReqWithQuery(Form{
"default_product_id": req.DefaultProductID,
"open_device": req.OpenDevice,
"hide_title": req.HideTitle,
}))
if err != nil {
return nil, err
}
return &resp, err
}