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.

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