Skip to content

Commit 50905a1

Browse files
authored
Merge pull request #106 from agin719/cos-v4-dev
Cos v4 dev
2 parents e0e66ae + deaede4 commit 50905a1

File tree

5 files changed

+614
-0
lines changed

5 files changed

+614
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@ Object API:
9393
* [x] Complete Multipart Upload(使用示例:[object/completeMultipartUpload.go](./example/object/completeMultipartUpload.go)
9494
* [x] Abort Multipart Upload(使用示例:[object/abortMultipartUpload.go](./example/object/abortMultipartUpload.go)
9595
* [x] Mutipart Upload(使用示例:[object/MutiUpload.go](./example/object/MutiUpload.go)
96+
97+
98+
数据处理 API:
99+
100+
* [x] 媒体处理(使用示例:[media_process.go](./example/CI/media_process/media_process.go)
101+
* [x] 文档处理(使用示例:[ci_doc_process.go](./example/CI/doc_process/ci_doc_process.go)
102+
103+
104+
内容审核 API:
105+
106+
* [x] 视频审核(使用示例:[ci_video_auditing_job.go](./example/CI/content_auditing/ci_video_auditing_job.go)

ci_media.go

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
package cos
2+
3+
import (
4+
"context"
5+
"encoding/xml"
6+
"net/http"
7+
)
8+
9+
type JobInput struct {
10+
Object string `xml:"Object,omitempty"`
11+
}
12+
13+
type JobOutput struct {
14+
Region string `xml:"Region,omitempty"`
15+
Bucket string `xml:"Bucket,omitempty"`
16+
Object string `xml:"Object,omitempty"`
17+
}
18+
19+
type Container struct {
20+
Format string `xml:"Format"`
21+
}
22+
23+
type Video struct {
24+
Codec string `xml:"Codec"`
25+
Width string `xml:"Width"`
26+
Height string `xml:"Height"`
27+
Fps string `xml:"Fps"`
28+
Remove string `xml:"Remove"`
29+
Profile string `xml:"Profile"`
30+
Bitrate string `xml:"Bitrate"`
31+
Crf string `xml:"Crf"`
32+
Gop string `xml:"Gop"`
33+
Preset string `xml:"Preset"`
34+
Bufsize string `xml:"Bufsize"`
35+
Maxrate string `xml:"Maxrate"`
36+
HlsTsTime string `xml:"HlsTsTime"`
37+
Pixfmt string `xml:"Pixfmt"`
38+
LongShortMode string `xml:"LongShortMode"`
39+
}
40+
41+
type TimeInterval struct {
42+
Start string `xml:"Start"`
43+
Duration string `xml:"Duration"`
44+
}
45+
46+
type Audio struct {
47+
Codec string `xml:"Codec"`
48+
Samplerate string `xml:"Samplerate"`
49+
Bitrate string `xml:"Bitrate"`
50+
Channels string `xml:"Channels"`
51+
Remove string `xml:"Remove"`
52+
}
53+
54+
type TransConfig struct {
55+
AdjDarMethod string `xml:"AdjDarMethod"`
56+
IsCheckReso string `xml:"IsCheckReso"`
57+
ResoAdjMethod string `xml:"ResoAdjMethod"`
58+
IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"`
59+
VideoBitrateAdjMethod string `xml:"VideoBitrateAdjMethod"`
60+
IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"`
61+
AudioBitrateAdjMethod string `xml:"AudioBitrateAdjMethod"`
62+
}
63+
64+
type Transcode struct {
65+
Container *Container `xml:"Container,omitempty"`
66+
Video *Video `xml:"Video,omitempty"`
67+
TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
68+
Audio *Audio `xml:"Audio,omitempty"`
69+
TransConfig *TransConfig `xml:"TransConfig,omitempty"`
70+
}
71+
72+
type Image struct {
73+
Url string `xml:"Url,omitempty"`
74+
Mode string `xml:"Mode,omitempty"`
75+
Width string `xml:"Width,omitempty"`
76+
Height string `xml:"Height,omitempty"`
77+
Transparency string `xml:"Transparency,omitempty"`
78+
Background string `xml:"Background,omitempty"`
79+
}
80+
81+
type Text struct {
82+
FontSize string `xml:"FontSize,omitempty"`
83+
FontType string `xml:"FontType,omitempty"`
84+
FontColor string `xml:"FontColor,omitempty"`
85+
Transparency string `xml:"Transparency,omitempty"`
86+
Text string `xml:"Text,omitempty"`
87+
}
88+
89+
type Watermark struct {
90+
Type string `xml:"Type,omitempty"`
91+
Pos string `xml:"Pos,omitempty"`
92+
LocMode string `xml:"LocMode,omitempty"`
93+
Dx string `xml:"Dx,omitempty"`
94+
Dy string `xml:"Dy,omitempty"`
95+
StartTime string `xml:"StartTime,omitempty"`
96+
EndTime string `xml:"EndTime,omitempty"`
97+
Image *Image `xml:"Image,omitempty"`
98+
Text *Text `xml:"Text,omitempty"`
99+
}
100+
101+
type MediaProcessJobOperation struct {
102+
Output *JobOutput `xml:"Output,omitempty"`
103+
Transcode *Transcode `xml:"Transcode,omitempty"`
104+
Watermark *Watermark `xml:"Watermark,omitempty"`
105+
TemplateId string `xml:"TemplateId,omitempty"`
106+
WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"`
107+
}
108+
109+
type CreateMediaJobsOptions struct {
110+
XMLName xml.Name `xml:"Request"`
111+
Tag string `xml:"Tag,omitempty"`
112+
Input *JobInput `xml:"Input,omitempty"`
113+
Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
114+
QueueId string `xml:"QueueId,omitempty"`
115+
}
116+
117+
type MediaProcessJobDetail struct {
118+
Code string `xml:"Code,omitempty"`
119+
Message string `xml:"Message,omitempty"`
120+
JobId string `xml:"JobId,omitempty"`
121+
Tag string `xml:"Tag,omitempty"`
122+
State string `xml:"State,omitempty"`
123+
CreationTime string `xml:"CreationTime,omitempty"`
124+
QueueId string `xml:"QueueId,omitempty"`
125+
Input *JobInput `xml:"Input,omitempty"`
126+
Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
127+
}
128+
129+
type CreateMediaJobsResult struct {
130+
XMLName xml.Name `xml:"Response"`
131+
JobsDetail MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
132+
}
133+
134+
func (s *CIService) CreateMediaJobs(ctx context.Context, opt *CreateMediaJobsOptions) (*CreateMediaJobsResult, *Response, error) {
135+
var res CreateMediaJobsResult
136+
sendOpt := sendOptions{
137+
baseURL: s.client.BaseURL.CIURL,
138+
uri: "/jobs",
139+
method: http.MethodPost,
140+
body: opt,
141+
result: &res,
142+
}
143+
resp, err := s.client.send(ctx, &sendOpt)
144+
return &res, resp, err
145+
}
146+
147+
type DescribeMediaProcessJobResult struct {
148+
XMLName xml.Name `xml:"Response"`
149+
JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
150+
NonExistJobIds string `xml:"NonExistJobIds,omitempty"`
151+
}
152+
153+
func (s *CIService) DescribeMediaJobs(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) {
154+
var res DescribeMediaProcessJobResult
155+
sendOpt := sendOptions{
156+
baseURL: s.client.BaseURL.CIURL,
157+
uri: "/jobs/" + jobid,
158+
method: http.MethodGet,
159+
result: &res,
160+
}
161+
resp, err := s.client.send(ctx, &sendOpt)
162+
return &res, resp, err
163+
}
164+
165+
type DescribeMediaProcessJobsOptions struct {
166+
QueueId string `url:"queueId,omitempty"`
167+
Tag string `url:"tag,omitempty"`
168+
OrderByTime string `url:"orderByTime,omitempty"`
169+
NextToken string `url:"nextToken,omitempty"`
170+
Size int `url:"size,omitempty"`
171+
States string `url:"states,omitempty"`
172+
StartCreationTime string `url:"startCreationTime,omitempty"`
173+
EndCreationTime string `url:"endCreationTime,omitempty"`
174+
}
175+
176+
type DescribeMediaProcessJobsResult struct {
177+
XMLName xml.Name `xml:"Response"`
178+
JobsDetail []DocProcessJobDetail `xml:"JobsDetail,omitempty"`
179+
NextToken string `xml:"NextToken,omitempty"`
180+
}
181+
182+
func (s *CIService) DescribeMediaProcessJobs(ctx context.Context, opt *DescribeMediaProcessJobsOptions) (*DescribeMediaProcessJobsResult, *Response, error) {
183+
var res DescribeMediaProcessJobsResult
184+
sendOpt := sendOptions{
185+
baseURL: s.client.BaseURL.CIURL,
186+
uri: "/jobs",
187+
optQuery: opt,
188+
method: http.MethodGet,
189+
result: &res,
190+
}
191+
resp, err := s.client.send(ctx, &sendOpt)
192+
return &res, resp, err
193+
}
194+
195+
type DescribeMediaProcessQueuesOptions struct {
196+
QueueIds string `url:"queueIds,omitempty"`
197+
State string `url:"state,omitempty"`
198+
PageNumber int `url:"pageNumber,omitempty"`
199+
PageSize int `url:"pageSize,omitempty"`
200+
}
201+
202+
type DescribeMediaProcessQueuesResult struct {
203+
XMLName xml.Name `xml:"Response"`
204+
RequestId string `xml:"RequestId,omitempty"`
205+
TotalCount int `xml:"TotalCount,omitempty"`
206+
PageNumber int `xml:"PageNumber,omitempty"`
207+
PageSize int `xml:"PageSize,omitempty"`
208+
QueueList []MediaProcessQueue `xml:"QueueList,omitempty"`
209+
NonExistPIDs []string `xml:"NonExistPIDs,omitempty"`
210+
}
211+
212+
type MediaProcessQueue struct {
213+
QueueId string `xml:"QueueId,omitempty"`
214+
Name string `xml:"Name,omitempty"`
215+
State string `xml:"State,omitempty"`
216+
MaxSize int `xml:"MaxSize,omitempty"`
217+
MaxConcurrent int `xml:"MaxConcurrent,omitempty"`
218+
UpdateTime string `xml:"UpdateTime,omitempty"`
219+
CreateTime string `xml:"CreateTime,omitempty"`
220+
NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
221+
}
222+
223+
type MediaProcessQueueNotifyConfig struct {
224+
Url string `xml:"Url,omitempty"`
225+
State string `xml:"State,omitempty"`
226+
Type string `xml:"Type,omitempty"`
227+
Event string `xml:"Event,omitempty"`
228+
}
229+
230+
func (s *CIService) DescribeMediaProcessQueues(ctx context.Context, opt *DescribeMediaProcessQueuesOptions) (*DescribeMediaProcessQueuesResult, *Response, error) {
231+
var res DescribeMediaProcessQueuesResult
232+
sendOpt := sendOptions{
233+
baseURL: s.client.BaseURL.CIURL,
234+
uri: "/queue",
235+
optQuery: opt,
236+
method: http.MethodGet,
237+
result: &res,
238+
}
239+
resp, err := s.client.send(ctx, &sendOpt)
240+
return &res, resp, err
241+
}
242+
243+
type UpdateMediaProcessQueueOptions struct {
244+
XMLName xml.Name `xml:"Request"`
245+
Name string `xml:"Name,omitempty"`
246+
QueueID string `xml:"QueueID,omitempty"`
247+
State string `xml:"State,omitempty"`
248+
NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
249+
}
250+
251+
type UpdateMediaProcessQueueResult struct {
252+
XMLName xml.Name `xml:"Response"`
253+
RequestId string `xml:"RequestId"`
254+
Queue *MediaProcessQueue `xml:"Queue"`
255+
}
256+
257+
func (s *CIService) UpdateMediaProcessQueue(ctx context.Context, opt *UpdateMediaProcessQueueOptions) (*UpdateMediaProcessQueueResult, *Response, error) {
258+
var res UpdateMediaProcessQueueResult
259+
sendOpt := sendOptions{
260+
baseURL: s.client.BaseURL.CIURL,
261+
uri: "/queue/" + opt.QueueID,
262+
body: opt,
263+
method: http.MethodPut,
264+
result: &res,
265+
}
266+
resp, err := s.client.send(ctx, &sendOpt)
267+
return &res, resp, err
268+
}
269+
270+
type DescribeMediaProcessBucketsOptions struct {
271+
Regions string `url:"regions,omitempty"`
272+
BucketNames string `url:"bucketNames,omitempty"`
273+
BucketName string `url:"bucketName,omitempty"`
274+
PageNumber int `url:"pageNumber,omitempty"`
275+
PageSize int `url:"pageSize,omitempty"`
276+
}
277+
278+
type DescribeMediaProcessBucketsResult struct {
279+
XMLName xml.Name `xml:"Response"`
280+
RequestId string `xml:"RequestId,omitempty"`
281+
TotalCount int `xml:"TotalCount,omitempty"`
282+
PageNumber int `xml:"PageNumber,omitempty"`
283+
PageSize int `xml:"PageSize,omitempty"`
284+
MediaBucketList []MediaProcessBucket `xml:"MediaBucketList,omitempty"`
285+
}
286+
type MediaProcessBucket struct {
287+
BucketId string `xml:"BucketId,omitempty"`
288+
Region string `xml:"Region,omitempty"`
289+
CreateTime string `xml:"CreateTime,omitempty"`
290+
}
291+
292+
func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *DescribeMediaProcessBucketsOptions) (*DescribeMediaProcessBucketsResult, *Response, error) {
293+
var res DescribeMediaProcessBucketsResult
294+
sendOpt := sendOptions{
295+
baseURL: s.client.BaseURL.CIURL,
296+
uri: "/mediabucket",
297+
optQuery: opt,
298+
method: http.MethodGet,
299+
result: &res,
300+
}
301+
resp, err := s.client.send(ctx, &sendOpt)
302+
return &res, resp, err
303+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"os"
9+
"time"
10+
11+
"github.com/tencentyun/cos-go-sdk-v5"
12+
"github.com/tencentyun/cos-go-sdk-v5/debug"
13+
)
14+
15+
func log_status(err error) {
16+
if err == nil {
17+
return
18+
}
19+
if cos.IsNotFoundError(err) {
20+
// WARN
21+
fmt.Println("WARN: Resource is not existed")
22+
} else if e, ok := cos.IsCOSError(err); ok {
23+
fmt.Printf("ERROR: Code: %v\n", e.Code)
24+
fmt.Printf("ERROR: Message: %v\n", e.Message)
25+
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
26+
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
27+
// ERROR
28+
} else {
29+
fmt.Printf("ERROR: %v\n", err)
30+
// ERROR
31+
}
32+
}
33+
34+
func main() {
35+
bu, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
36+
cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.myqcloud.com")
37+
b := &cos.BaseURL{BucketURL: bu, CIURL: cu}
38+
c := cos.NewClient(b, &http.Client{
39+
Transport: &cos.AuthorizationTransport{
40+
SecretID: os.Getenv("COS_SECRETID"),
41+
SecretKey: os.Getenv("COS_SECRETKEY"),
42+
Transport: &debug.DebugRequestTransport{
43+
RequestHeader: true,
44+
RequestBody: true,
45+
ResponseHeader: true,
46+
ResponseBody: true,
47+
},
48+
},
49+
})
50+
opt := &cos.PutVideoAuditingJobOptions{
51+
InputObject: "demo.mp4",
52+
Conf: &cos.VideoAuditingJobConf{
53+
DetectType: "Porn,Terrorism,Politics,Ads",
54+
Snapshot: &cos.PutVideoAuditingJobSnapshot{
55+
Mode: "Interval",
56+
Start: 0.5,
57+
TimeInterval: 50.5,
58+
Count: 100,
59+
},
60+
},
61+
}
62+
63+
res, _, err := c.CI.PutVideoAuditingJob(context.Background(), opt)
64+
log_status(err)
65+
fmt.Printf("%+v\n", res)
66+
67+
time.Sleep(3 * time.Second)
68+
res2, _, err := c.CI.GetVideoAuditingJob(context.Background(), res.JobsDetail.JobId)
69+
log_status(err)
70+
fmt.Printf("%+v\n", res2)
71+
}

0 commit comments

Comments
 (0)