diff --git a/alidrive/req_bean.go b/alidrive/req_bean.go index 570ec901..52f37a25 100644 --- a/alidrive/req_bean.go +++ b/alidrive/req_bean.go @@ -72,4 +72,12 @@ type VideoPreviewUrlReq struct { DriveId string `json:"drive_id"` FileId string `json:"file_id"` ExpireSec int `json:"expire_sec"` -} \ No newline at end of file +} + +// VideoPreviewPlayInfoReq video preview play info req +type VideoPreviewPlayInfoReq struct { + Category string `json:"category"` + DriveId string `json:"drive_id"` + FileId string `json:"file_id"` + TemplateId string `json:"template_id"` +} diff --git a/alidrive/request.go b/alidrive/request.go index d14e622e..ea980869 100644 --- a/alidrive/request.go +++ b/alidrive/request.go @@ -5,7 +5,7 @@ import ( "github.com/Xhofe/alist/conf" ) -// get file +// GetFile get file func GetFile(fileId string, drive *conf.Drive) (*File, error) { url := conf.Conf.AliDrive.ApiUrl + "/file/get" req := GetReq{ @@ -21,7 +21,7 @@ func GetFile(fileId string, drive *conf.Drive) (*File, error) { return &resp, nil } -// get download_url +// GetDownLoadUrl get download_url func GetDownLoadUrl(fileId string, drive *conf.Drive) (*DownloadResp, error) { url := conf.Conf.AliDrive.ApiUrl + "/file/get_download_url" req := DownloadReq{ @@ -36,7 +36,7 @@ func GetDownLoadUrl(fileId string, drive *conf.Drive) (*DownloadResp, error) { return &resp, nil } -// search by keyword +// Search search by keyword func Search(key string, limit int, marker string, drive *conf.Drive) (*Files, error) { url := conf.Conf.AliDrive.ApiUrl + "/file/search" req := SearchReq{ @@ -56,12 +56,12 @@ func Search(key string, limit int, marker string, drive *conf.Drive) (*Files, er return &resp, nil } -// get root folder +// GetRoot get root folder func GetRoot(limit int, marker string, orderBy string, orderDirection string, drive *conf.Drive) (*Files, error) { return GetList(drive.RootFolder, limit, marker, orderBy, orderDirection, drive) } -// get folder list by file_id +// GetList get folder list by file_id func GetList(parent string, limit int, marker string, orderBy string, orderDirection string, drive *conf.Drive) (*Files, error) { url := conf.Conf.AliDrive.ApiUrl + "/file/list" req := ListReq{ @@ -83,7 +83,7 @@ func GetList(parent string, limit int, marker string, orderBy string, orderDirec return &resp, nil } -// get user info +// GetUserInfo get user info func GetUserInfo(drive *conf.Drive) (*UserInfo, error) { url := conf.Conf.AliDrive.ApiUrl + "/user/get" var resp UserInfo @@ -93,7 +93,7 @@ func GetUserInfo(drive *conf.Drive) (*UserInfo, error) { return &resp, nil } -// get office preview url and token +// GetOfficePreviewUrl get office preview url and token func GetOfficePreviewUrl(fileId string, drive *conf.Drive) (*OfficePreviewUrlResp, error) { url := conf.Conf.AliDrive.ApiUrl + "/file/get_office_preview_url" req := OfficePreviewUrlReq{ @@ -108,7 +108,7 @@ func GetOfficePreviewUrl(fileId string, drive *conf.Drive) (*OfficePreviewUrlRes return &resp, nil } -// get video preview url +// GetVideoPreviewUrl get video preview url func GetVideoPreviewUrl(fileId string, drive *conf.Drive) (*VideoPreviewUrlResp, error) { url := conf.Conf.AliDrive.ApiUrl + "/databox/get_video_play_info" req := VideoPreviewUrlReq{ @@ -122,3 +122,18 @@ func GetVideoPreviewUrl(fileId string, drive *conf.Drive) (*VideoPreviewUrlResp, } return &resp, nil } + +// GetVideoPreviewPlayInfo get video preview url +func GetVideoPreviewPlayInfo(fileId string, drive *conf.Drive) (*VideoPreviewPlayInfoResp, error) { + url := conf.Conf.AliDrive.ApiUrl + "/file/get_video_preview_play_info" + req := VideoPreviewPlayInfoReq{ + DriveId: drive.DefaultDriveId, + FileId: fileId, + Category: "live_transcoding", + } + var resp VideoPreviewPlayInfoResp + if err := BodyToJson(url, req, &resp, drive); err != nil { + return nil, err + } + return &resp, nil +} diff --git a/alidrive/resp_bean.go b/alidrive/resp_bean.go index 1ff102ef..308dbecb 100644 --- a/alidrive/resp_bean.go +++ b/alidrive/resp_bean.go @@ -4,7 +4,7 @@ import ( "time" ) -// response bean methods +// RespHandle response bean methods type RespHandle interface { IsAvailable() bool // check available GetCode() string // get err code @@ -12,7 +12,7 @@ type RespHandle interface { SetCode(code string) // set err code } -// common response bean +// RespError common response bean type RespError struct { Code string `json:"code"` Message string `json:"message"` @@ -34,7 +34,7 @@ func (resp *RespError) SetCode(code string) { resp.Code = code } -// user_info response bean +// UserInfo user_info response bean type UserInfo struct { RespError DomainId string `json:"domain_id"` @@ -53,7 +53,7 @@ type UserInfo struct { UserData map[string]interface{} `json:"user_data"` } -// folder files response bean +// Files folder files response bean type Files struct { RespError Items []File `json:"items"` @@ -62,7 +62,7 @@ type Files struct { Paths []Path `json:"paths"` } -// path bean +// Path path bean type Path struct { Name string `json:"name"` FileId string `json:"file_id"` @@ -75,8 +75,9 @@ type Path struct { "size":1141068377, "content_type":"video/mp4" } - */ -// file response bean +*/ + +// File file response bean type File struct { RespError DriveId string `json:"drive_id"` @@ -120,13 +121,13 @@ type DownloadResp struct { //} `json:"rate_limit"`//rate limit } -// token_login response bean +// TokenLoginResp token_login response bean type TokenLoginResp struct { RespError Goto string `json:"goto"` } -// token response bean +// TokenResp token response bean type TokenResp struct { RespError AccessToken string `json:"access_token"` @@ -147,7 +148,7 @@ type TokenResp struct { DeviceId string `json:"device_id"` } -// office_preview_url response bean +// OfficePreviewUrlResp office_preview_url response bean type OfficePreviewUrlResp struct { RespError PreviewUrl string `json:"preview_url"` @@ -162,3 +163,15 @@ type VideoPreviewUrlResp struct { Url string `json:"url"` } `json:"template_list"` } + +type VideoPreviewPlayInfoResp struct { + RespError + VideoPreviewPlayInfo struct { + LiveTranscodingTaskList []struct { + TemplateId string `json:"template_id"` + Status string `json:"status"` + Url string `json:"url"` + Stage string `json:"stage"` + } `json:"live_transcoding_task_list"` + } `json:"video_preview_play_info"` +} diff --git a/conf/const.go b/conf/const.go index 6f439ee7..2e953d35 100644 --- a/conf/const.go +++ b/conf/const.go @@ -22,7 +22,7 @@ var ( var Conf = new(Config) const ( - VERSION = "v1.0.5" + VERSION = "v1.0.6" ImageThumbnailProcess = "image/resize,w_50" VideoThumbnailProcess = "video/snapshot,t_0,f_jpg,w_50" diff --git a/server/controllers/video_preview.go b/server/controllers/video_preview.go index a77dec01..42e0d479 100644 --- a/server/controllers/video_preview.go +++ b/server/controllers/video_preview.go @@ -11,7 +11,7 @@ type VideoPreviewReq struct { FileId string `json:"file_id" binding:"required"` } -// handle video_preview request +// VideoPreview handle video_preview request func VideoPreview(c *gin.Context) { drive := utils.GetDriveByName(c.Param("drive")) if drive == nil { @@ -31,3 +31,23 @@ func VideoPreview(c *gin.Context) { } c.JSON(200, DataResponse(preview)) } + +func VideoPreviewPlayInfo(c *gin.Context) { + drive := utils.GetDriveByName(c.Param("drive")) + if drive == nil { + c.JSON(200, MetaResponse(400, "drive isn't exist.")) + return + } + var req VideoPreviewReq + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error())) + return + } + log.Debugf("preview_req:%+v", req) + preview, err := alidrive.GetVideoPreviewPlayInfo(req.FileId, drive) + if err != nil { + c.JSON(200, MetaResponse(500, err.Error())) + return + } + c.JSON(200, DataResponse(preview)) +} \ No newline at end of file diff --git a/server/router.go b/server/router.go index 4fc7ea63..be1a834d 100644 --- a/server/router.go +++ b/server/router.go @@ -34,7 +34,7 @@ func InitApiRouter(engine *gin.Engine, download bool) { if download { apiV2.POST("/office_preview/:drive", controllers.OfficePreview) apiV2.POST("/video_preview/:drive", controllers.VideoPreview) - + apiV2.POST("/video_preview_play_info/:drive", controllers.VideoPreviewPlayInfo) engine.GET("/d/*path", controllers.Down) } }