Skip to content

Commit

Permalink
海报合成任务
Browse files Browse the repository at this point in the history
  • Loading branch information
lilang committed Apr 23, 2023
1 parent 200e93b commit dbc50da
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 0 deletions.
78 changes: 78 additions & 0 deletions ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1998,3 +1998,81 @@ func (s *CIService) AIBodyRecognition(ctx context.Context, key string, opt *AIBo
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}

// 海报合成
// PosterproductionInput TODO
type PosterproductionInput struct {
Object string `xml:"Object,omitempty"`
}

// PosterproductionTemplateOptions TODO
type PosterproductionTemplateOptions struct {
XMLName xml.Name `xml:"Request"`
Input *PosterproductionInput `xml:"Input,omitempty"`
Name string `xml:"Name,omitempty"`
CategoryIds string `xml:"CategoryIds,omitempty"`
}

// DescribePosterproductionTemplateOptions TODO
type DescribePosterproductionTemplateOptions struct {
PageNumber int `url:"pageNumber,omitempty"`
PageSize int `url:"pageSize,omitempty"`
CategoryIds string `url:"categoryIds,omitempty"`
Type string `url:"type,omitempty"`
}

// PosterproductionTemplateResult TODO
type PosterproductionTemplateResult struct {
XMLName xml.Name `xml:"Response"`
RequestId string `xml:"RequestId,omitempty"`
Template interface{} `xml:"Template,omitempty"`
}

// PosterproductionTemplateResult TODO
type PosterproductionTemplateResults struct {
XMLName xml.Name `xml:"Response"`
RequestId string `xml:"RequestId,omitempty"`
TotalCount string `xml:"TotalCount,omitempty"`
PageNumber string `xml:"PageNumber,omitempty"`
PageSize string `xml:"PageSize,omitempty"`
TemplateList interface{} `xml:"TemplateList,omitempty"`
}

func (s *CIService) PutPosterproductionTemplate(ctx context.Context, opt *PosterproductionTemplateOptions) (*PosterproductionTemplateResult, *Response, error) {
var res PosterproductionTemplateResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/posterproduction/template",
method: http.MethodPost,
optQuery: nil,
body: &opt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}

func (s *CIService) GetPosterproductionTemplate(ctx context.Context, tplId string) (*PosterproductionTemplateResult, *Response, error) {
var res PosterproductionTemplateResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/posterproduction/template/" + tplId,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}

func (s *CIService) GetPosterproductionTemplates(ctx context.Context, opt *DescribePosterproductionTemplateOptions) (*PosterproductionTemplateResults, *Response, error) {
var res PosterproductionTemplateResults
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/posterproduction/template",
method: http.MethodGet,
optQuery: opt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
7 changes: 7 additions & 0 deletions ci_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,12 @@ type PicProcessResult struct {
} `xml:"UploadResult"`
}

// PosterProduction TODO
type PosterProduction struct {
TemplateId string `xml:"TemplateId,omitempty"`
Info interface{} `xml:"Info,omitempty"`
}

// PicProcessJobOperation TODO
type PicProcessJobOperation struct {
TemplateId string `xml:"TemplateId,omitempty"`
Expand All @@ -659,6 +665,7 @@ type PicProcessJobOperation struct {
UserData string `xml:"UserData,omitempty"`
JobLevel int `xml:"JobLevel,omitempty"`
PicProcessResult *PicProcessResult `xml:"PicProcessResult,omitempty"`
PosterProduction *PosterProduction `xml:"PosterProduction,omitempty"`
}

// MediaProcessJobOperation TODO
Expand Down
49 changes: 49 additions & 0 deletions example/CI/media_process/media_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,54 @@ func InvokeSoundHoundJob() {
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
}

func InvokePosterProductionJob() {
u, _ := url.Parse("https://test-1234567890.cos.ap-chongqing.myqcloud.com")
cu, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
// todo 需要替换为自己的secretid secretkey
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
// CreatePicProcessJobs
type autoInfo struct {
TextMain string `xml:"text_main,omitempty"`
TextSub string `xml:"text_sub,omitempty"`
}
info := autoInfo{
TextMain: "父亲节快乐",
TextSub: "献给最伟大的父亲!!!",
}
createJobOpt := &cos.CreatePicJobsOptions{
Tag: "PosterProduction",
Operation: &cos.PicProcessJobOperation{
PosterProduction: &cos.PosterProduction{
TemplateId: "6444f12ae24d596cdbd774fb",
Info: info,
},
Output: &cos.JobOutput{
Region: "ap-chongqing",
Bucket: "test-1234567890",
Object: "poster/PosterProduction2.jpg",
},
},
// todo 需要替换为自己的回调地址信息
CallBack: "https://demo.org/callback",
}
createJobRes, _, err := c.CI.CreatePicProcessJobs(context.Background(), createJobOpt)
log_status(err)
fmt.Printf("%+v\n", createJobRes.JobsDetail)
}

func main() {
// InvokeAnimationJob()
// InvokeSnapshotJob()
Expand Down Expand Up @@ -2202,4 +2250,5 @@ func main() {
// InvokeSplitVideoPartsJob()
// InvokeVideoTargetRecJob()
// InvokeSegmentVideoBodyJob()
InvokePosterProductionJob()
}
116 changes: 116 additions & 0 deletions example/CI/media_process/poster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package main

import (
"context"
"fmt"
"net/http"
"net/url"
"os"

"github.com/tencentyun/cos-go-sdk-v5"
"github.com/tencentyun/cos-go-sdk-v5/debug"
)

func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}

func PutPosterproductionTemplate() {
u, _ := url.Parse("https://test-1234567890.cos.ap-chongqing.myqcloud.com")
cu, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
PosterproductionTemplate := &cos.PosterproductionTemplateOptions{
Input: &cos.PosterproductionInput{
Object: "input/sample.psd",
},
Name: "test",
}
PutPosterproductionRes, _, err := c.CI.PutPosterproductionTemplate(context.Background(), PosterproductionTemplate)
log_status(err)
fmt.Printf("%+v\n", PutPosterproductionRes)
fmt.Printf("%+v\n", &PutPosterproductionRes.Template)
}

func GetPosterproductionTemplate() {
u, _ := url.Parse("https://test-1234567890.cos.ap-chongqing.myqcloud.com")
cu, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
PutPosterproductionRes, _, err := c.CI.GetPosterproductionTemplate(context.Background(), "6444f12ae24d596cdbd774fb")
log_status(err)
fmt.Printf("%+v\n", PutPosterproductionRes)
fmt.Printf("%+v\n", &PutPosterproductionRes.Template)
}

func GetPosterproductionTemplates() {
u, _ := url.Parse("https://test-1234567890.cos.ap-chongqing.myqcloud.com")
cu, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
opt := &cos.DescribePosterproductionTemplateOptions{
PageNumber: 1,
PageSize: 10,
}
PutPosterproductionRes, _, err := c.CI.GetPosterproductionTemplates(context.Background(), opt)
log_status(err)
fmt.Printf("%+v\n", PutPosterproductionRes)
fmt.Printf("%+v\n", &PutPosterproductionRes.TemplateList)
}

func main() {
// PutPosterproductionTemplate()
// GetPosterproductionTemplate()
// GetPosterproductionTemplates()
}

0 comments on commit dbc50da

Please sign in to comment.