Skip to content

Commit

Permalink
feat(local): 增加本地推素材管理相关API
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Oct 11, 2024
1 parent 83bada9 commit aadb555
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 3 deletions.
6 changes: 6 additions & 0 deletions marketing-api/LOCAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@
- 获取项目数据 [ ProjectGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *report.ProjectGetRequest) (*report.ProjectGetResult, error) ]
- 获取广告数据 [ PromotionGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *report.PromotionGetRequest) (*report.PromotionGetResult, error) ]
- 获取素材数据 [ MaterialGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *report.MaterialGetRequest) (*report.MaterialGetResult, error) ]
- 本地推素材管理 (local/file)
- 异步上传本地推视频 [ UploadTaskCreate(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.UploadTaskCreateRequest) (uint64, error) ]
- 查询异步上传本地推视频结果 [ VideoUploadTaskList(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoUploadTaskListRequest) ([]file.UploadTask, error) ]
- 上传视频 [ VideoUpload(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoUploadRequest) (*file.Video, error) ]
- 获取素材库视频 [ VideoGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoGetRequest) (*file.VideoGetResult, error) ]
- 获取抖音主页视频 [ VideoAwemeGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoAwemeGetRequest) (*file.VideoAwemeGetResult, error) ]
2 changes: 2 additions & 0 deletions marketing-api/api/local/file/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package file 本地推素材管理相关
package file
19 changes: 19 additions & 0 deletions marketing-api/api/local/file/upload_task_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package file

import (
"context"

"github.com/bububa/oceanengine/marketing-api/core"
"github.com/bububa/oceanengine/marketing-api/model/local/file"
)

// UploadTaskCreate 异步上传本地推视频
// 将视频文件通过连山云素材服务上传后获取到视频文件链接,再将获取到的连山云视频文件url作为入参的video_url通过素材库提供的视频上传接口进行文件上传
// 仅支持开发者购置连山云素材服务上传生成的tos链接上传,不支持其他三方链接地址
func UploadTaskCreate(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.UploadTaskCreateRequest) (uint64, error) {
var resp file.UploadTaskCreateResponse
if err := clt.PostAPI(ctx, "v3.0/local/file/upload_task/create/", req, &resp, accessToken); err != nil {
return 0, err
}
return resp.Data.TaskID, nil
}
17 changes: 17 additions & 0 deletions marketing-api/api/local/file/video_aweme_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package file

import (
"context"

"github.com/bububa/oceanengine/marketing-api/core"
"github.com/bububa/oceanengine/marketing-api/model/local/file"
)

// VideoAwemeGet 获取素材库视频
func VideoAwemeGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoAwemeGetRequest) (*file.VideoAwemeGetResult, error) {
var resp file.VideoAwemeGetResponse
if err := clt.GetAPI(ctx, "v3.0/local/file/video/aweme/get/", req, &resp, accessToken); err != nil {
return nil, err
}
return resp.Data, nil
}
17 changes: 17 additions & 0 deletions marketing-api/api/local/file/video_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package file

import (
"context"

"github.com/bububa/oceanengine/marketing-api/core"
"github.com/bububa/oceanengine/marketing-api/model/local/file"
)

// VideoGet 获取素材库视频
func VideoGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoGetRequest) (*file.VideoGetResult, error) {
var resp file.VideoGetResponse
if err := clt.GetAPI(ctx, "v3.0/local/file/video/get/", req, &resp, accessToken); err != nil {
return nil, err
}
return resp.Data, nil
}
17 changes: 17 additions & 0 deletions marketing-api/api/local/file/video_upload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package file

import (
"context"

"github.com/bububa/oceanengine/marketing-api/core"
"github.com/bububa/oceanengine/marketing-api/model/local/file"
)

// VideoUpload 上传视频
func VideoUpload(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoUploadRequest) (*file.Video, error) {
var resp file.VideoUploadResponse
if err := clt.Upload(ctx, "v3.0/local/file/video/upload/", req, &resp, accessToken); err != nil {
return nil, err
}
return resp.Data, nil
}
17 changes: 17 additions & 0 deletions marketing-api/api/local/file/video_upload_task_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package file

import (
"context"

"github.com/bububa/oceanengine/marketing-api/core"
"github.com/bububa/oceanengine/marketing-api/model/local/file"
)

// VideoUploadTaskList 查询异步上传本地推视频结果
func VideoUploadTaskList(ctx context.Context, clt *core.SDKClient, accessToken string, req *file.VideoUploadTaskListRequest) ([]file.UploadTask, error) {
var resp file.VideoUploadTaskListResponse
if err := clt.GetAPI(ctx, "v3.0/local/file/video/upload_task/list/", req, &resp, accessToken); err != nil {
return nil, err
}
return resp.Data.List, nil
}
14 changes: 11 additions & 3 deletions marketing-api/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ func (c *SDKClient) OpenGet(ctx context.Context, gw string, req model.GetRequest
return c.get(ctx, OPEN_URL, gw, req, resp, accessToken)
}

// Upload multipart/form-data post
func (c *SDKClient) Upload(ctx context.Context, gw string, req model.UploadRequest, resp model.Response, accessToken string) error {
return c.upload(ctx, BASE_URL, gw, req, resp, accessToken)
}

func (c *SDKClient) UploadAPI(ctx context.Context, gw string, req model.UploadRequest, resp model.Response, accessToken string) error {
return c.upload(ctx, API_BASE_URL, gw, req, resp, accessToken)
}

func (c *SDKClient) post(ctx context.Context, base string, gw string, req model.PostRequest, resp model.Response, accessToken string) error {
var reqBytes []byte
if req != nil {
Expand Down Expand Up @@ -217,8 +226,7 @@ func (c *SDKClient) GetBytes(ctx context.Context, gw string, req model.GetReques
return ret, err
}

// Upload multipart/form-data post
func (c *SDKClient) Upload(ctx context.Context, gw string, req model.UploadRequest, resp model.Response, accessToken string) error {
func (c *SDKClient) upload(ctx context.Context, base string, gw string, req model.UploadRequest, resp model.Response, accessToken string) error {
buf := util.GetBufferPool()
defer util.PutBufferPool(buf)
mw := multipart.NewWriter(buf)
Expand Down Expand Up @@ -252,7 +260,7 @@ func (c *SDKClient) Upload(ctx context.Context, gw string, req model.UploadReque
}
}
mw.Close()
reqUrl := util.StringsJoin(BASE_URL, gw)
reqUrl := util.StringsJoin(base, gw)
debug.PrintPostMultipartRequest(reqUrl, mp, c.debug)
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, reqUrl, buf)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions marketing-api/enum/local/material_analysis_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package local

// MaterialAnalysisType 评估类型
type MaterialAnalysisType string

const (
// MaterialAnalysisType_FIRST_PUBLISH 首发
MaterialAnalysisType_FIRST_PUBLISH MaterialAnalysisType = "FIRST_PUBLISH"
// MaterialAnalysisType_FIRST_PUBLISH_AND_HIGH_QUALITY 首发&优质
MaterialAnalysisType_FIRST_PUBLISH_AND_HIGH_QUALITY MaterialAnalysisType = "FIRST_PUBLISH_AND_HIGH_QUALITY"
// MaterialAnalysisType_HIGH_QUALITY 优质
MaterialAnalysisType_HIGH_QUALITY MaterialAnalysisType = "HIGH_QUALITY"
)
17 changes: 17 additions & 0 deletions marketing-api/enum/local/material_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package local

// MaterialSource 素材来源
type MaterialSource string

const (
// MaterialSource_BP_PLATFORM 巨量引擎工作平台共享视频
MaterialSource_BP_PLATFORM MaterialSource = "BP_PLATFORM"
// MaterialSource_CREATIVE_AIGC 即创
MaterialSource_CREATIVE_AIGC MaterialSource = "CREATIVE_AIGC"
// MaterialSource_LOCAL_ADS_UPLOAD 本地上传
MaterialSource_LOCAL_ADS_UPLOAD MaterialSource = "LOCAL_ADS_UPLOAD"
// MaterialSource_STAR 星图平台
MaterialSource_STAR MaterialSource = "STAR"
// MaterialSource_MAPI MAPI上传
MaterialSource_MAPI MaterialSource = "MAPI"
)
13 changes: 13 additions & 0 deletions marketing-api/enum/local/upload_task_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package local

// UploadTaskStatus 任务处理状态
type UploadTaskStatus string

const (
// UploadTaskStatus_PROCESS 处理中
UploadTaskStatus_PROCESS UploadTaskStatus = "PROCESS"
// UploadTaskStatus_SUCCESS 成功
UploadTaskStatus_SUCCESS UploadTaskStatus = "SUCCESS"
// UploadTaskStatus_FAILED 失败
UploadTaskStatus_FAILED UploadTaskStatus = "FAILED"
)
2 changes: 2 additions & 0 deletions marketing-api/model/local/file/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package file 本地推素材管理相关
package file
31 changes: 31 additions & 0 deletions marketing-api/model/local/file/upload_task_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package file

import (
"github.com/bububa/oceanengine/marketing-api/model"
"github.com/bububa/oceanengine/marketing-api/util"
)

// UploadTaskCreateRequest 异步上传本地推视频 API Request
type UploadTaskCreateRequest struct {
// LocalAccountID 本地推账户id
LocalAccountID uint64 `json:"local_account_id,omitempty"`
// Filename 素材的文件名
Filename string `json:"filename,omitempty"`
// VideoURL 视频 url地址,最大支持上传文件大小:1000M
// 仅支持开发者购置连山云素材服务上传生成的tos链接上传,不支持其他三方链接地址,具体见接入指南
VideoURL string `json:"video_url,omitempty"`
}

// Encode implements PostRequest interface
func (r UploadTaskCreateRequest) Encode() []byte {
return util.JSONMarshal(r)
}

// UploadTaskCreateResponse 异步上传本地推视频 API Response
type UploadTaskCreateResponse struct {
model.BaseResponse
Data struct {
// TaskID 本地推任务id
TaskID uint64 `json:"task_id,omitempty"`
} `json:"data,omitempty"`
}
81 changes: 81 additions & 0 deletions marketing-api/model/local/file/video.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package file

import "github.com/bububa/oceanengine/marketing-api/enum/local"

// Video 视频信息
type Video struct {
// VideoID 视频id
VideoID string `json:"video_id,omitempty"`
// MaterialID 素材id
MaterialID uint64 `json:"material_id,omitempty"`
// Size 视频大小
Size int64 `json:"size,omitempty"`
// VideoSiganture 视频md5
VideoSiganture string `json:"video_siganture,omitempty"`
// Width 视频宽
Width int64 `json:"width,omitempty"`
// Height 视频高
Height int64 `json:"height,omitempty"`
// VideoURL 视频地址
VideoURL string `json:"video_url,omitempty"`
// Duration 视频时长
Duration float64 `json:"duration,omitempty"`
// VideoName 视频名称
VideoName string `json:"video_name,omitempty"`
// PosterURL 视频首帧截图
PosterURL string `json:"poster_url,omitempty"`
// MaterialProperties 素材标签,枚举值:
// COPY 搬运风险
// FIRST_PUBLISH 首发
// HIGH_QUALITY 优质
// LOW_QUALITY 低质
// SIMILAR 同质化风险
MaterialProperties []string `json:"material_properties,omitempty"`
// ImageMode 视频类型,枚举值:
// IMAGE_MODE_VIDEO 横版视频
// IMAGE_MODE_VIDEO_VERTICAL 竖版视频
ImageMode local.ImageMode `json:"image_mode,omitempty"`
// Source 视频来源,枚举值:
// BP_PLATFORM 巨量引擎工作平台共享视频
// CREATIVE_AIGC 即创
// LOCAL_ADS_UPLOAD 本地上传
// STAR 星图平台
// MAPI MAPI接口上传
Source local.MaterialSource `json:"source,omitempty"`
// CreateTime 素材的上传时间,格式:yyyy-mm-dd HH:mm:ss
CreateTime string `json:"create_time,omitempty"`
}

// VideoAweme 抖音视频
type VideoAweme struct {
// ItemID 抖音视频ID
ItemID uint64 `json:"item_id,omitempty"`
// Title 视频标题
Title string `json:"title,omitempty"`
// VideoID 视频ID
VideoID string `json:"video_id,omitempty"`
// AwemeID 抖音号ID
AwemeID string `json:"aweme_id,omitempty"`
// ImageMode 视频类型,枚举值:
// IMAGE_MODE_VIDEO 横版视频
// IMAGE_MODE_VIDEO_VERTICAL 竖版视频
ImageMode local.ImageMode `json:"image_mode,omitempty"`
// CoverImageURL 视频封面图片地址
CoverImageURL string `json:"cover_image_url,omitempty"`
// AwemeVideoURL 视频播放地址
AwemeVideoURL string `json:"aweme_video_url,omitempty"`
// NotDeliveryReason 不可投放原因
NotDeliveryReason string `json:"not_delivery_reason,omitempty"`
// CanDelivery 视频是否可投放
// true 可投放
// false 不可投放
CanDelivery bool `json:"can_delivery,omitempty"`
// LegoMaterialID 素材id
LegoMaterialID uint64 `json:"lego_material_id,omitempty"`
// VideoWidth 视频宽度
VideoWidth int64 `json:"video_width,omitempty"`
// VideoHeight 视频高度
VideoHeight int64 `json:"video_height,omitempty"`
// Duration 视频时长
Duration string `json:"duration,omitempty"`
}
Loading

0 comments on commit aadb555

Please sign in to comment.