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.

97 lines
2.5 KiB

4 years ago
4 years ago
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "net/http"
  6. "net/url"
  7. "os"
  8. "github.com/tencentyun/cos-go-sdk-v5"
  9. "github.com/tencentyun/cos-go-sdk-v5/debug"
  10. )
  11. func log_status(err error) {
  12. if err == nil {
  13. return
  14. }
  15. if cos.IsNotFoundError(err) {
  16. // WARN
  17. fmt.Println("WARN: Resource is not existed")
  18. } else if e, ok := cos.IsCOSError(err); ok {
  19. fmt.Printf("ERROR: Code: %v\n", e.Code)
  20. fmt.Printf("ERROR: Message: %v\n", e.Message)
  21. fmt.Printf("ERROR: Resource: %v\n", e.Resource)
  22. fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
  23. // ERROR
  24. } else {
  25. fmt.Printf("ERROR: %v\n", err)
  26. // ERROR
  27. }
  28. }
  29. func main() {
  30. u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com")
  31. cu, _ := url.Parse("https://wwj-cq-1253960454.ci.ap-chongqing.myqcloud.com")
  32. b := &cos.BaseURL{BucketURL: u, CIURL: cu}
  33. c := cos.NewClient(b, &http.Client{
  34. Transport: &cos.AuthorizationTransport{
  35. SecretID: os.Getenv("COS_SECRETID"),
  36. SecretKey: os.Getenv("COS_SECRETKEY"),
  37. Transport: &debug.DebugRequestTransport{
  38. RequestHeader: true,
  39. // Notice when put a large file and set need the request body, might happend out of memory error.
  40. RequestBody: true,
  41. ResponseHeader: true,
  42. ResponseBody: true,
  43. },
  44. },
  45. })
  46. // DescribeMediaProcessQueues
  47. DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{
  48. QueueIds: "",
  49. PageNumber: 1,
  50. PageSize: 2,
  51. }
  52. DescribeQueueRes, _, err := c.CI.DescribeMediaProcessQueues(context.Background(), DescribeQueueOpt)
  53. log_status(err)
  54. fmt.Printf("%+v\n", DescribeQueueRes)
  55. // CreateMediaJobs
  56. createJobOpt := &cos.CreateMediaJobsOptions{
  57. Tag: "Transcode",
  58. Input: &cos.JobInput{
  59. Object: "input/117374C.mp4",
  60. },
  61. Operation: &cos.MediaProcessJobOperation{
  62. Output: &cos.JobOutput{
  63. Region: "ap-chongqing",
  64. Object: "output/go_117374C.mp4",
  65. Bucket: "wwj-cq-1253960454",
  66. },
  67. Transcode: &cos.Transcode{
  68. Container: &cos.Container{
  69. Format: "mp4",
  70. },
  71. Video: &cos.Video{
  72. Codec: "H.264",
  73. },
  74. Audio: &cos.Audio{
  75. Codec: "AAC",
  76. },
  77. TimeInterval: &cos.TimeInterval{
  78. Start: "10",
  79. Duration: "",
  80. },
  81. },
  82. },
  83. QueueId: "paaf4fce5521a40888a3034a5de80f6ca",
  84. }
  85. createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt)
  86. log_status(err)
  87. fmt.Printf("%+v\n", createJobRes.JobsDetail)
  88. // DescribeMediaJobs
  89. DescribeJobRes, _, err := c.CI.DescribeMediaJobs(context.Background(), createJobRes.JobsDetail.JobId)
  90. log_status(err)
  91. fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
  92. }