You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

502 lines
18 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type JobInput struct {
  8. Object string `xml:"Object,omitempty"`
  9. }
  10. type JobOutput struct {
  11. Region string `xml:"Region,omitempty"`
  12. Bucket string `xml:"Bucket,omitempty"`
  13. Object string `xml:"Object,omitempty"`
  14. }
  15. type Container struct {
  16. Format string `xml:"Format"`
  17. }
  18. type Video struct {
  19. Codec string `xml:"Codec"`
  20. Width string `xml:"Width"`
  21. Height string `xml:"Height"`
  22. Fps string `xml:"Fps"`
  23. Remove string `xml:"Remove,omitempty"`
  24. Profile string `xml:"Profile"`
  25. Bitrate string `xml:"Bitrate"`
  26. Crf string `xml:"Crf"`
  27. Gop string `xml:"Gop"`
  28. Preset string `xml:"Preset"`
  29. Bufsize string `xml:"Bufsize"`
  30. Maxrate string `xml:"Maxrate"`
  31. HlsTsTime string `xml:"HlsTsTime"`
  32. Pixfmt string `xml:"Pixfmt"`
  33. LongShortMode string `xml:"LongShortMode"`
  34. }
  35. type TimeInterval struct {
  36. Start string `xml:"Start"`
  37. Duration string `xml:"Duration"`
  38. }
  39. type Audio struct {
  40. Codec string `xml:"Codec"`
  41. Samplerate string `xml:"Samplerate"`
  42. Bitrate string `xml:"Bitrate"`
  43. Channels string `xml:"Channels"`
  44. Remove string `xml:"Remove,omitempty"`
  45. }
  46. type TransConfig struct {
  47. AdjDarMethod string `xml:"AdjDarMethod"`
  48. IsCheckReso string `xml:"IsCheckReso"`
  49. ResoAdjMethod string `xml:"ResoAdjMethod"`
  50. IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"`
  51. VideoBitrateAdjMethod string `xml:"VideoBitrateAdjMethod"`
  52. IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"`
  53. AudioBitrateAdjMethod string `xml:"AudioBitrateAdjMethod"`
  54. }
  55. type Transcode struct {
  56. Container *Container `xml:"Container,omitempty"`
  57. Video *Video `xml:"Video,omitempty"`
  58. TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
  59. Audio *Audio `xml:"Audio,omitempty"`
  60. TransConfig *TransConfig `xml:"TransConfig,omitempty"`
  61. }
  62. type Image struct {
  63. Url string `xml:"Url,omitempty"`
  64. Mode string `xml:"Mode,omitempty"`
  65. Width string `xml:"Width,omitempty"`
  66. Height string `xml:"Height,omitempty"`
  67. Transparency string `xml:"Transparency,omitempty"`
  68. Background string `xml:"Background,omitempty"`
  69. }
  70. type Text struct {
  71. FontSize string `xml:"FontSize,omitempty"`
  72. FontType string `xml:"FontType,omitempty"`
  73. FontColor string `xml:"FontColor,omitempty"`
  74. Transparency string `xml:"Transparency,omitempty"`
  75. Text string `xml:"Text,omitempty"`
  76. }
  77. type Watermark struct {
  78. Type string `xml:"Type,omitempty"`
  79. Pos string `xml:"Pos,omitempty"`
  80. LocMode string `xml:"LocMode,omitempty"`
  81. Dx string `xml:"Dx,omitempty"`
  82. Dy string `xml:"Dy,omitempty"`
  83. StartTime string `xml:"StartTime,omitempty"`
  84. EndTime string `xml:"EndTime,omitempty"`
  85. Image *Image `xml:"Image,omitempty"`
  86. Text *Text `xml:"Text,omitempty"`
  87. }
  88. type ConcatFragment struct {
  89. Url string `xml:"Url,omitempty"`
  90. StartTime string `xml:"StartTime,omitempty"`
  91. EndTime string `xml:"EndTime,omitempty"`
  92. }
  93. type ConcatTemplate struct {
  94. ConcatFragment []ConcatFragment `xml:"ConcatFragment,omitempty"`
  95. Audio *Audio `xml:"Audio,omitempty"`
  96. Video *Video `xml:"Video,omitempty"`
  97. Container *Container `xml:"Container,omitempty"`
  98. Index string `xml:"Index,omitempty"`
  99. }
  100. type Snapshot struct {
  101. Mode string `xml:"Mode,omitempty"`
  102. Start string `xml:"Start,omitempty"`
  103. TimeInterval string `xml:"TimeInterval,omitempty"`
  104. Count string `xml:"Count,omitempty"`
  105. Width string `xml:"Width,omitempty"`
  106. Height string `xml:"Height,omitempty"`
  107. }
  108. // 有意和转码区分,两种任务关注的参数不一样避免干扰
  109. type AnimationVideo struct {
  110. Codec string `xml:"Codec"`
  111. Width string `xml:"Width"`
  112. Height string `xml:"Height"`
  113. Fps string `xml:"Fps"`
  114. AnimateOnlyKeepKeyFrame string `xml:"AnimateOnlyKeepKeyFrame"`
  115. AnimateTimeIntervalOfFrame string `xml:"AnimateTimeIntervalOfFrame"`
  116. AnimateFramesPerSecond string `xml:"AnimateFramesPerSecond"`
  117. Quality string `xml:"Quality"`
  118. }
  119. type Animation struct {
  120. Container *Container `xml:"Container,omitempty"`
  121. Video *AnimationVideo `xml:"Video,omitempty"`
  122. TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
  123. }
  124. type MediaProcessJobOperation struct {
  125. Tag string `xml:"Tag,omitempty"`
  126. Output *JobOutput `xml:"Output,omitempty"`
  127. Transcode *Transcode `xml:"Transcode,omitempty"`
  128. Watermark *Watermark `xml:"Watermark,omitempty"`
  129. TemplateId string `xml:"TemplateId,omitempty"`
  130. WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"`
  131. ConcatTemplate *ConcatTemplate `xml:"ConcatTemplate,omitempty"`
  132. Snapshot *Snapshot `xml:"Snapshot,omitempty"`
  133. Animation *Animation `xml:"Animation,omitempty"`
  134. }
  135. type CreateMediaJobsOptions struct {
  136. XMLName xml.Name `xml:"Request"`
  137. Tag string `xml:"Tag,omitempty"`
  138. Input *JobInput `xml:"Input,omitempty"`
  139. Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
  140. QueueId string `xml:"QueueId,omitempty"`
  141. CallBack string `xml:"CallBack,omitempty"`
  142. }
  143. type MediaProcessJobDetail struct {
  144. Code string `xml:"Code,omitempty"`
  145. Message string `xml:"Message,omitempty"`
  146. JobId string `xml:"JobId,omitempty"`
  147. Tag string `xml:"Tag,omitempty"`
  148. State string `xml:"State,omitempty"`
  149. CreationTime string `xml:"CreationTime,omitempty"`
  150. QueueId string `xml:"QueueId,omitempty"`
  151. Input *JobInput `xml:"Input,omitempty"`
  152. Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
  153. }
  154. type CreateMediaJobsResult struct {
  155. XMLName xml.Name `xml:"Response"`
  156. JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  157. }
  158. type CreateMultiMediaJobsOptions struct {
  159. XMLName xml.Name `xml:"Request"`
  160. Tag string `xml:"Tag,omitempty"`
  161. Input *JobInput `xml:"Input,omitempty"`
  162. Operation []MediaProcessJobOperation `xml:"Operation,omitempty"`
  163. QueueId string `xml:"QueueId,omitempty"`
  164. CallBack string `xml:"CallBack,omitempty"`
  165. }
  166. type CreateMultiMediaJobsResult struct {
  167. XMLName xml.Name `xml:"Response"`
  168. JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  169. }
  170. type MediaProcessJobsNotifyBody struct {
  171. XMLName xml.Name `xml:"Response"`
  172. EventName string `xml:"EventName"`
  173. JobsDetail struct {
  174. Code string `xml:"Code"`
  175. CreationTime string `xml:"CreationTime"`
  176. EndTime string `xml:"EndTime"`
  177. Input struct {
  178. BucketId string `xml:"BucketId"`
  179. Object string `xml:"Object"`
  180. Region string `xml:"Region"`
  181. } `xml:"Input"`
  182. JobId string `xml:"JobId"`
  183. Message string `xml:"Message"`
  184. Operation struct {
  185. MediaInfo struct {
  186. Format struct {
  187. Text string `xml:",chardata"`
  188. Bitrate string `xml:"Bitrate"`
  189. Duration string `xml:"Duration"`
  190. FormatLongName string `xml:"FormatLongName"`
  191. FormatName string `xml:"FormatName"`
  192. NumProgram string `xml:"NumProgram"`
  193. NumStream string `xml:"NumStream"`
  194. Size string `xml:"Size"`
  195. StartTime string `xml:"StartTime"`
  196. } `xml:"Format"`
  197. Stream struct {
  198. Audio []struct {
  199. Bitrate string `xml:"Bitrate"`
  200. Channel string `xml:"Channel"`
  201. ChannelLayout string `xml:"ChannelLayout"`
  202. CodecLongName string `xml:"CodecLongName"`
  203. CodecName string `xml:"CodecName"`
  204. CodecTag string `xml:"CodecTag"`
  205. CodecTagString string `xml:"CodecTagString"`
  206. CodecTimeBase string `xml:"CodecTimeBase"`
  207. Duration string `xml:"Duration"`
  208. Index string `xml:"Index"`
  209. Language string `xml:"Language"`
  210. SampleFmt string `xml:"SampleFmt"`
  211. SampleRate string `xml:"SampleRate"`
  212. StartTime string `xml:"StartTime"`
  213. Timebase string `xml:"Timebase"`
  214. } `xml:"Audio"`
  215. Subtitle string `xml:"Subtitle"`
  216. Video []struct {
  217. AvgFps string `xml:"AvgFps"`
  218. Bitrate string `xml:"Bitrate"`
  219. CodecLongName string `xml:"CodecLongName"`
  220. CodecName string `xml:"CodecName"`
  221. CodecTag string `xml:"CodecTag"`
  222. CodecTagString string `xml:"CodecTagString"`
  223. CodecTimeBase string `xml:"CodecTimeBase"`
  224. Dar string `xml:"Dar"`
  225. Duration string `xml:"Duration"`
  226. Fps string `xml:"Fps"`
  227. HasBFrame string `xml:"HasBFrame"`
  228. Height string `xml:"Height"`
  229. Index string `xml:"Index"`
  230. Language string `xml:"Language"`
  231. Level string `xml:"Level"`
  232. NumFrames string `xml:"NumFrames"`
  233. PixFormat string `xml:"PixFormat"`
  234. Profile string `xml:"Profile"`
  235. RefFrames string `xml:"RefFrames"`
  236. Rotation string `xml:"Rotation"`
  237. Sar string `xml:"Sar"`
  238. StartTime string `xml:"StartTime"`
  239. Timebase string `xml:"Timebase"`
  240. Width string `xml:"Width"`
  241. } `xml:"Video"`
  242. } `xml:"Stream"`
  243. } `xml:"MediaInfo"`
  244. MediaResult struct {
  245. OutputFile struct {
  246. Bucket string `xml:"Bucket"`
  247. ObjectName string `xml:"ObjectName"`
  248. ObjectPrefix string `xml:"ObjectPrefix"`
  249. Region string `xml:"Region"`
  250. } `xml:"OutputFile"`
  251. } `xml:"MediaResult"`
  252. Output struct {
  253. Bucket string `xml:"Bucket"`
  254. Object string `xml:"Object"`
  255. Region string `xml:"Region"`
  256. } `xml:"Output"`
  257. TemplateId string `xml:"TemplateId"`
  258. TemplateName string `xml:"TemplateName"`
  259. } `xml:"Operation"`
  260. QueueId string `xml:"QueueId"`
  261. StartTime string `xml:"StartTime"`
  262. State string `xml:"State"`
  263. Tag string `xml:"Tag"`
  264. } `xml:"JobsDetail"`
  265. }
  266. type WorkflowExecutionNotifyBody struct {
  267. XMLName xml.Name `xml:"Response"`
  268. EventName string `xml:"EventName"`
  269. WorkflowExecution struct {
  270. RunId string `xml:"RunId"`
  271. BucketId string `xml:"BucketId"`
  272. Object string `xml:"Object"`
  273. CosHeaders []struct {
  274. Key string `xml:"Key"`
  275. Value string `xml:"Value"`
  276. } `xml:"CosHeaders"`
  277. WorkflowId string `xml:"WorkflowId"`
  278. WorkflowName string `xml:"WorkflowName"`
  279. CreateTime string `xml:"CreateTime"`
  280. State string `xml:"State"`
  281. Tasks []struct {
  282. Type string `xml:"Type"`
  283. CreateTime string `xml:"CreateTime"`
  284. EndTime string `xml:"EndTime"`
  285. State string `xml:"State"`
  286. JobId string `xml:"JobId"`
  287. Name string `xml:"Name"`
  288. TemplateId string `xml:"TemplateId"`
  289. TemplateName string `xml:"TemplateName"`
  290. TranscodeTemplateId string `xml:"TranscodeTemplateId,omitempty"`
  291. TranscodeTemplateName string `xml:"TranscodeTemplateName,omitempty"`
  292. HdrMode string `xml:"HdrMode,omitempty"`
  293. } `xml:"Tasks"`
  294. } `xml:"WorkflowExecution"`
  295. }
  296. func (s *CIService) CreateMultiMediaJobs(ctx context.Context, opt *CreateMultiMediaJobsOptions) (*CreateMultiMediaJobsResult, *Response, error) {
  297. var res CreateMultiMediaJobsResult
  298. sendOpt := sendOptions{
  299. baseURL: s.client.BaseURL.CIURL,
  300. uri: "/jobs",
  301. method: http.MethodPost,
  302. body: opt,
  303. result: &res,
  304. }
  305. resp, err := s.client.send(ctx, &sendOpt)
  306. return &res, resp, err
  307. }
  308. func (s *CIService) CreateMediaJobs(ctx context.Context, opt *CreateMediaJobsOptions) (*CreateMediaJobsResult, *Response, error) {
  309. var res CreateMediaJobsResult
  310. sendOpt := sendOptions{
  311. baseURL: s.client.BaseURL.CIURL,
  312. uri: "/jobs",
  313. method: http.MethodPost,
  314. body: opt,
  315. result: &res,
  316. }
  317. resp, err := s.client.send(ctx, &sendOpt)
  318. return &res, resp, err
  319. }
  320. type DescribeMediaProcessJobResult struct {
  321. XMLName xml.Name `xml:"Response"`
  322. JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  323. NonExistJobIds string `xml:"NonExistJobIds,omitempty"`
  324. }
  325. func (s *CIService) DescribeMediaJob(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) {
  326. var res DescribeMediaProcessJobResult
  327. sendOpt := sendOptions{
  328. baseURL: s.client.BaseURL.CIURL,
  329. uri: "/jobs/" + jobid,
  330. method: http.MethodGet,
  331. result: &res,
  332. }
  333. resp, err := s.client.send(ctx, &sendOpt)
  334. return &res, resp, err
  335. }
  336. type DescribeMediaJobsOptions struct {
  337. QueueId string `url:"queueId,omitempty"`
  338. Tag string `url:"tag,omitempty"`
  339. OrderByTime string `url:"orderByTime,omitempty"`
  340. NextToken string `url:"nextToken,omitempty"`
  341. Size int `url:"size,omitempty"`
  342. States string `url:"states,omitempty"`
  343. StartCreationTime string `url:"startCreationTime,omitempty"`
  344. EndCreationTime string `url:"endCreationTime,omitempty"`
  345. }
  346. type DescribeMediaJobsResult struct {
  347. XMLName xml.Name `xml:"Response"`
  348. JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  349. NextToken string `xml:"NextToken,omitempty"`
  350. }
  351. func (s *CIService) DescribeMediaJobs(ctx context.Context, opt *DescribeMediaJobsOptions) (*DescribeMediaJobsResult, *Response, error) {
  352. var res DescribeMediaJobsResult
  353. sendOpt := sendOptions{
  354. baseURL: s.client.BaseURL.CIURL,
  355. uri: "/jobs",
  356. optQuery: opt,
  357. method: http.MethodGet,
  358. result: &res,
  359. }
  360. resp, err := s.client.send(ctx, &sendOpt)
  361. return &res, resp, err
  362. }
  363. type DescribeMediaProcessQueuesOptions struct {
  364. QueueIds string `url:"queueIds,omitempty"`
  365. State string `url:"state,omitempty"`
  366. PageNumber int `url:"pageNumber,omitempty"`
  367. PageSize int `url:"pageSize,omitempty"`
  368. }
  369. type DescribeMediaProcessQueuesResult struct {
  370. XMLName xml.Name `xml:"Response"`
  371. RequestId string `xml:"RequestId,omitempty"`
  372. TotalCount int `xml:"TotalCount,omitempty"`
  373. PageNumber int `xml:"PageNumber,omitempty"`
  374. PageSize int `xml:"PageSize,omitempty"`
  375. QueueList []MediaProcessQueue `xml:"QueueList,omitempty"`
  376. NonExistPIDs []string `xml:"NonExistPIDs,omitempty"`
  377. }
  378. type MediaProcessQueue struct {
  379. QueueId string `xml:"QueueId,omitempty"`
  380. Name string `xml:"Name,omitempty"`
  381. State string `xml:"State,omitempty"`
  382. MaxSize int `xml:"MaxSize,omitempty"`
  383. MaxConcurrent int `xml:"MaxConcurrent,omitempty"`
  384. UpdateTime string `xml:"UpdateTime,omitempty"`
  385. CreateTime string `xml:"CreateTime,omitempty"`
  386. NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
  387. }
  388. type MediaProcessQueueNotifyConfig struct {
  389. Url string `xml:"Url,omitempty"`
  390. State string `xml:"State,omitempty"`
  391. Type string `xml:"Type,omitempty"`
  392. Event string `xml:"Event,omitempty"`
  393. }
  394. func (s *CIService) DescribeMediaProcessQueues(ctx context.Context, opt *DescribeMediaProcessQueuesOptions) (*DescribeMediaProcessQueuesResult, *Response, error) {
  395. var res DescribeMediaProcessQueuesResult
  396. sendOpt := sendOptions{
  397. baseURL: s.client.BaseURL.CIURL,
  398. uri: "/queue",
  399. optQuery: opt,
  400. method: http.MethodGet,
  401. result: &res,
  402. }
  403. resp, err := s.client.send(ctx, &sendOpt)
  404. return &res, resp, err
  405. }
  406. type UpdateMediaProcessQueueOptions struct {
  407. XMLName xml.Name `xml:"Request"`
  408. Name string `xml:"Name,omitempty"`
  409. QueueID string `xml:"QueueID,omitempty"`
  410. State string `xml:"State,omitempty"`
  411. NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
  412. }
  413. type UpdateMediaProcessQueueResult struct {
  414. XMLName xml.Name `xml:"Response"`
  415. RequestId string `xml:"RequestId"`
  416. Queue *MediaProcessQueue `xml:"Queue"`
  417. }
  418. func (s *CIService) UpdateMediaProcessQueue(ctx context.Context, opt *UpdateMediaProcessQueueOptions) (*UpdateMediaProcessQueueResult, *Response, error) {
  419. var res UpdateMediaProcessQueueResult
  420. sendOpt := sendOptions{
  421. baseURL: s.client.BaseURL.CIURL,
  422. uri: "/queue/" + opt.QueueID,
  423. body: opt,
  424. method: http.MethodPut,
  425. result: &res,
  426. }
  427. resp, err := s.client.send(ctx, &sendOpt)
  428. return &res, resp, err
  429. }
  430. type DescribeMediaProcessBucketsOptions struct {
  431. Regions string `url:"regions,omitempty"`
  432. BucketNames string `url:"bucketNames,omitempty"`
  433. BucketName string `url:"bucketName,omitempty"`
  434. PageNumber int `url:"pageNumber,omitempty"`
  435. PageSize int `url:"pageSize,omitempty"`
  436. }
  437. type DescribeMediaProcessBucketsResult struct {
  438. XMLName xml.Name `xml:"Response"`
  439. RequestId string `xml:"RequestId,omitempty"`
  440. TotalCount int `xml:"TotalCount,omitempty"`
  441. PageNumber int `xml:"PageNumber,omitempty"`
  442. PageSize int `xml:"PageSize,omitempty"`
  443. MediaBucketList []MediaProcessBucket `xml:"MediaBucketList,omitempty"`
  444. }
  445. type MediaProcessBucket struct {
  446. BucketId string `xml:"BucketId,omitempty"`
  447. Region string `xml:"Region,omitempty"`
  448. CreateTime string `xml:"CreateTime,omitempty"`
  449. }
  450. func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *DescribeMediaProcessBucketsOptions) (*DescribeMediaProcessBucketsResult, *Response, error) {
  451. var res DescribeMediaProcessBucketsResult
  452. sendOpt := sendOptions{
  453. baseURL: s.client.BaseURL.CIURL,
  454. uri: "/mediabucket",
  455. optQuery: opt,
  456. method: http.MethodGet,
  457. result: &res,
  458. }
  459. resp, err := s.client.send(ctx, &sendOpt)
  460. return &res, resp, err
  461. }