全部产品

媒资管理

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

初始化客户端

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

搜索媒资信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.SearchMedia
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                SearchMediaRequest request = new SearchMediaRequest();
                request.SearchType = "video";
                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";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                SearchMediaResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.MediaList != null && response.MediaList.Count > 0)
                {
                    Console.WriteLine("Total = " + response.Total + "\n");
                    Console.WriteLine("ScrollToken = " + response.ScrollToken + "\n");
                    foreach (var media in response.MediaList)
                    {
                        Console.WriteLine("MediaId = " + media.MediaId + "\n");
                        Console.WriteLine("MediaType = " + media.MediaType + "\n");
                        Console.WriteLine("CreationTime = " + media.CreationTime + "\n");
                        Console.WriteLine("Title = " + media.Video.Title + "\n");
                        Console.WriteLine("CoverURL = " + media.Video.CoverURL + "\n");
                        Console.WriteLine("Status = " + media.Video.Status + "\n");
                    }
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

获取视频信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetVideoInfo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetVideoInfoRequest request = new GetVideoInfoRequest();
                request.VideoId = "<your VideoId>";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetVideoInfoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("Title = " + response.Video.Title);
                Console.WriteLine("CoverURL = " + response.Video.CoverURL);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

批量获取视频信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetVideoInfos
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetVideoInfosRequest request = new GetVideoInfosRequest();
                request.VideoIds = "VideoId1,VideoId2";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetVideoInfosResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.NonExistVideoIds != null && response.NonExistVideoIds.Count > 0)
                {
                    foreach (var videoId in response.NonExistVideoIds) {
                        Console.WriteLine("NonExist videoId = " + videoId);
                    }
                }
                if (response.VideoList != null && response.VideoList.Count > 0)
                {
                    foreach (var video in response.VideoList)
                    {
                        Console.WriteLine("MediaId = " + video.VideoId);
                        Console.WriteLine("Title = " + video.Title);
                        Console.WriteLine("CreationTime = " + video.CreationTime);
                        Console.WriteLine("CoverURL = " + video.CoverURL);
                        Console.WriteLine("Status = " + video.Status);
                    }
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

修改视频信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.UpdateVideoInfo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                UpdateVideoInfoRequest request = new UpdateVideoInfoRequest();
                request.VideoId = "<your VideoId>";
                request.Title = "new Title";
                request.Description = "new Description";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateVideoInfoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

批量修改视频信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.UpdateVideoInfos
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                UpdateVideoInfosRequest request = new UpdateVideoInfosRequest();
                request.UpdateContent = "[{\"VideoId\":\"VideoId1\",\"Title\":\"new Title\"},{\"VideoId\":\"VideoId2\",\"Description\":\"new Description\"}]";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateVideoInfosResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.NonExistVideoIds != null && response.NonExistVideoIds.Count > 0)
                {
                    foreach (var videoId in response.NonExistVideoIds)
                    {
                        Console.WriteLine("NonExist videoId = " + videoId);
                    }
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

删除视频

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteVideo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                DeleteVideoRequest request = new DeleteVideoRequest();
                request.VideoIds = "VideoId1,VideoId2";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteVideoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

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

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetMezzanineInfo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetMezzanineInfoRequest request = new GetMezzanineInfoRequest();
                request.VideoId = "f45cf4eba5c84d25b29023338955****";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetMezzanineInfoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("FileURL = " + response.Mezzanine.FileURL);
                Console.WriteLine("Duration = " + response.Mezzanine.Duration);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

获取视频列表

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetVideoListRequest request = new GetVideoListRequest();
                // 分别取一个月前、当前时间的UTC时间作为筛选视频列表的起止时间
                request.StartTime = DateTime.UtcNow.AddMonths(-2).ToString("yyyy-MM-ddTHH:mm:ssZ");
                request.EndTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
                request.Status = "Normal,Checking";
                request.PageNo = 1;
                request.PageSize = 20;
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetVideoListResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                foreach (var videoInfo in response.VideoList)
                {
                    Console.WriteLine("VideoList.VideoId = " + videoInfo.VideoId);
                    Console.WriteLine("VideoList.Title = " + videoInfo.Title);
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

删除媒体流

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                DeleteStreamRequest request = new DeleteStreamRequest();
                request.VideoId = "<your VideoId>";
                request.JobIds = "JobId1,JobId2";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteStreamResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

批量删除源文件

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteMezzanines
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                DeleteMezzaninesRequest request = new DeleteMezzaninesRequest();
                // 待删除的视频ID列表
                request.VideoIds = "VideoId1,VideoId2";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteMezzaninesResponse response = client.GetAcsResponse(request);
                // 打印本次请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.NonExistVideoIds != null && response.NonExistVideoIds.Count > 0)
                {
                    foreach (var videoId in response.NonExistVideoIds)
                    {
                        Console.WriteLine("NonExist videoId = " + videoId);
                    }
                }
                if (response.UnRemoveableVideoIds != null && response.UnRemoveableVideoIds.Count > 0)
                {
                    foreach (var videoId in response.UnRemoveableVideoIds)
                    {
                        Console.WriteLine("UnRemoveable videoId = " + videoId);
                    }
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

批量更新图片信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.UpdateImageInfos
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                UpdateImageInfosRequest request = new UpdateImageInfosRequest();

                request.UpdateContent = "[{\"ImageId\":\"ImageId1\",\"Title\":\"new Title\"},{\"ImageId\":\"ImageId2\",\"Description\":\"new Description\"}]";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateImageInfosResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.NonExistImageIds != null && response.NonExistImageIds.Count > 0)
                {
                    foreach (var imageId in response.NonExistImageIds)
                    {
                        Console.WriteLine("NonExist ImageId = " + imageId);
                    }
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

获取图片信息

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetImageInfo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetImageInfoRequest request = new GetImageInfoRequest();
                // 图片ID
                request.ImageId = "ImageId";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetImageInfoResponse response = client.GetAcsResponse(request);
                // 打印本次请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.ImageInfo != null)
                {
                    Console.WriteLine("ImageId = " + response.ImageInfo.ImageId);
                    Console.WriteLine("ImageType = " + response.ImageInfo.ImageType);
                    Console.WriteLine("Title = " + response.ImageInfo.Title);
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

删除图片

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteImage
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                DeleteImageRequest request = new DeleteImageRequest();
                //根据ImageURL删除图片文件
                request.DeleteImageType = "ImageURL";
                request.ImageURLs = "http://192.168.0.0/16/cover.jpg";
                //根据ImageId删除图片文件
                //request.DeleteImageType = "ImageId";
                //request.ImageIds = "ImageId1,ImageId2";
                //根据VideoId删除指定ImageType的图片文件
                //request.DeleteImageType = "VideoId";
                //request.VideoId = "VideoId";
                //request.ImageType = "SpriteSnapshot";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteImageResponse response = client.GetAcsResponse(request);
                // 打印本次请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}