全部产品
云市场

媒资管理

更新时间:2018-12-30 18:05:12

初始化客户端

使用前请先初始化客户端,参考 InitVodClient 接口。

搜索媒资信息

接口参数和返回字段请参考 SearchMedia

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MySearchMedia(client *vod.Client) (response *vod.SearchMediaResponse, err error) {
  9. request := vod.CreateSearchMediaRequest()
  10. request.Fields = "Title,CoverURL,Status"
  11. request.Match = "Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')"
  12. request.PageNo = "1"
  13. request.PageSize = "10"
  14. request.SearchType = "video"
  15. request.SortBy = "CreationTime:Desc"
  16. request.AcceptFormat = "JSON"
  17. return client.SearchMedia(request)
  18. }
  19. func main() {
  20. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  21. if err != nil {
  22. panic(err)
  23. }
  24. response, err := MySearchMedia(client)
  25. if err != nil {
  26. panic(err)
  27. }
  28. fmt.Println(response.GetHttpContentString())
  29. //fmt.Println(response.MediaList)
  30. }

获取视频信息

接口参数和返回字段请参考 GetVideoInfo

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetVideoInfo(client *vod.Client) (response *vod.GetVideoInfoResponse, err error) {
  9. request := vod.CreateGetVideoInfoRequest()
  10. request.VideoId = "<videoId>"
  11. request.AcceptFormat = "JSON"
  12. return client.GetVideoInfo(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetVideoInfo(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. //fmt.Println(response.Video)
  25. }

批量获取视频信息

接口参数和返回字段请参考 GetVideoInfos

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetVideoInfos(client *vod.Client) (response *vod.GetVideoInfosResponse, err error) {
  9. request := vod.CreateGetVideoInfosRequest()
  10. request.VideoIds = "VideoId1,VideoId2"
  11. request.AcceptFormat = "JSON"
  12. return client.GetVideoInfos(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetVideoInfos(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.NonExistVideoIds)
  25. //fmt.Println(response.VideoList)
  26. }

修改视频信息

接口参数和返回字段请参考 UpdateVideoInfo

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyUpdateVideoInfo(client *vod.Client) (response *vod.UpdateVideoInfoResponse, err error) {
  9. request := vod.CreateUpdateVideoInfoRequest()
  10. request.VideoId = "<videoId>"
  11. request.Title = "new Title"
  12. request.Description = "new Description"
  13. request.Tags = "new Tag1,new Tag2"
  14. request.AcceptFormat = "JSON"
  15. return client.UpdateVideoInfo(request)
  16. }
  17. func main() {
  18. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  19. if err != nil {
  20. panic(err)
  21. }
  22. response, err := MyUpdateVideoInfo(client)
  23. if err != nil {
  24. panic(err)
  25. }
  26. fmt.Println(response.GetHttpContentString())
  27. fmt.Println(response.RequestId)
  28. }

批量修改视频信息

接口参数和返回字段请参考 UpdateVideoInfos

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. "encoding/json"
  8. )
  9. func MyUpdateVideoInfos(client *vod.Client) (response *vod.UpdateVideoInfosResponse, err error) {
  10. request := vod.CreateUpdateVideoInfosRequest()
  11. updateContent := []map[string]interface{}{}
  12. updateItem1 := map[string]interface{}{"VideoId":"<VideoId1>", "Title":"New Title 1", "Tags": "NewTag1,NewTag2"}
  13. updateItem2 := map[string]interface{}{"VideoId":"<VideoId2>", "Title":"New Title 2", "Tags": "NewTag1,NewTag2"}
  14. updateContent = append(updateContent, updateItem1, updateItem2)
  15. jsonContent, err := json.Marshal(updateContent)
  16. if err != nil {
  17. fmt.Println("json.Marshal failed:", err)
  18. return
  19. }
  20. request.UpdateContent = string(jsonContent)
  21. request.AcceptFormat = "JSON"
  22. return client.UpdateVideoInfos(request)
  23. }
  24. func main() {
  25. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  26. if err != nil {
  27. panic(err)
  28. }
  29. response, err := MyUpdateVideoInfos(client)
  30. if err != nil {
  31. panic(err)
  32. }
  33. fmt.Println(response.GetHttpContentString())
  34. fmt.Println(response.NonExistVideoIds)
  35. fmt.Println(response.RequestId)
  36. }

删除视频

接口参数和返回字段请参考 DeleteVideo

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyDeleteVideo(client *vod.Client) (response *vod.DeleteVideoResponse, err error) {
  9. request := vod.CreateDeleteVideoRequest()
  10. // 支持批量删除视频,多个用逗号分隔
  11. request.VideoIds = "VideoId1,VideoId2"
  12. request.AcceptFormat = "JSON"
  13. return client.DeleteVideo(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyDeleteVideo(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. }

获取源文件信息(含原片下载地址)

接口参数和返回字段请参考 GetMezzanineInfo

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetMezzanineInfo(client *vod.Client) (response *vod.GetMezzanineInfoResponse, err error) {
  9. request := vod.CreateGetMezzanineInfoRequest()
  10. request.VideoId = "<VideoId>"
  11. request.AuthTimeout = "86400"
  12. //request.OutputType = "oss"
  13. request.AcceptFormat = "JSON"
  14. return client.GetMezzanineInfo(request)
  15. }
  16. func main() {
  17. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  18. if err != nil {
  19. panic(err)
  20. }
  21. response, err := MyGetMezzanineInfo(client)
  22. if err != nil {
  23. panic(err)
  24. }
  25. fmt.Println(response.GetHttpContentString())
  26. fmt.Println(response.RequestId)
  27. fmt.Println(response.Mezzanine.FileURL)
  28. }

获取视频列表

接口参数和返回字段请参考 GetVideoList

注意时间参数要使用UTC时间,北京时间与UTC的时差为+8,也就是UTC+8,例如2018-01-01T12:00:00Z表示北京时间2018年1月1日20点0分0秒

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetVideoList(client *vod.Client) (response *vod.GetVideoListResponse, err error) {
  9. request := vod.CreateGetVideoListRequest()
  10. request.StartTime = "2018-12-01T06:00:00Z"
  11. request.EndTime = "2018-12-25T06:00:00Z"
  12. //request.Status = "Uploading,Normal,Transcoding"
  13. request.PageNo = "1"
  14. request.PageSize = "10"
  15. request.SortBy = "CreationTime:Desc"
  16. request.AcceptFormat = "JSON"
  17. return client.GetVideoList(request)
  18. }
  19. func main() {
  20. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  21. if err != nil {
  22. panic(err)
  23. }
  24. response, err := MyGetVideoList(client)
  25. if err != nil {
  26. panic(err)
  27. }
  28. fmt.Println(response.GetHttpContentString())
  29. fmt.Println(response.RequestId)
  30. videoList := response.VideoList.Video
  31. for _, video := range videoList {
  32. fmt.Printf("%s: %s\n", video.VideoId, video.Title)
  33. }
  34. }

删除媒体流

接口参数和返回字段请参考 DeleteStream

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyDeleteStream(client *vod.Client) (response *vod.DeleteStreamResponse, err error) {
  9. request := vod.CreateDeleteStreamRequest()
  10. request.VideoId = "<VideoId>"
  11. request.JobIds = "JobId1,JobId2"
  12. request.AcceptFormat = "JSON"
  13. return client.DeleteStream(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyDeleteStream(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. }

批量删除源文件

接口参数和返回字段请参考 DeleteMezzanines

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyDeleteMezzanines(client *vod.Client) (response *vod.DeleteMezzaninesResponse, err error) {
  9. request := vod.CreateDeleteMezzaninesRequest()
  10. request.VideoIds = "VideoId1,VideoId2"
  11. request.Force = "false"
  12. request.AcceptFormat = "JSON"
  13. return client.DeleteMezzanines(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyDeleteMezzanines(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. fmt.Println(response.NonExistVideoIds)
  27. }

批量更新图片信息

接口参数和返回字段请参考 UpdateImageInfos

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. "encoding/json"
  8. )
  9. func MyUpdateImageInfos(client *vod.Client) (response *vod.UpdateImageInfosResponse, err error) {
  10. request := vod.CreateUpdateImageInfosRequest()
  11. updateContent := []map[string]interface{}{}
  12. updateItem1 := map[string]interface{}{"ImageId":"<ImageId1>", "Title":"New Title 1", "Tags": "NewTag1,NewTag2"}
  13. updateItem2 := map[string]interface{}{"ImageId":"<ImageId2>", "Title":"New Title 2", "Tags": "NewTag1,NewTag2"}
  14. updateContent = append(updateContent, updateItem1, updateItem2)
  15. jsonContent, err := json.Marshal(updateContent)
  16. if err != nil {
  17. fmt.Println("json.Marshal failed:", err)
  18. return
  19. }
  20. request.UpdateContent = string(jsonContent)
  21. request.AcceptFormat = "JSON"
  22. return client.UpdateImageInfos(request)
  23. }
  24. func main() {
  25. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  26. if err != nil {
  27. panic(err)
  28. }
  29. response, err := MyUpdateImageInfos(client)
  30. if err != nil {
  31. panic(err)
  32. }
  33. fmt.Println(response.GetHttpContentString())
  34. fmt.Println(response.RequestId)
  35. fmt.Println(response.NonExistImageIds)
  36. }

获取图片信息

接口参数和返回字段请参考 GetImageInfo

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetImageInfo(client *vod.Client) (response *vod.GetImageInfoResponse, err error) {
  9. request := vod.CreateGetImageInfoRequest()
  10. request.ImageId = "<ImageId>"
  11. request.AuthTimeout = "86400"
  12. request.AcceptFormat = "JSON"
  13. return client.GetImageInfo(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyGetImageInfo(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. fmt.Println(response.ImageInfo.URL)
  27. }

删除图片

接口参数和返回字段请参考 DeleteImage

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyDeleteImage(client *vod.Client) (response *vod.DeleteImageResponse, err error) {
  9. request := vod.CreateDeleteImageRequest()
  10. // 根据ImageId删除图片文件
  11. request.DeleteImageType = "ImageId"
  12. request.ImageIds = "ImageId1,ImageId2"
  13. /*
  14. // 根据ImageURL删除图片文件
  15. request.DeleteImageType = "ImageURL"
  16. request.ImageURLs = "http://out-20170320144157164-bjsdu4mihp.oss-cn-shanghai.aliyuncs.com.gif"
  17. // 根据VideoId删除指定ImageType的图片文件
  18. request.DeleteImageType = "VideoId"
  19. request.VideoId = "<VideoId>"
  20. request.ImageType = "SpriteSnapshot"
  21. */
  22. request.AcceptFormat = "JSON"
  23. return client.DeleteImage(request)
  24. }
  25. func main() {
  26. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  27. if err != nil {
  28. panic(err)
  29. }
  30. response, err := MyDeleteImage(client)
  31. if err != nil {
  32. panic(err)
  33. }
  34. fmt.Println(response.GetHttpContentString())
  35. fmt.Println(response.RequestId)
  36. }