全部产品

媒资管理

更新时间:2020-11-30 17:53

本篇文档提供了Go SDK媒资管理模块相关功能的API调用示例。主要包含搜索媒资信息、获取视频信息、修改视频信息、删除视频、获取源文件信息、获取图片信息、删除图片信息等。

初始化客户端

使用前请先初始化客户端,请参见初始化

搜索媒资信息

调用SearchMedia接口,完成搜索媒资信息功能。

接口参数和返回字段请参见SearchMedia。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MySearchMedia(client *vod.Client) (response *vod.SearchMediaResponse, err error) {
    request := vod.CreateSearchMediaRequest()
    request.Fields = "Title,CoverURL,Status"
    request.Match = "Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')"
    request.PageNo = "1"
    request.PageSize = "10"
    request.SearchType = "video"
    request.SortBy = "CreationTime:Desc"
    request.AcceptFormat = "JSON"

    return client.SearchMedia(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MySearchMedia(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    //fmt.Println(response.MediaList)
}

获取视频信息

调用GetVideoInfo接口,完成获取视频信息功能。

接口参数和返回字段请参见GetVideoInfo。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetVideoInfo(client *vod.Client) (response *vod.GetVideoInfoResponse, err error) {
    request := vod.CreateGetVideoInfoRequest()
    request.VideoId = "<videoId>"
    request.AcceptFormat = "JSON"

    return client.GetVideoInfo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetVideoInfo(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    //fmt.Println(response.Video)
}

批量获取视频信息

调用GetVideoInfos接口,完成批量获取视频信息功能。

接口参数和返回字段请参见GetVideoInfos。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetVideoInfos(client *vod.Client) (response *vod.GetVideoInfosResponse, err error) {
    request := vod.CreateGetVideoInfosRequest()
    request.VideoIds = "VideoId1,VideoId2"
    request.AcceptFormat = "JSON"

    return client.GetVideoInfos(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetVideoInfos(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.NonExistVideoIds)
    //fmt.Println(response.VideoList)
}

修改视频信息

调用UpdateVideoInfo接口,完成修改视频信息功能。

接口参数和返回字段请参见UpdateVideoInfo。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyUpdateVideoInfo(client *vod.Client) (response *vod.UpdateVideoInfoResponse, err error) {
    request := vod.CreateUpdateVideoInfoRequest()
    request.VideoId = "<videoId>"
    request.Title = "new Title"
    request.Description = "new Description"
    request.Tags = "new Tag1,new Tag2"
    request.AcceptFormat = "JSON"

    return client.UpdateVideoInfo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyUpdateVideoInfo(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

批量修改视频信息

调用UpdateVideoInfos接口,完成批量修改视频信息功能。

接口参数和返回字段请参见UpdateVideoInfos。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
    "encoding/json"
)

func MyUpdateVideoInfos(client *vod.Client) (response *vod.UpdateVideoInfosResponse, err error) {
    request := vod.CreateUpdateVideoInfosRequest()

    updateContent := []map[string]interface{}{}
    updateItem1 := map[string]interface{}{"VideoId":"<VideoId1>", "Title":"New Title 1", "Tags": "NewTag1,NewTag2"}
    updateItem2 := map[string]interface{}{"VideoId":"<VideoId2>", "Title":"New Title 2", "Tags": "NewTag1,NewTag2"}
    updateContent = append(updateContent, updateItem1, updateItem2)
    jsonContent, err := json.Marshal(updateContent)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.UpdateContent = string(jsonContent)
    request.AcceptFormat = "JSON"

    return client.UpdateVideoInfos(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyUpdateVideoInfos(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.NonExistVideoIds)
    fmt.Println(response.RequestId)
}

删除视频

调用DeleteVideo接口,完成删除视频功能。

接口参数和返回字段请参见DeleteVideo。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDeleteVideo(client *vod.Client) (response *vod.DeleteVideoResponse, err error) {
    request := vod.CreateDeleteVideoRequest()
    // 支持批量删除视频,多个用逗号分隔
    request.VideoIds = "VideoId1,VideoId2"
    request.AcceptFormat = "JSON"

    return client.DeleteVideo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyDeleteVideo(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

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

调用GetMezzanineInfo接口,完成获取源文件信息功能。

接口参数和返回字段请参见GetMezzanineInfo。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetMezzanineInfo(client *vod.Client) (response *vod.GetMezzanineInfoResponse, err error) {
    request := vod.CreateGetMezzanineInfoRequest()
    request.VideoId = "<VideoId>"
    request.AuthTimeout = "86400"
    //request.OutputType = "oss"
    request.AcceptFormat = "JSON"

    return client.GetMezzanineInfo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetMezzanineInfo(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.Mezzanine.FileURL)
}

获取视频列表

调用GetVideoList接口,完成获取视频列表功能。

接口参数和返回字段请参见GetVideoList。调用示例如下:

注意

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

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetVideoList(client *vod.Client) (response *vod.GetVideoListResponse, err error) {
    request := vod.CreateGetVideoListRequest()
    request.StartTime = "2018-12-01T06:00:00Z"
    request.EndTime = "2018-12-25T06:00:00Z"
    //request.Status = "Uploading,Normal,Transcoding"
    request.PageNo = "1"
    request.PageSize = "10"
    request.SortBy = "CreationTime:Desc"
    request.AcceptFormat = "JSON"

    return client.GetVideoList(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetVideoList(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    videoList := response.VideoList.Video
    for _, video := range videoList {
        fmt.Printf("%s: %s\n", video.VideoId, video.Title)
    }
}

删除媒体流

调用DeleteStream接口,完成删除媒体流功能。

接口参数和返回字段请参见DeleteStream。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDeleteStream(client *vod.Client) (response *vod.DeleteStreamResponse, err error) {
    request := vod.CreateDeleteStreamRequest()
    request.VideoId = "<VideoId>"
    request.JobIds = "JobId1,JobId2"
    request.AcceptFormat = "JSON"

    return client.DeleteStream(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyDeleteStream(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

批量删除源文件

调用DeleteMezzanines接口,完成批量删除源文件功能。

接口参数和返回字段请参见DeleteMezzanines。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDeleteMezzanines(client *vod.Client) (response *vod.DeleteMezzaninesResponse, err error) {
    request := vod.CreateDeleteMezzaninesRequest()
    request.VideoIds = "VideoId1,VideoId2"
    request.Force = "false"
    request.AcceptFormat = "JSON"

    return client.DeleteMezzanines(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyDeleteMezzanines(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.NonExistVideoIds)
}

批量更新图片信息

调用UpdateImageInfos接口,完成批量更新图片信息功能。

接口参数和返回字段请参见UpdateImageInfos。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
    "encoding/json"
)

func MyUpdateImageInfos(client *vod.Client) (response *vod.UpdateImageInfosResponse, err error) {
    request := vod.CreateUpdateImageInfosRequest()

    updateContent := []map[string]interface{}{}
    updateItem1 := map[string]interface{}{"ImageId":"<ImageId1>", "Title":"New Title 1", "Tags": "NewTag1,NewTag2"}
    updateItem2 := map[string]interface{}{"ImageId":"<ImageId2>", "Title":"New Title 2", "Tags": "NewTag1,NewTag2"}
    updateContent = append(updateContent, updateItem1, updateItem2)
    jsonContent, err := json.Marshal(updateContent)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.UpdateContent = string(jsonContent)
    request.AcceptFormat = "JSON"

    return client.UpdateImageInfos(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyUpdateImageInfos(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.NonExistImageIds)
}

获取图片信息

调用GetImageInfo接口,完成获取图片信息功能。

接口参数和返回字段请参见GetImageInfo。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetImageInfo(client *vod.Client) (response *vod.GetImageInfoResponse, err error) {
    request := vod.CreateGetImageInfoRequest()
    request.ImageId = "<ImageId>"
    request.AuthTimeout = "86400"
    request.AcceptFormat = "JSON"

    return client.GetImageInfo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetImageInfo(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.ImageInfo.URL)
}

删除图片

调用DeleteImage接口,完成删除图片功能。

接口参数和返回字段请参见DeleteImage。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDeleteImage(client *vod.Client) (response *vod.DeleteImageResponse, err error) {
    request := vod.CreateDeleteImageRequest()

    // 根据ImageId删除图片文件
    request.DeleteImageType = "ImageId"
    request.ImageIds = "ImageId1,ImageId2"

    /*
    // 根据ImageURL删除图片文件
    request.DeleteImageType = "ImageURL"
    request.ImageURLs = "http://out-20170320144157164-bjsdu4mihp.oss-cn-shanghai.aliyuncs.com.gif"

    // 根据VideoId删除指定ImageType的图片文件
    request.DeleteImageType = "VideoId"
    request.VideoId = "<VideoId>"
    request.ImageType = "SpriteSnapshot"
    */

    request.AcceptFormat = "JSON"

    return client.DeleteImage(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyDeleteImage(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}