From 917abd14626ac6b1dd08c21d46b9a9988f537b1a Mon Sep 17 00:00:00 2001 From: wanjiewu Date: Thu, 4 Mar 2021 11:23:49 +0800 Subject: [PATCH 1/5] =?UTF-8?q?add:=E6=94=AF=E6=8C=81=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci_media.go | 304 +++++++++++++++++++++++++++++++++ example/media_process/media_process.go | 98 +++++++++++ 2 files changed, 402 insertions(+) create mode 100644 ci_media.go create mode 100644 example/media_process/media_process.go diff --git a/ci_media.go b/ci_media.go new file mode 100644 index 0000000..3749d24 --- /dev/null +++ b/ci_media.go @@ -0,0 +1,304 @@ +package cos + +import ( + "context" + "encoding/xml" + "net/http" +) + +type JobInput struct { + Object string `xml:"Object,omitempty"` +} + +type JobOutput struct { + Region string `xml:"Region,omitempty"` + Bucket string `xml:"Bucket,omitempty"` + Object string `xml:"Object,omitempty"` +} + +type Container struct { + Format string `xml:"Format"` +} + +type Video struct { + Codec string `xml:"Codec"` + Width string `xml:"Width"` + Height string `xml:"Height"` + Fps string `xml:"Fps"` + Remove string `xml:"Remove"` + Profile string `xml:"Profile"` + Bitrate string `xml:"Bitrate"` + Crf string `xml:"Crf"` + Gop string `xml:"Gop"` + Preset string `xml:"Preset"` + Bufsize string `xml:"Bufsize"` + Maxrate string `xml:"Maxrate"` + HlsTsTime string `xml:"HlsTsTime"` + Pixfmt string `xml:"Pixfmt"` + LongShortMode string `xml:"LongShortMode"` +} + +type TimeInterval struct { + Start string `xml:"Start"` + Duration string `xml:"Duration"` +} + +type Audio struct { + Codec string `xml:"Codec"` + Samplerate string `xml:"Samplerate"` + Bitrate string `xml:"Bitrate"` + Channels string `xml:"Channels"` + Remove string `xml:"Remove"` +} + +type TransConfig struct { + AdjDarMethod string `xml:"AdjDarMethod"` + IsCheckReso string `xml:"IsCheckReso"` + ResoAdjMethod string `xml:"ResoAdjMethod"` + IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"` + VideoBitrateAdjMethod string `xml:"VideoBitrateAdjMethod"` + IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"` + AudioBitrateAdjMethod string `xml:"AudioBitrateAdjMethod"` +} + +type Transcode struct { + Container *Container `xml:"Container,omitempty"` + Video *Video `xml:"Video,omitempty"` + TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"` + Audio *Audio `xml:"Audio,omitempty"` + TransConfig *TransConfig `xml:"TransConfig,omitempty"` +} + +type Image struct { + Url string `xml:"Url,omitempty"` + Mode string `xml:"Mode,omitempty"` + Width string `xml:"Width,omitempty"` + Height string `xml:"Height,omitempty"` + Transparency string `xml:"Transparency,omitempty"` + Background string `xml:"Background,omitempty"` +} + + +type Text struct { + FontSize string `xml:"FontSize,omitempty"` + FontType string `xml:"FontType,omitempty"` + FontColor string `xml:"FontColor,omitempty"` + Transparency string `xml:"Transparency,omitempty"` + Text string `xml:"Text,omitempty"` +} + +type Watermark struct { + Type string `xml:"Type,omitempty"` + Pos string `xml:"Pos,omitempty"` + LocMode string `xml:"LocMode,omitempty"` + Dx string `xml:"Dx,omitempty"` + Dy string `xml:"Dy,omitempty"` + StartTime string `xml:"StartTime,omitempty"` + EndTime string `xml:"EndTime,omitempty"` + Image *Image `xml:"Image,omitempty"` + Text *Text `xml:"Text,omitempty"` +} + +type MediaProcessJobOperation struct { + Output *JobOutput `xml:"Output,omitempty"` + Transcode *Transcode `xml:"Transcode,omitempty"` + Watermark *Watermark `xml:"Watermark,omitempty"` + TemplateId string `xml:"TemplateId,omitempty"` + WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"` +} + +type CreateMediaJobsOptions struct { + XMLName xml.Name `xml:"Request"` + Tag string `xml:"Tag,omitempty"` + Input *JobInput `xml:"Input,omitempty"` + Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` + QueueId string `xml:"QueueId,omitempty"` +} + +type MediaProcessJobDetail struct { + Code string `xml:"Code,omitempty"` + Message string `xml:"Message,omitempty"` + JobId string `xml:"JobId,omitempty"` + Tag string `xml:"Tag,omitempty"` + State string `xml:"State,omitempty"` + CreationTime string `xml:"CreationTime,omitempty"` + QueueId string `xml:"QueueId,omitempty"` + Input *JobInput `xml:"Input,omitempty"` + Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` +} + +type CreateMediaJobsResult struct { + XMLName xml.Name `xml:"Response"` + JobsDetail MediaProcessJobDetail `xml:"JobsDetail,omitempty"` +} + +func (s *CIService) CreateMediaJobs(ctx context.Context, opt *CreateMediaJobsOptions) (*CreateMediaJobsResult, *Response, error) { + var res CreateMediaJobsResult + sendOpt := sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: "/jobs", + method: http.MethodPost, + body: opt, + result: &res, + } + resp, err := s.client.send(ctx, &sendOpt) + return &res, resp, err +} + +type DescribeMediaProcessJobResult struct { + XMLName xml.Name `xml:"Response"` + JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"` + NonExistJobIds string `xml:"NonExistJobIds,omitempty"` +} + +func (s *CIService) DescribeMediaJobs(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) { + var res DescribeMediaProcessJobResult + sendOpt := sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: "/jobs/" + jobid, + method: http.MethodGet, + result: &res, + } + resp, err := s.client.send(ctx, &sendOpt) + return &res, resp, err +} + +type DescribeMediaProcessJobsOptions struct { + QueueId string `url:"queueId,omitempty"` + Tag string `url:"tag,omitempty"` + OrderByTime string `url:"orderByTime,omitempty"` + NextToken string `url:"nextToken,omitempty"` + Size int `url:"size,omitempty"` + States string `url:"states,omitempty"` + StartCreationTime string `url:"startCreationTime,omitempty"` + EndCreationTime string `url:"endCreationTime,omitempty"` +} + +type DescribeMediaProcessJobsResult struct { + XMLName xml.Name `xml:"Response"` + JobsDetail []DocProcessJobDetail `xml:"JobsDetail,omitempty"` + NextToken string `xml:"NextToken,omitempty"` +} + +func (s *CIService) DescribeMediaProcessJobs(ctx context.Context, opt *DescribeMediaProcessJobsOptions) (*DescribeMediaProcessJobsResult, *Response, error) { + var res DescribeMediaProcessJobsResult + sendOpt := sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: "/jobs", + optQuery: opt, + method: http.MethodGet, + result: &res, + } + resp, err := s.client.send(ctx, &sendOpt) + return &res, resp, err +} + +type DescribeMediaProcessQueuesOptions struct { + QueueIds string `url:"queueIds,omitempty"` + State string `url:"state,omitempty"` + PageNumber int `url:"pageNumber,omitempty"` + PageSize int `url:"pageSize,omitempty"` +} + +type DescribeMediaProcessQueuesResult struct { + XMLName xml.Name `xml:"Response"` + RequestId string `xml:"RequestId,omitempty"` + TotalCount int `xml:"TotalCount,omitempty"` + PageNumber int `xml:"PageNumber,omitempty"` + PageSize int `xml:"PageSize,omitempty"` + QueueList []MediaProcessQueue `xml:"QueueList,omitempty"` + NonExistPIDs []string `xml:"NonExistPIDs,omitempty"` +} + +type MediaProcessQueue struct { + QueueId string `xml:"QueueId,omitempty"` + Name string `xml:"Name,omitempty"` + State string `xml:"State,omitempty"` + MaxSize int `xml:"MaxSize,omitempty"` + MaxConcurrent int `xml:"MaxConcurrent,omitempty"` + UpdateTime string `xml:"UpdateTime,omitempty"` + CreateTime string `xml:"CreateTime,omitempty"` + NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"` +} + +type MediaProcessQueueNotifyConfig struct { + Url string `xml:"Url,omitempty"` + State string `xml:"State,omitempty"` + Type string `xml:"Type,omitempty"` + Event string `xml:"Event,omitempty"` +} + +func (s *CIService) DescribeMediaProcessQueues(ctx context.Context, opt *DescribeMediaProcessQueuesOptions) (*DescribeMediaProcessQueuesResult, *Response, error) { + var res DescribeMediaProcessQueuesResult + sendOpt := sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: "/queue", + optQuery: opt, + method: http.MethodGet, + result: &res, + } + resp, err := s.client.send(ctx, &sendOpt) + return &res, resp, err +} + +type UpdateMediaProcessQueueOptions struct { + XMLName xml.Name `xml:"Request"` + Name string `xml:"Name,omitempty"` + QueueID string `xml:"QueueID,omitempty"` + State string `xml:"State,omitempty"` + NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"` +} + +type UpdateMediaProcessQueueResult struct { + XMLName xml.Name `xml:"Response"` + RequestId string `xml:"RequestId"` + Queue *MediaProcessQueue `xml:"Queue"` +} + +func (s *CIService) UpdateMediaProcessQueue(ctx context.Context, opt *UpdateMediaProcessQueueOptions) (*UpdateMediaProcessQueueResult, *Response, error) { + var res UpdateMediaProcessQueueResult + sendOpt := sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: "/queue/" + opt.QueueID, + body: opt, + method: http.MethodPut, + result: &res, + } + resp, err := s.client.send(ctx, &sendOpt) + return &res, resp, err +} + +type DescribeMediaProcessBucketsOptions struct { + Regions string `url:"regions,omitempty"` + BucketNames string `url:"bucketNames,omitempty"` + BucketName string `url:"bucketName,omitempty"` + PageNumber int `url:"pageNumber,omitempty"` + PageSize int `url:"pageSize,omitempty"` +} + +type DescribeMediaProcessBucketsResult struct { + XMLName xml.Name `xml:"Response"` + RequestId string `xml:"RequestId,omitempty"` + TotalCount int `xml:"TotalCount,omitempty"` + PageNumber int `xml:"PageNumber,omitempty"` + PageSize int `xml:"PageSize,omitempty"` + MediaBucketList []MediaProcessBucket `xml:"MediaBucketList,omitempty"` +} +type MediaProcessBucket struct { + BucketId string `xml:"BucketId,omitempty"` + Region string `xml:"Region,omitempty"` + CreateTime string `xml:"CreateTime,omitempty"` +} + +func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *DescribeMediaProcessBucketsOptions) (*DescribeMediaProcessBucketsResult, *Response, error) { + var res DescribeMediaProcessBucketsResult + sendOpt := sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: "/mediabucket", + optQuery: opt, + method: http.MethodGet, + result: &res, + } + resp, err := s.client.send(ctx, &sendOpt) + return &res, resp, err +} \ No newline at end of file diff --git a/example/media_process/media_process.go b/example/media_process/media_process.go new file mode 100644 index 0000000..cab0ee5 --- /dev/null +++ b/example/media_process/media_process.go @@ -0,0 +1,98 @@ +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 main() { + u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com") + cu, _ := url.Parse("https://wwj-cq-1253960454.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, + }, + }, + }) + fmt.Printf("%+v\n", os.Getenv("COS_SECRETID")) + // DescribeMediaProcessQueues + DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{ + QueueIds: "", + PageNumber: 1, + PageSize: 2, + } + DescribeQueueRes, _, err := c.CI.DescribeMediaProcessQueues(context.Background(), DescribeQueueOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeQueueRes) + // CreateMediaJobs + createJobOpt := &cos.CreateMediaJobsOptions{ + Tag: "Transcode", + Input: &cos.JobInput{ + Object: "input/117374C.mp4", + }, + Operation: &cos.MediaProcessJobOperation{ + Output: &cos.JobOutput{ + Region: "ap-chongqing", + Object: "output/go_117374C.mp4", + Bucket: "wwj-cq-1253960454", + }, + Transcode: &cos.Transcode{ + Container: &cos.Container{ + Format: "mp4", + }, + Video: &cos.Video{ + Codec: "H.264", + }, + Audio: &cos.Audio{ + Codec: "AAC", + }, + TimeInterval: &cos.TimeInterval{ + Start: "10", + Duration: "", + }, + }, + }, + QueueId: "paaf4fce5521a40888a3034a5de80f6ca", + } + createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt) + log_status(err) + fmt.Printf("%+v\n", createJobRes.JobsDetail) + + // DescribeMediaJobs + DescribeJobRes, _, err := c.CI.DescribeMediaJobs(context.Background(), createJobRes.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) +} \ No newline at end of file From d795d20dca35ef730c8b58ba8a1e7e27fd9810d3 Mon Sep 17 00:00:00 2001 From: wanjiewu Date: Thu, 4 Mar 2021 11:41:25 +0800 Subject: [PATCH 2/5] =?UTF-8?q?add:redeme=E9=87=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++ example/content_auditing/ci_video_auditing_job.go | 71 ++++++++++++ example/doc_process/ci_doc_process.go | 132 ++++++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 example/content_auditing/ci_video_auditing_job.go create mode 100644 example/doc_process/ci_doc_process.go diff --git a/README.md b/README.md index 0316a13..5210f36 100644 --- a/README.md +++ b/README.md @@ -93,3 +93,14 @@ Object API: * [x] Complete Multipart Upload(使用示例:[object/completeMultipartUpload.go](./example/object/completeMultipartUpload.go)) * [x] Abort Multipart Upload(使用示例:[object/abortMultipartUpload.go](./example/object/abortMultipartUpload.go)) * [x] Mutipart Upload(使用示例:[object/MutiUpload.go](./example/object/MutiUpload.go)) + + +数据处理 API: + +* [x] 媒体处理(使用示例:[ci_media.go](./example/media_process/media_process.go)) +* [x] 文档处理(使用示例:[ci_doc.go](./example/doc_process/ci_doc_process.go)) + + +内容审核 API: + +* [x] 视频审核(使用示例:[ci_doc.go](./example/content_auditing/ci_video_auditing_job.go)) \ No newline at end of file diff --git a/example/content_auditing/ci_video_auditing_job.go b/example/content_auditing/ci_video_auditing_job.go new file mode 100644 index 0000000..9a5cbb7 --- /dev/null +++ b/example/content_auditing/ci_video_auditing_job.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "net/url" + "os" + "time" + + "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 main() { + bu, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") + cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.myqcloud.com") + b := &cos.BaseURL{BucketURL: bu, 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, + RequestBody: true, + ResponseHeader: true, + ResponseBody: true, + }, + }, + }) + opt := &cos.PutVideoAuditingJobOptions{ + InputObject: "demo.mp4", + Conf: &cos.VideoAuditingJobConf{ + DetectType: "Porn,Terrorism,Politics,Ads", + Snapshot: &cos.PutVideoAuditingJobSnapshot{ + Mode: "Interval", + Start: 0.5, + TimeInterval: 50.5, + Count: 100, + }, + }, + } + + res, _, err := c.CI.PutVideoAuditingJob(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) + + time.Sleep(3 * time.Second) + res2, _, err := c.CI.GetVideoAuditingJob(context.Background(), res.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", res2) +} diff --git a/example/doc_process/ci_doc_process.go b/example/doc_process/ci_doc_process.go new file mode 100644 index 0000000..c743d64 --- /dev/null +++ b/example/doc_process/ci_doc_process.go @@ -0,0 +1,132 @@ +package main + +import ( + "context" + "fmt" + "io" + "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 main() { + u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") + cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.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, + }, + }, + }) + + // 1、UpdateDocProcessQueue + updateQueueOpt := &cos.UpdateDocProcessQueueOptions{ + Name: "queue-doc-process-1", + QueueID: "p111a8dd208104ce3b11c78398f658ca8", + State: "Active", + NotifyConfig: &cos.DocProcessQueueNotifyConfig{ + State: "Off", + }, + } + updateQueueRes, _, err := c.CI.UpdateDocProcessQueue(context.Background(), updateQueueOpt) + log_status(err) + fmt.Printf("%+v\n", updateQueueRes) + + // 2、DescribeDocProcessQueues + DescribeQueueOpt := &cos.DescribeDocProcessQueuesOptions{ + QueueIds: "p111a8dd208104ce3b11c78398f658ca8,p4318f85d2aa14c43b1dba6f9b78be9b3,aacb2bb066e9c4478834d4196e76c49d3", + PageNumber: 1, + PageSize: 2, + } + DescribeQueueRes, _, err := c.CI.DescribeDocProcessQueues(context.Background(), DescribeQueueOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeQueueRes) + + // 3、DescribeDocProcessBuckets + BucketsOpt := &cos.DescribeDocProcessBucketsOptions{ + Regions: "All", + } + BucketsRes, _, err := c.CI.DescribeDocProcessBuckets(context.Background(), BucketsOpt) + log_status(err) + fmt.Printf("%+v\n", BucketsRes) + + // 4、CreateDocProcessJobs + createJobOpt := &cos.CreateDocProcessJobsOptions{ + Tag: "DocProcess", + Input: &cos.DocProcessJobInput{ + Object: "form.pdf", + }, + Operation: &cos.DocProcessJobOperation{ + Output: &cos.DocProcessJobOutput{ + Region: "ap-guangzhou", + Object: "test-doc${Number}", + Bucket: "test-1259654469", + }, + DocProcess: &cos.DocProcessJobDocProcess{ + TgtType: "png", + StartPage: 1, + EndPage: -1, + ImageParams: "watermark/1/image/aHR0cDovL3Rlc3QwMDUtMTI1MTcwNDcwOC5jb3MuYXAtY2hvbmdxaW5nLm15cWNsb3VkLmNvbS8xLmpwZw==/gravity/southeast", + }, + }, + QueueId: "p111a8dd208104ce3b11c78398f658ca8", + } + createJobRes, _, err := c.CI.CreateDocProcessJobs(context.Background(), createJobOpt) + log_status(err) + fmt.Printf("%+v\n", createJobRes.JobsDetail) + + // 5、DescribeDocProcessJob + DescribeJobRes, _, err := c.CI.DescribeDocProcessJob(context.Background(), createJobRes.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) + + // 6、DescribeDocProcessJobs + DescribeJobsOpt := &cos.DescribeDocProcessJobsOptions{ + QueueId: "p111a8dd208104ce3b11c78398f658ca8", + Tag: "DocProcess", + } + DescribeJobsRes, _, err := c.CI.DescribeDocProcessJobs(context.Background(), DescribeJobsOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeJobsRes) + + // 7、doc-preview + opt := &cos.DocPreviewOptions{ + Page: 1, + } + resp, err := c.CI.DocPreview(context.Background(), "form.pdf", opt) + log_status(err) + fd, _ := os.OpenFile("form.pdf", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660) + io.Copy(fd, resp.Body) + fd.Close() + +} From a060fa03a93c6b7bb2e303e7c270fa0df8895e24 Mon Sep 17 00:00:00 2001 From: wanjiewu Date: Thu, 4 Mar 2021 11:43:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?add:redeme=E9=87=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5210f36..60b7262 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,10 @@ Object API: 数据处理 API: -* [x] 媒体处理(使用示例:[ci_media.go](./example/media_process/media_process.go)) -* [x] 文档处理(使用示例:[ci_doc.go](./example/doc_process/ci_doc_process.go)) +* [x] 媒体处理(使用示例:[media_process.go](./example/media_process/media_process.go)) +* [x] 文档处理(使用示例:[ci_doc_process.go](./example/doc_process/ci_doc_process.go)) 内容审核 API: -* [x] 视频审核(使用示例:[ci_doc.go](./example/content_auditing/ci_video_auditing_job.go)) \ No newline at end of file +* [x] 视频审核(使用示例:[ci_video_auditing_job.go](./example/content_auditing/ci_video_auditing_job.go)) \ No newline at end of file From 33b02c0be26631712f47c410e6d1f32f6fae477b Mon Sep 17 00:00:00 2001 From: jojoliang Date: Thu, 4 Mar 2021 12:51:30 +0800 Subject: [PATCH 4/5] update ci --- README.md | 6 +- ci_media.go | 189 ++++++++++----------- .../CI/content_auditing/ci_video_auditing_job.go | 71 ++++++++ example/CI/doc_process/ci_doc_process.go | 132 ++++++++++++++ example/CI/media_process/media_process.go | 98 +++++++++++ example/content_auditing/ci_video_auditing_job.go | 71 -------- example/doc_process/ci_doc_process.go | 132 -------------- example/media_process/media_process.go | 98 ----------- 8 files changed, 398 insertions(+), 399 deletions(-) create mode 100644 example/CI/content_auditing/ci_video_auditing_job.go create mode 100644 example/CI/doc_process/ci_doc_process.go create mode 100644 example/CI/media_process/media_process.go delete mode 100644 example/content_auditing/ci_video_auditing_job.go delete mode 100644 example/doc_process/ci_doc_process.go delete mode 100644 example/media_process/media_process.go diff --git a/README.md b/README.md index 60b7262..72b2b88 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,10 @@ Object API: 数据处理 API: -* [x] 媒体处理(使用示例:[media_process.go](./example/media_process/media_process.go)) -* [x] 文档处理(使用示例:[ci_doc_process.go](./example/doc_process/ci_doc_process.go)) +* [x] 媒体处理(使用示例:[media_process.go](./example/CI/media_process/media_process.go)) +* [x] 文档处理(使用示例:[ci_doc_process.go](./example/CI/doc_process/ci_doc_process.go)) 内容审核 API: -* [x] 视频审核(使用示例:[ci_video_auditing_job.go](./example/content_auditing/ci_video_auditing_job.go)) \ No newline at end of file +* [x] 视频审核(使用示例:[ci_video_auditing_job.go](./example/CI/content_auditing/ci_video_auditing_job.go)) diff --git a/ci_media.go b/ci_media.go index 3749d24..9a10c61 100644 --- a/ci_media.go +++ b/ci_media.go @@ -10,7 +10,7 @@ type JobInput struct { Object string `xml:"Object,omitempty"` } -type JobOutput struct { +type JobOutput struct { Region string `xml:"Region,omitempty"` Bucket string `xml:"Bucket,omitempty"` Object string `xml:"Object,omitempty"` @@ -21,114 +21,113 @@ type Container struct { } type Video struct { - Codec string `xml:"Codec"` - Width string `xml:"Width"` - Height string `xml:"Height"` - Fps string `xml:"Fps"` - Remove string `xml:"Remove"` - Profile string `xml:"Profile"` - Bitrate string `xml:"Bitrate"` - Crf string `xml:"Crf"` - Gop string `xml:"Gop"` - Preset string `xml:"Preset"` - Bufsize string `xml:"Bufsize"` - Maxrate string `xml:"Maxrate"` - HlsTsTime string `xml:"HlsTsTime"` - Pixfmt string `xml:"Pixfmt"` + Codec string `xml:"Codec"` + Width string `xml:"Width"` + Height string `xml:"Height"` + Fps string `xml:"Fps"` + Remove string `xml:"Remove"` + Profile string `xml:"Profile"` + Bitrate string `xml:"Bitrate"` + Crf string `xml:"Crf"` + Gop string `xml:"Gop"` + Preset string `xml:"Preset"` + Bufsize string `xml:"Bufsize"` + Maxrate string `xml:"Maxrate"` + HlsTsTime string `xml:"HlsTsTime"` + Pixfmt string `xml:"Pixfmt"` LongShortMode string `xml:"LongShortMode"` } type TimeInterval struct { - Start string `xml:"Start"` + Start string `xml:"Start"` Duration string `xml:"Duration"` } type Audio struct { - Codec string `xml:"Codec"` + Codec string `xml:"Codec"` Samplerate string `xml:"Samplerate"` - Bitrate string `xml:"Bitrate"` - Channels string `xml:"Channels"` - Remove string `xml:"Remove"` + Bitrate string `xml:"Bitrate"` + Channels string `xml:"Channels"` + Remove string `xml:"Remove"` } type TransConfig struct { - AdjDarMethod string `xml:"AdjDarMethod"` - IsCheckReso string `xml:"IsCheckReso"` - ResoAdjMethod string `xml:"ResoAdjMethod"` - IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"` + AdjDarMethod string `xml:"AdjDarMethod"` + IsCheckReso string `xml:"IsCheckReso"` + ResoAdjMethod string `xml:"ResoAdjMethod"` + IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"` VideoBitrateAdjMethod string `xml:"VideoBitrateAdjMethod"` - IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"` + IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"` AudioBitrateAdjMethod string `xml:"AudioBitrateAdjMethod"` } type Transcode struct { Container *Container `xml:"Container,omitempty"` - Video *Video `xml:"Video,omitempty"` + Video *Video `xml:"Video,omitempty"` TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"` - Audio *Audio `xml:"Audio,omitempty"` + Audio *Audio `xml:"Audio,omitempty"` TransConfig *TransConfig `xml:"TransConfig,omitempty"` } type Image struct { - Url string `xml:"Url,omitempty"` - Mode string `xml:"Mode,omitempty"` - Width string `xml:"Width,omitempty"` - Height string `xml:"Height,omitempty"` + Url string `xml:"Url,omitempty"` + Mode string `xml:"Mode,omitempty"` + Width string `xml:"Width,omitempty"` + Height string `xml:"Height,omitempty"` Transparency string `xml:"Transparency,omitempty"` - Background string `xml:"Background,omitempty"` + Background string `xml:"Background,omitempty"` } - type Text struct { - FontSize string `xml:"FontSize,omitempty"` - FontType string `xml:"FontType,omitempty"` - FontColor string `xml:"FontColor,omitempty"` + FontSize string `xml:"FontSize,omitempty"` + FontType string `xml:"FontType,omitempty"` + FontColor string `xml:"FontColor,omitempty"` Transparency string `xml:"Transparency,omitempty"` - Text string `xml:"Text,omitempty"` + Text string `xml:"Text,omitempty"` } type Watermark struct { - Type string `xml:"Type,omitempty"` - Pos string `xml:"Pos,omitempty"` - LocMode string `xml:"LocMode,omitempty"` - Dx string `xml:"Dx,omitempty"` - Dy string `xml:"Dy,omitempty"` + Type string `xml:"Type,omitempty"` + Pos string `xml:"Pos,omitempty"` + LocMode string `xml:"LocMode,omitempty"` + Dx string `xml:"Dx,omitempty"` + Dy string `xml:"Dy,omitempty"` StartTime string `xml:"StartTime,omitempty"` - EndTime string `xml:"EndTime,omitempty"` - Image *Image `xml:"Image,omitempty"` - Text *Text `xml:"Text,omitempty"` + EndTime string `xml:"EndTime,omitempty"` + Image *Image `xml:"Image,omitempty"` + Text *Text `xml:"Text,omitempty"` } type MediaProcessJobOperation struct { - Output *JobOutput `xml:"Output,omitempty"` - Transcode *Transcode `xml:"Transcode,omitempty"` - Watermark *Watermark `xml:"Watermark,omitempty"` - TemplateId string `xml:"TemplateId,omitempty"` - WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"` + Output *JobOutput `xml:"Output,omitempty"` + Transcode *Transcode `xml:"Transcode,omitempty"` + Watermark *Watermark `xml:"Watermark,omitempty"` + TemplateId string `xml:"TemplateId,omitempty"` + WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"` } type CreateMediaJobsOptions struct { - XMLName xml.Name `xml:"Request"` - Tag string `xml:"Tag,omitempty"` - Input *JobInput `xml:"Input,omitempty"` + XMLName xml.Name `xml:"Request"` + Tag string `xml:"Tag,omitempty"` + Input *JobInput `xml:"Input,omitempty"` Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` - QueueId string `xml:"QueueId,omitempty"` + QueueId string `xml:"QueueId,omitempty"` } type MediaProcessJobDetail struct { - Code string `xml:"Code,omitempty"` - Message string `xml:"Message,omitempty"` - JobId string `xml:"JobId,omitempty"` - Tag string `xml:"Tag,omitempty"` - State string `xml:"State,omitempty"` - CreationTime string `xml:"CreationTime,omitempty"` - QueueId string `xml:"QueueId,omitempty"` - Input *JobInput `xml:"Input,omitempty"` - Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` + Code string `xml:"Code,omitempty"` + Message string `xml:"Message,omitempty"` + JobId string `xml:"JobId,omitempty"` + Tag string `xml:"Tag,omitempty"` + State string `xml:"State,omitempty"` + CreationTime string `xml:"CreationTime,omitempty"` + QueueId string `xml:"QueueId,omitempty"` + Input *JobInput `xml:"Input,omitempty"` + Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` } type CreateMediaJobsResult struct { - XMLName xml.Name `xml:"Response"` + XMLName xml.Name `xml:"Response"` JobsDetail MediaProcessJobDetail `xml:"JobsDetail,omitempty"` } @@ -143,12 +142,12 @@ func (s *CIService) CreateMediaJobs(ctx context.Context, opt *CreateMediaJobsOpt } resp, err := s.client.send(ctx, &sendOpt) return &res, resp, err -} +} type DescribeMediaProcessJobResult struct { - XMLName xml.Name `xml:"Response"` + XMLName xml.Name `xml:"Response"` JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"` - NonExistJobIds string `xml:"NonExistJobIds,omitempty"` + NonExistJobIds string `xml:"NonExistJobIds,omitempty"` } func (s *CIService) DescribeMediaJobs(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) { @@ -201,23 +200,23 @@ type DescribeMediaProcessQueuesOptions struct { } type DescribeMediaProcessQueuesResult struct { - XMLName xml.Name `xml:"Response"` - RequestId string `xml:"RequestId,omitempty"` - TotalCount int `xml:"TotalCount,omitempty"` - PageNumber int `xml:"PageNumber,omitempty"` - PageSize int `xml:"PageSize,omitempty"` + XMLName xml.Name `xml:"Response"` + RequestId string `xml:"RequestId,omitempty"` + TotalCount int `xml:"TotalCount,omitempty"` + PageNumber int `xml:"PageNumber,omitempty"` + PageSize int `xml:"PageSize,omitempty"` QueueList []MediaProcessQueue `xml:"QueueList,omitempty"` - NonExistPIDs []string `xml:"NonExistPIDs,omitempty"` + NonExistPIDs []string `xml:"NonExistPIDs,omitempty"` } type MediaProcessQueue struct { - QueueId string `xml:"QueueId,omitempty"` - Name string `xml:"Name,omitempty"` - State string `xml:"State,omitempty"` - MaxSize int `xml:"MaxSize,omitempty"` - MaxConcurrent int `xml:"MaxConcurrent,omitempty"` - UpdateTime string `xml:"UpdateTime,omitempty"` - CreateTime string `xml:"CreateTime,omitempty"` + QueueId string `xml:"QueueId,omitempty"` + Name string `xml:"Name,omitempty"` + State string `xml:"State,omitempty"` + MaxSize int `xml:"MaxSize,omitempty"` + MaxConcurrent int `xml:"MaxConcurrent,omitempty"` + UpdateTime string `xml:"UpdateTime,omitempty"` + CreateTime string `xml:"CreateTime,omitempty"` NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"` } @@ -242,16 +241,16 @@ func (s *CIService) DescribeMediaProcessQueues(ctx context.Context, opt *Describ } type UpdateMediaProcessQueueOptions struct { - XMLName xml.Name `xml:"Request"` - Name string `xml:"Name,omitempty"` - QueueID string `xml:"QueueID,omitempty"` - State string `xml:"State,omitempty"` + XMLName xml.Name `xml:"Request"` + Name string `xml:"Name,omitempty"` + QueueID string `xml:"QueueID,omitempty"` + State string `xml:"State,omitempty"` NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"` } type UpdateMediaProcessQueueResult struct { - XMLName xml.Name `xml:"Response"` - RequestId string `xml:"RequestId"` + XMLName xml.Name `xml:"Response"` + RequestId string `xml:"RequestId"` Queue *MediaProcessQueue `xml:"Queue"` } @@ -277,17 +276,17 @@ type DescribeMediaProcessBucketsOptions struct { } type DescribeMediaProcessBucketsResult struct { - XMLName xml.Name `xml:"Response"` - RequestId string `xml:"RequestId,omitempty"` - TotalCount int `xml:"TotalCount,omitempty"` - PageNumber int `xml:"PageNumber,omitempty"` - PageSize int `xml:"PageSize,omitempty"` + XMLName xml.Name `xml:"Response"` + RequestId string `xml:"RequestId,omitempty"` + TotalCount int `xml:"TotalCount,omitempty"` + PageNumber int `xml:"PageNumber,omitempty"` + PageSize int `xml:"PageSize,omitempty"` MediaBucketList []MediaProcessBucket `xml:"MediaBucketList,omitempty"` } type MediaProcessBucket struct { - BucketId string `xml:"BucketId,omitempty"` - Region string `xml:"Region,omitempty"` - CreateTime string `xml:"CreateTime,omitempty"` + BucketId string `xml:"BucketId,omitempty"` + Region string `xml:"Region,omitempty"` + CreateTime string `xml:"CreateTime,omitempty"` } func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *DescribeMediaProcessBucketsOptions) (*DescribeMediaProcessBucketsResult, *Response, error) { @@ -301,4 +300,4 @@ func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *Descri } resp, err := s.client.send(ctx, &sendOpt) return &res, resp, err -} \ No newline at end of file +} diff --git a/example/CI/content_auditing/ci_video_auditing_job.go b/example/CI/content_auditing/ci_video_auditing_job.go new file mode 100644 index 0000000..9a5cbb7 --- /dev/null +++ b/example/CI/content_auditing/ci_video_auditing_job.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "net/url" + "os" + "time" + + "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 main() { + bu, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") + cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.myqcloud.com") + b := &cos.BaseURL{BucketURL: bu, 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, + RequestBody: true, + ResponseHeader: true, + ResponseBody: true, + }, + }, + }) + opt := &cos.PutVideoAuditingJobOptions{ + InputObject: "demo.mp4", + Conf: &cos.VideoAuditingJobConf{ + DetectType: "Porn,Terrorism,Politics,Ads", + Snapshot: &cos.PutVideoAuditingJobSnapshot{ + Mode: "Interval", + Start: 0.5, + TimeInterval: 50.5, + Count: 100, + }, + }, + } + + res, _, err := c.CI.PutVideoAuditingJob(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) + + time.Sleep(3 * time.Second) + res2, _, err := c.CI.GetVideoAuditingJob(context.Background(), res.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", res2) +} diff --git a/example/CI/doc_process/ci_doc_process.go b/example/CI/doc_process/ci_doc_process.go new file mode 100644 index 0000000..c743d64 --- /dev/null +++ b/example/CI/doc_process/ci_doc_process.go @@ -0,0 +1,132 @@ +package main + +import ( + "context" + "fmt" + "io" + "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 main() { + u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") + cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.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, + }, + }, + }) + + // 1、UpdateDocProcessQueue + updateQueueOpt := &cos.UpdateDocProcessQueueOptions{ + Name: "queue-doc-process-1", + QueueID: "p111a8dd208104ce3b11c78398f658ca8", + State: "Active", + NotifyConfig: &cos.DocProcessQueueNotifyConfig{ + State: "Off", + }, + } + updateQueueRes, _, err := c.CI.UpdateDocProcessQueue(context.Background(), updateQueueOpt) + log_status(err) + fmt.Printf("%+v\n", updateQueueRes) + + // 2、DescribeDocProcessQueues + DescribeQueueOpt := &cos.DescribeDocProcessQueuesOptions{ + QueueIds: "p111a8dd208104ce3b11c78398f658ca8,p4318f85d2aa14c43b1dba6f9b78be9b3,aacb2bb066e9c4478834d4196e76c49d3", + PageNumber: 1, + PageSize: 2, + } + DescribeQueueRes, _, err := c.CI.DescribeDocProcessQueues(context.Background(), DescribeQueueOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeQueueRes) + + // 3、DescribeDocProcessBuckets + BucketsOpt := &cos.DescribeDocProcessBucketsOptions{ + Regions: "All", + } + BucketsRes, _, err := c.CI.DescribeDocProcessBuckets(context.Background(), BucketsOpt) + log_status(err) + fmt.Printf("%+v\n", BucketsRes) + + // 4、CreateDocProcessJobs + createJobOpt := &cos.CreateDocProcessJobsOptions{ + Tag: "DocProcess", + Input: &cos.DocProcessJobInput{ + Object: "form.pdf", + }, + Operation: &cos.DocProcessJobOperation{ + Output: &cos.DocProcessJobOutput{ + Region: "ap-guangzhou", + Object: "test-doc${Number}", + Bucket: "test-1259654469", + }, + DocProcess: &cos.DocProcessJobDocProcess{ + TgtType: "png", + StartPage: 1, + EndPage: -1, + ImageParams: "watermark/1/image/aHR0cDovL3Rlc3QwMDUtMTI1MTcwNDcwOC5jb3MuYXAtY2hvbmdxaW5nLm15cWNsb3VkLmNvbS8xLmpwZw==/gravity/southeast", + }, + }, + QueueId: "p111a8dd208104ce3b11c78398f658ca8", + } + createJobRes, _, err := c.CI.CreateDocProcessJobs(context.Background(), createJobOpt) + log_status(err) + fmt.Printf("%+v\n", createJobRes.JobsDetail) + + // 5、DescribeDocProcessJob + DescribeJobRes, _, err := c.CI.DescribeDocProcessJob(context.Background(), createJobRes.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) + + // 6、DescribeDocProcessJobs + DescribeJobsOpt := &cos.DescribeDocProcessJobsOptions{ + QueueId: "p111a8dd208104ce3b11c78398f658ca8", + Tag: "DocProcess", + } + DescribeJobsRes, _, err := c.CI.DescribeDocProcessJobs(context.Background(), DescribeJobsOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeJobsRes) + + // 7、doc-preview + opt := &cos.DocPreviewOptions{ + Page: 1, + } + resp, err := c.CI.DocPreview(context.Background(), "form.pdf", opt) + log_status(err) + fd, _ := os.OpenFile("form.pdf", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660) + io.Copy(fd, resp.Body) + fd.Close() + +} diff --git a/example/CI/media_process/media_process.go b/example/CI/media_process/media_process.go new file mode 100644 index 0000000..476f7e7 --- /dev/null +++ b/example/CI/media_process/media_process.go @@ -0,0 +1,98 @@ +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 main() { + u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com") + cu, _ := url.Parse("https://wwj-cq-1253960454.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, + }, + }, + }) + fmt.Printf("%+v\n", os.Getenv("COS_SECRETID")) + // DescribeMediaProcessQueues + DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{ + QueueIds: "", + PageNumber: 1, + PageSize: 2, + } + DescribeQueueRes, _, err := c.CI.DescribeMediaProcessQueues(context.Background(), DescribeQueueOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeQueueRes) + // CreateMediaJobs + createJobOpt := &cos.CreateMediaJobsOptions{ + Tag: "Transcode", + Input: &cos.JobInput{ + Object: "input/117374C.mp4", + }, + Operation: &cos.MediaProcessJobOperation{ + Output: &cos.JobOutput{ + Region: "ap-chongqing", + Object: "output/go_117374C.mp4", + Bucket: "wwj-cq-1253960454", + }, + Transcode: &cos.Transcode{ + Container: &cos.Container{ + Format: "mp4", + }, + Video: &cos.Video{ + Codec: "H.264", + }, + Audio: &cos.Audio{ + Codec: "AAC", + }, + TimeInterval: &cos.TimeInterval{ + Start: "10", + Duration: "", + }, + }, + }, + QueueId: "paaf4fce5521a40888a3034a5de80f6ca", + } + createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt) + log_status(err) + fmt.Printf("%+v\n", createJobRes.JobsDetail) + + // DescribeMediaJobs + DescribeJobRes, _, err := c.CI.DescribeMediaJobs(context.Background(), createJobRes.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) +} diff --git a/example/content_auditing/ci_video_auditing_job.go b/example/content_auditing/ci_video_auditing_job.go deleted file mode 100644 index 9a5cbb7..0000000 --- a/example/content_auditing/ci_video_auditing_job.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "context" - "fmt" - "net/http" - "net/url" - "os" - "time" - - "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 main() { - bu, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") - cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.myqcloud.com") - b := &cos.BaseURL{BucketURL: bu, 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, - RequestBody: true, - ResponseHeader: true, - ResponseBody: true, - }, - }, - }) - opt := &cos.PutVideoAuditingJobOptions{ - InputObject: "demo.mp4", - Conf: &cos.VideoAuditingJobConf{ - DetectType: "Porn,Terrorism,Politics,Ads", - Snapshot: &cos.PutVideoAuditingJobSnapshot{ - Mode: "Interval", - Start: 0.5, - TimeInterval: 50.5, - Count: 100, - }, - }, - } - - res, _, err := c.CI.PutVideoAuditingJob(context.Background(), opt) - log_status(err) - fmt.Printf("%+v\n", res) - - time.Sleep(3 * time.Second) - res2, _, err := c.CI.GetVideoAuditingJob(context.Background(), res.JobsDetail.JobId) - log_status(err) - fmt.Printf("%+v\n", res2) -} diff --git a/example/doc_process/ci_doc_process.go b/example/doc_process/ci_doc_process.go deleted file mode 100644 index c743d64..0000000 --- a/example/doc_process/ci_doc_process.go +++ /dev/null @@ -1,132 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io" - "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 main() { - u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") - cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.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, - }, - }, - }) - - // 1、UpdateDocProcessQueue - updateQueueOpt := &cos.UpdateDocProcessQueueOptions{ - Name: "queue-doc-process-1", - QueueID: "p111a8dd208104ce3b11c78398f658ca8", - State: "Active", - NotifyConfig: &cos.DocProcessQueueNotifyConfig{ - State: "Off", - }, - } - updateQueueRes, _, err := c.CI.UpdateDocProcessQueue(context.Background(), updateQueueOpt) - log_status(err) - fmt.Printf("%+v\n", updateQueueRes) - - // 2、DescribeDocProcessQueues - DescribeQueueOpt := &cos.DescribeDocProcessQueuesOptions{ - QueueIds: "p111a8dd208104ce3b11c78398f658ca8,p4318f85d2aa14c43b1dba6f9b78be9b3,aacb2bb066e9c4478834d4196e76c49d3", - PageNumber: 1, - PageSize: 2, - } - DescribeQueueRes, _, err := c.CI.DescribeDocProcessQueues(context.Background(), DescribeQueueOpt) - log_status(err) - fmt.Printf("%+v\n", DescribeQueueRes) - - // 3、DescribeDocProcessBuckets - BucketsOpt := &cos.DescribeDocProcessBucketsOptions{ - Regions: "All", - } - BucketsRes, _, err := c.CI.DescribeDocProcessBuckets(context.Background(), BucketsOpt) - log_status(err) - fmt.Printf("%+v\n", BucketsRes) - - // 4、CreateDocProcessJobs - createJobOpt := &cos.CreateDocProcessJobsOptions{ - Tag: "DocProcess", - Input: &cos.DocProcessJobInput{ - Object: "form.pdf", - }, - Operation: &cos.DocProcessJobOperation{ - Output: &cos.DocProcessJobOutput{ - Region: "ap-guangzhou", - Object: "test-doc${Number}", - Bucket: "test-1259654469", - }, - DocProcess: &cos.DocProcessJobDocProcess{ - TgtType: "png", - StartPage: 1, - EndPage: -1, - ImageParams: "watermark/1/image/aHR0cDovL3Rlc3QwMDUtMTI1MTcwNDcwOC5jb3MuYXAtY2hvbmdxaW5nLm15cWNsb3VkLmNvbS8xLmpwZw==/gravity/southeast", - }, - }, - QueueId: "p111a8dd208104ce3b11c78398f658ca8", - } - createJobRes, _, err := c.CI.CreateDocProcessJobs(context.Background(), createJobOpt) - log_status(err) - fmt.Printf("%+v\n", createJobRes.JobsDetail) - - // 5、DescribeDocProcessJob - DescribeJobRes, _, err := c.CI.DescribeDocProcessJob(context.Background(), createJobRes.JobsDetail.JobId) - log_status(err) - fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) - - // 6、DescribeDocProcessJobs - DescribeJobsOpt := &cos.DescribeDocProcessJobsOptions{ - QueueId: "p111a8dd208104ce3b11c78398f658ca8", - Tag: "DocProcess", - } - DescribeJobsRes, _, err := c.CI.DescribeDocProcessJobs(context.Background(), DescribeJobsOpt) - log_status(err) - fmt.Printf("%+v\n", DescribeJobsRes) - - // 7、doc-preview - opt := &cos.DocPreviewOptions{ - Page: 1, - } - resp, err := c.CI.DocPreview(context.Background(), "form.pdf", opt) - log_status(err) - fd, _ := os.OpenFile("form.pdf", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660) - io.Copy(fd, resp.Body) - fd.Close() - -} diff --git a/example/media_process/media_process.go b/example/media_process/media_process.go deleted file mode 100644 index cab0ee5..0000000 --- a/example/media_process/media_process.go +++ /dev/null @@ -1,98 +0,0 @@ -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 main() { - u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com") - cu, _ := url.Parse("https://wwj-cq-1253960454.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, - }, - }, - }) - fmt.Printf("%+v\n", os.Getenv("COS_SECRETID")) - // DescribeMediaProcessQueues - DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{ - QueueIds: "", - PageNumber: 1, - PageSize: 2, - } - DescribeQueueRes, _, err := c.CI.DescribeMediaProcessQueues(context.Background(), DescribeQueueOpt) - log_status(err) - fmt.Printf("%+v\n", DescribeQueueRes) - // CreateMediaJobs - createJobOpt := &cos.CreateMediaJobsOptions{ - Tag: "Transcode", - Input: &cos.JobInput{ - Object: "input/117374C.mp4", - }, - Operation: &cos.MediaProcessJobOperation{ - Output: &cos.JobOutput{ - Region: "ap-chongqing", - Object: "output/go_117374C.mp4", - Bucket: "wwj-cq-1253960454", - }, - Transcode: &cos.Transcode{ - Container: &cos.Container{ - Format: "mp4", - }, - Video: &cos.Video{ - Codec: "H.264", - }, - Audio: &cos.Audio{ - Codec: "AAC", - }, - TimeInterval: &cos.TimeInterval{ - Start: "10", - Duration: "", - }, - }, - }, - QueueId: "paaf4fce5521a40888a3034a5de80f6ca", - } - createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt) - log_status(err) - fmt.Printf("%+v\n", createJobRes.JobsDetail) - - // DescribeMediaJobs - DescribeJobRes, _, err := c.CI.DescribeMediaJobs(context.Background(), createJobRes.JobsDetail.JobId) - log_status(err) - fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) -} \ No newline at end of file From deaede440c412277e93e9c0a891089ddb92381f3 Mon Sep 17 00:00:00 2001 From: jojoliang Date: Thu, 4 Mar 2021 14:26:50 +0800 Subject: [PATCH 5/5] update ci --- example/CI/media_process/media_process.go | 1 - 1 file changed, 1 deletion(-) diff --git a/example/CI/media_process/media_process.go b/example/CI/media_process/media_process.go index 476f7e7..15466b8 100644 --- a/example/CI/media_process/media_process.go +++ b/example/CI/media_process/media_process.go @@ -47,7 +47,6 @@ func main() { }, }, }) - fmt.Printf("%+v\n", os.Getenv("COS_SECRETID")) // DescribeMediaProcessQueues DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{ QueueIds: "",