作者 yangfu

视频点播修改

... ... @@ -37,6 +37,27 @@ func (this *VodController) CreateUploadVideo() {
msg = protocol.NewReturnResponse(upload.CreateUploadVideo(header, request))
}
//刷新视频上传凭证 RefreshUploadVideo
// @router /refreshUploadVideo [post]
func (this *VodController) RefreshUploadVideo() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.RefreshUploadVideoRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(upload.RefreshUploadVideo(header, request))
}
//创建图片上传凭证 CreateUploadImage
// @router /createUploadImage [post]
func (this *VodController) CreateUploadImage() {
... ... @@ -58,6 +79,45 @@ func (this *VodController) CreateUploadImage() {
msg = protocol.NewReturnResponse(upload.CreateUploadImage(header, request))
}
//创建图片上传凭证 CreateUploadImages
// @router /createUploadImages [post]
func (this *VodController) CreateUploadImages() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var (
request *aliyun.CreateUploadImagesRequest
response *aliyun.CreateUploadImagesResponse = &aliyun.CreateUploadImagesResponse{
List: make([]*aliyun.CreateUploadImageResponse, 0),
}
)
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
var err error
if len(request.Items) == 0 {
msg = protocol.BadRequestParam(2)
}
header := controllers.GetRequestHeader(this.Ctx)
for i := range request.Items {
r := request.Items[i]
if rsp, e := upload.CreateUploadImage(header, r); e != nil {
err = e
break
} else {
response.List = append(response.List, rsp)
}
}
msg = protocol.NewReturnResponse(response, err)
}
//获取视频播放地址 GetPlayInfo
// @router /getPlayInfo [post]
func (this *VodController) GetPlayInfo() {
... ...
... ... @@ -3,7 +3,7 @@ package aliyun
//创建视频上传凭证
/*CreateUploadVideo */
type CreateUploadVideoRequest struct {
FileName string `position:"Query" name:"fileName"`
FileName string `json:"fileName"`
}
type CreateUploadVideoResponse struct {
... ... @@ -11,6 +11,20 @@ type CreateUploadVideoResponse struct {
VideoId string `json:"videoId"`
UploadAddress string `json:"uploadAddress"`
UploadAuth string `json:"uploadAuth"`
FileURL string `json:"fileURL"`
}
//刷新视频上传凭证 RefreshUploadVideo
type RefreshUploadVideoRequest struct {
VideoId string `json:"videoId" valid:"Required;"`
}
type RefreshUploadVideoResponse struct {
RequestId string `json:"requestId"`
VideoId string `json:"videoId"`
UploadAddress string `json:"uploadAddress"`
UploadAuth string `json:"uploadAuth"`
FileURL string `json:"fileURL"`
}
/*GetPlayInfo 获取播放信息*/
... ... @@ -75,3 +89,19 @@ type PlayInfo struct {
PlayURL string `json:"PlayURL" xml:"PlayURL"`
Specification string `json:"Specification" xml:"Specification"`
}
//GetVideoPlayAuthResponse is the response struct for api GetVideoPlayAuth
type GetVideoPlayAuthResponse struct {
RequestId string `json:"requestId" xml:"RequestId"`
PlayAuth string `json:"playAuth" xml:"PlayAuth"`
VideoMeta VideoMeta `json:"videoMeta" xml:"VideoMeta"`
}
// VideoMeta is a nested struct in vod response
type VideoMeta struct {
CoverURL string `json:"coverURL" xml:"CoverURL"`
Duration float64 `json:"duration" xml:"Duration"`
Status string `json:"-" xml:"Status"`
Title string `json:"title" xml:"Title"`
VideoId string `json:"videoId" xml:"VideoId"`
}
... ...
... ... @@ -5,10 +5,18 @@ type CreateUploadImageRequest struct {
}
type CreateUploadImageResponse struct {
RequestId string `json:"requestId" xml:"RequestId"`
ImageId string `json:"imageId" xml:"ImageId"`
ImageURL string `json:"imageURL" xml:"ImageURL"`
UploadAddress string `json:"uploadAddress" xml:"UploadAddress"`
UploadAuth string `json:"uploadAuth" xml:"UploadAuth"`
FileURL string `json:"fileURL" xml:"FileURL"`
RequestId string `json:"requestId"`
ImageId string `json:"imageId" `
ImageURL string `json:"imageURL"`
UploadAddress string `json:"uploadAddress"`
UploadAuth string `json:"uploadAuth"`
FileURL string `json:"fileURL"`
}
type CreateUploadImagesRequest struct {
Items []*CreateUploadImageRequest `json:"items"`
}
type CreateUploadImagesResponse struct {
List []*CreateUploadImageResponse `json:"list"`
}
... ...
package aliyun
import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)
type UploadAddress struct {
Endpoint string
Bucket string
FileName string
}
//@cname 绑定域名
func (up UploadAddress) GetFileUrl(cname string) string {
if len(cname) > 0 {
return fmt.Sprintf("%v%v", cname, up.FileName)
}
if strings.Contains(up.Endpoint, "https") {
return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:8], up.Bucket, up.Endpoint[8:], up.FileName)
} else if strings.Contains(up.Endpoint, "http") {
return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:7], up.Bucket, up.Endpoint[7:], up.FileName)
}
return ""
}
//解析UploadAddress
func ParseUploadAddress(uploadAddress string) (up UploadAddress, err error) {
var jsData []byte
jsData, err = base64.StdEncoding.DecodeString(uploadAddress)
if err != nil {
return
}
if err = json.Unmarshal(jsData, &up); err != nil {
return
}
return
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
"github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
"github.com/astaxie/beego"
"github.com/prometheus/common/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
"opp/internal/utils"
... ... @@ -42,11 +43,10 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons
request := vod.CreateCreateUploadVideoRequest()
filePath := getFileName(FileVideo, r.FileName)
if filepath.Ext(r.FileName) == "mp3" {
filePath = getFileName(FileVideo, r.FileName)
filePath = getFileName(FileVoice, r.FileName)
}
request.Title = filePath
request.FileName = filePath
//request.StorageLocation = filepath.Base(filePath)
request.AcceptFormat = "JSON"
rsp, err := client.CreateUploadVideo(request)
if err != nil {
... ... @@ -58,6 +58,32 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons
UploadAddress: rsp.UploadAddress,
UploadAuth: rsp.UploadAuth,
}
if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
log.Error(e)
} else {
response.FileURL = up.GetFileUrl("")
}
return
}
func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (response *RefreshUploadVideoResponse, err error) {
request := vod.CreateRefreshUploadVideoRequest()
request.VideoId = r.VideoId
request.AcceptFormat = "JSON"
var rsp *vod.RefreshUploadVideoResponse
rsp, err = client.RefreshUploadVideo(request)
if err != nil {
return
}
if err = utils.JsonDeepCopy(&response, &rsp); err != nil {
return
}
if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
log.Error(e)
} else {
response.FileURL = up.GetFileUrl("")
}
return
}
... ... @@ -67,7 +93,7 @@ func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (respons
filePath := getFileName(FileImage, r.FileName)
request.ImageType = "default"
request.Title = filePath
request.ImageExt = filepath.Ext(r.FileName)
request.ImageExt = filepath.Ext(r.FileName)[1:]
request.AcceptFormat = "JSON"
//request.StorageLocation = filepath.Base(request.Title)
rsp, err := client.CreateUploadImage(request)
... ... @@ -87,11 +113,17 @@ func GetPlayInfo(client *vod.Client, r *GetPlayInfoRequest) (response *vod.GetPl
}
//获取播放信息
func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (response interface{}, err error) {
func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (response GetVideoPlayAuthResponse, err error) {
request := vod.CreateGetVideoPlayAuthRequest()
request.VideoId = r.VideoId
request.AcceptFormat = "JSON"
return client.GetVideoPlayAuth(request)
var rsp *vod.GetVideoPlayAuthResponse
if rsp, err = client.GetVideoPlayAuth(request); err != nil {
log.Error(err)
return
}
err = utils.JsonDeepCopy(&response, rsp)
return
}
//fileType: video voice image
... ...
... ... @@ -492,13 +492,15 @@ func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) {
type Speech struct {
Path string `json:"path"`
Duration int `json:"duration"`
VideoId string `json:"videoId"`
}
//图片
type Picture struct {
Path string `json:"path"`
W int `json:"w"`
H int `json:"h"`
Path string `json:"path"`
W int `json:"w"`
H int `json:"h"`
ImageId string `json:"imageId"`
}
//视频
... ... @@ -506,6 +508,7 @@ type Video struct {
Path string `json:"path"`
Cover Cover `json:"cover"` //封面
Duration int `json:"duration"`
VideoId string `json:"videoId"`
}
//审批配置
... ...
... ... @@ -625,6 +625,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadImages",
Router: `/createUploadImages`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadVideo",
Router: `/createUploadVideo`,
AllowHTTPMethods: []string{"post"},
... ... @@ -647,4 +655,12 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
beego.ControllerComments{
Method: "RefreshUploadVideo",
Router: `/refreshUploadVideo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -151,6 +151,22 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl
return
}
//创建视频上传凭证
func RefreshUploadVideo(header *protocol.RequestHeader, request *aliyun.RefreshUploadVideoRequest) (rsp *aliyun.RefreshUploadVideoResponse, err error) {
var ()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
rsp, err = aliyun.RefreshUploadVideo(client, request)
if err != nil {
log.Error(err)
}
return
}
//创建图片上传凭证
func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUploadImageRequest) (rsp *aliyun.CreateUploadImageResponse, err error) {
var ()
... ... @@ -160,6 +176,9 @@ func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUpl
err = e
return
}
if len(request.FileName) == 0 {
request.FileName = aliyun.DefaultImageFileName
}
rsp, err = aliyun.CreateUploadImage(client, request)
if err != nil {
log.Error(err)
... ...