初始化客户端

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

搜索媒资信息

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

import com.aliyuncs.vod.model.v20170321.SearchMediaRequest;
import com.aliyuncs.vod.model.v20170321.SearchMediaResponse;

/**
 * 搜索媒资信息
 * @param client 发送请求客户端
 * @return SearchMediaResponse 搜索媒资信息响应数据
 * @throws Exception
 
*/
public static SearchMediaResponse searchMedia(DefaultAcsClient client) throws Exception {
    SearchMediaRequest request = new SearchMediaRequest();
	request.setFields("Title,CoverURL,Status");
	request.setMatch("Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')");
	request.setPageNo(1);
	request.setPageSize(10);
	request.setSearchType("video");
	request.setSortBy("CreationTime:Desc");
	return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	SearchMediaResponse response = new SearchMediaResponse();
	try {
		response = searchMedia(client);
		if (response.getMediaList() != null && response.getMediaList().size() > 0) {
            System.out.print("Total = " + response.getTotal() + "\n");
            System.out.print("ScrollToken = " + response.getScrollToken() + "\n");
            for (SearchMediaResponse.Media media : response.getMediaList()) {
                System.out.print("MediaId = " + media.getMediaId() + "\n");
                System.out.print("MediaType = " + media.getMediaType() + "\n");
                System.out.print("CreationTime = " + media.getCreationTime() + "\n");
                System.out.print("Title = " + media.getVideo().getTitle() + "\n");
                System.out.print("CoverURL = " + media.getVideo().getCoverURL() + "\n");
                System.out.print("Status = " + media.getVideo().getStatus() + "\n");
            }
        }
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

获取视频信息

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

import com.aliyuncs.vod.model.v20170321.GetVideoInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoInfoResponse;

/**
 * 获取视频信息
 * @param client 发送请求客户端
 * @return GetVideoInfoResponse 获取视频信息响应数据
 * @throws Exception
*/
public static GetVideoInfoResponse getVideoInfo(DefaultAcsClient client) throws Exception {
	GetVideoInfoRequest request = new GetVideoInfoRequest();
	request.setVideoId("VideoId");
	return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	GetVideoInfoResponse response = new GetVideoInfoResponse();
	try {
		response = getVideoInfo(client);
		System.out.print("Title = " + response.getVideo().getTitle() + "\n");
		System.out.print("Description = " + response.getVideo().getDescription() + "\n");
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

批量获取视频信息

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

import com.aliyuncs.vod.model.v20170321.GetVideoInfosRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoInfosResponse;

/**
 * 批量获取视频信息函数
 * @param client 发送请求客户端
 * @return GetVideoInfosResponse 获取视频信息响应数据
 * @throws Exception
*/
public static GetVideoInfosResponse getVideoInfos(DefaultAcsClient client) throws Exception {
    GetVideoInfosRequest request = new GetVideoInfosRequest();
    request.setVideoIds("VideoId1,VideoId2");
    return client.getAcsResponse(request);
}

//请求示例
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    GetVideoInfosResponse response = new GetVideoInfosResponse();
    try {
        response = getVideoInfos(client);
        if (response.getVideoList() != null && response.getVideoList().size() > 0) {
            System.out.print("===== exist video infos : ===== \n");
            for (GetVideoInfosResponse.Video video : response.getVideoList()) {
                System.out.print("VideoId = " + video.getVideoId() + "\n");
                System.out.print("Title = " + video.getTitle() + "\n");
                System.out.print("Description = " + video.getDescription() + "\n");
                System.out.print("Tags = " + video.getTags() + "\n");
                System.out.print("CreationTime = " + video.getCreationTime() + "\n");
            }
        }
        if (response.getNonExistVideoIds() != null && response.getNonExistVideoIds().size() > 0) {
            System.out.print("===== nonexistent videoIds : ===== \n");
            for (String videoId : response.getNonExistVideoIds()) {
                System.out.print(videoId + "\n");
            }
        }
    } catch (Exception e) {
      System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

			

修改视频信息

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

import com.aliyuncs.vod.model.v20170321.UpdateVideoInfoRequest;
import com.aliyuncs.vod.model.v20170321.UpdateVideoInfoResponse;

/**
 * 修改视频信息
 * @param client 发送请求客户端
 * @return UpdateVideoInfoResponse 修改视频信息响应数据
 * @throws Exception
*/
public static UpdateVideoInfoResponse updateVideoInfo(DefaultAcsClient client) throws Exception {
	UpdateVideoInfoRequest request = new UpdateVideoInfoRequest();
	request.setVideoId("VideoId");
	request.setTitle("new Title");
	request.setDescription("new Description");
	request.setTags("new Tag1,new Tag2");
	return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	UpdateVideoInfoResponse response = new UpdateVideoInfoResponse();
	try {
		response = updateVideoInfo(client);
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

批量修改视频信息

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

import com.aliyuncs.vod.model.v20170321.UpdateVideoInfosRequest;
import com.aliyuncs.vod.model.v20170321.UpdateVideoInfosResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 批量修改视频信息
 * @param client 发送请求客户端
 * @return UpdateVideoInfosResponse 批量修改视频信息响应数据
 * @throws Exception
*/
public static UpdateVideoInfosResponse updateVideoInfos(DefaultAcsClient client) throws Exception {
    UpdateVideoInfosRequest request = new UpdateVideoInfosRequest();
    JSONArray updateContentArray = new JSONArray();
    JSONObject updateContent1 = new JSONObject();
    updateContent1.put("VideoId", "VideoId1");
    // updateContent1.put("Title", "new Title");
    // updateContent1.put("Tags", "new Tag1,new Tag2");
    updateContentArray.add((updateContent1));
    JSONObject updateContent2 = new JSONObject();
    updateContent2.put("VideoId", "VideoId2");
    // updateContent2.put("Title", "new Title");
    // updateContent2.put("Tags", "new Tag1,new Tag2");
    updateContentArray.add((updateContent2));
    request.setUpdateContent(updateContentArray.toJSONString());
    DefaultAcsClient client = init();
    return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    UpdateVideoInfosResponse response = new UpdateVideoInfosResponse();
    try {
        response = updateVideoInfos(client);
        if (response.getNonExistVideoIds() != null && response.getNonExistVideoIds().size() > 0) {
            System.out.print("======nonexistent VideoIds : ======\n");
            for (String videoId : response.getNonExistVideoIds()) {
                System.out.print(videoId + "\n");
            }
        }
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

删除视频

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

import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
import com.aliyuncs.vod.model.v20170321.DeleteVideoResponse;

/**
 * 删除视频
 * @param client 发送请求客户端
 * @return DeleteVideoResponse 删除视频响应数据
 * @throws Exception
*/
public static DeleteVideoResponse deleteVideo(DefaultAcsClient client) throws Exception {
	DeleteVideoRequest request = new DeleteVideoRequest();
	//支持传入多个视频ID,多个用逗号分隔
	request.setVideoIds("VideoId1,VideoId2");
	return client.getAcsResponse(request);
}

/*请求示例*/
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	DeleteVideoResponse response = new DeleteVideoResponse();
	try {
		response = deleteVideo(client);
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

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

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

import com.aliyuncs.vod.model.v20170321.GetMezzanineInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetMezzanineInfoResponse;

/**
 * 获取源文件信息
 * @param client 发送请求客户端
 * @return GetMezzanineInfoResponse 获取源文件信息响应数据
 * @throws Exception
*/
public static GetMezzanineInfoResponse getMezzanineInfo(DefaultAcsClient client) throws Exception {
	GetMezzanineInfoRequest request = new GetMezzanineInfoRequest();
	request.setVideoId("VideoId");
	//源片下载地址过期时间
	request.setAuthTimeout(3600L);
	return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	GetMezzanineInfoResponse response = new GetMezzanineInfoResponse();
	try {
		response = getMezzanineInfo(client);
		System.out.print("Mezzanine.VideoId = " + response.getMezzanine().getVideoId() + "\n");
		System.out.print("Mezzanine.FileURL = " + response.getMezzanine().getFileURL() + "\n");
		System.out.print("Mezzanine.Width = " + response.getMezzanine().getWidth() + "\n");
		System.out.print("Mezzanine.Height = " + response.getMezzanine().getHeight() + "\n");
		System.out.print("Mezzanine.Size = " + response.getMezzanine().getSize() + "\n");
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

获取视频列表

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

import com.aliyuncs.vod.model.v20170321.GetVideoListRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoListResponse;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

// 根据Date时间生成UTC时间函数
public static String generateUTCTime(Date time) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
	dateFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
	dateFormat.setLenient(false);
	return dateFormat.format(time);
}

/**
 * 获取视频列表
 * @param client 发送请求客户端
 * @return GetVideoListResponse 获取视频列表响应数据
 * @throws Exception
*/
public static GetVideoListResponse getVideoList(DefaultAcsClient client) throws Exception {
	GetVideoListRequest request = new GetVideoListRequest();
	// 分别取一个月前、当前时间的UTC时间作为筛选视频列表的起止时间
	String monthAgoUTCTime = generateUTCTime(new Date(System.currentTimeMillis() - 30*86400*1000L));
	String nowUTCTime = generateUTCTime(new Date(System.currentTimeMillis()));
	// 视频创建的起始时间,为UTC格式
	request.setStartTime(monthAgoUTCTime);
	// 视频创建的结束时间,为UTC格式
	request.setEndTime(nowUTCTime);
	// 视频状态,默认获取所有状态的视频,多个用逗号分隔
	// request.setStatus("Uploading,Normal,Transcoding");
	request.setPageNo(1L);
	request.setPageSize(20L);
	return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	GetVideoListResponse response = new GetVideoListResponse();
	try {
		response = getVideoList(client);
		// 根据指定筛选条件查询到的视频总数
		System.out.print("Total = " + response.getTotal() + "\n");
		for (GetVideoListResponse.Video video : response.getVideoList()) {
			System.out.print("Title = " + video.getTitle() + "\n");
			System.out.print("Description = " + video.getDescription() + "\n");
			System.out.print("Tags = " + video.getTags() + "\n");
			System.out.print("CreationTime = " + video.getCreationTime() + "\n");
		}
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}

			

删除媒体流

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

import com.aliyuncs.vod.model.v20170321.DeleteStreamRequest;
import com.aliyuncs.vod.model.v20170321.DeleteStreamResponse;

/**
 * 删除媒体流函数
 * @param client 发送请求客户端
 * @return DeleteMezzaninesResponse 删除媒体流响应数据
 * @throws Exception
*/
public static DeleteStreamResponse deleteStream(DefaultAcsClient client) throws Exception {
	DeleteStreamRequest request = new DeleteStreamRequest();
	request.setVideoId("VideoId");
	request.setJobIds("JobId1,JobId2");
	return client.getAcsResponse(request);
}

//请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	DeleteStreamResponse response = new DeleteStreamResponse();
	try {
		response = deleteStream(client);
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}

			

批量删除源文件

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

import com.aliyuncs.vod.model.v20170321.DeleteMezzaninesRequest;
import com.aliyuncs.vod.model.v20170321.DeleteMezzaninesResponse;
/**
 * 批量删除源文件函数
 * @param client 发送请求客户端
 * @return DeleteMezzaninesResponse 批量删除源文件响应数据
 * @throws Exception
*/
public static DeleteMezzaninesResponse deleteMezzanines(DefaultAcsClient client) throws Exception {
	DeleteMezzaninesRequest request = new DeleteMezzaninesRequest();
	//支持传入多个视频ID,多个用逗号分隔
	request.setVideoIds("VideoId1,VideoId2");
	request.setForce(false);
	return client.getAcsResponse(request);
}

//请求示例
public static void main(String[] argv) {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	DeleteMezzaninesResponse response = new DeleteMezzaninesResponse();
	try {
		response = deleteMezzanines(client);
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}

			

批量更新图片信息

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

import com.aliyuncs.vod.model.v20170321.UpdateImageInfosRequest;
import com.aliyuncs.vod.model.v20170321.UpdateImageInfosResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 批量更新图片信息函数
 * @param client 发送请求客户端
 * @return UpdateImageInfosResponse 批量更新图片信息响应数据
 * @throws Exception
*/
public static UpdateImageInfosResponse updateImageInfos(DefaultAcsClient client) throws Exception{
        UpdateImageInfosRequest request = new UpdateImageInfosRequest();
        JSONArray updateContentArray = new JSONArray();
        JSONObject updateContent1 = new JSONObject();
        updateContent1.put("ImageId", "ImageId1");
//        updateContent1.put("Title", "new Title");
//        updateContent1.put("Tags", "new Tag1,new Tag2");
        updateContentArray.add((updateContent1));
        JSONObject updateContent2 = new JSONObject();
        updateContent2.put("ImageId", "ImageId2");
//        updateContent2.put("Title", "new Title");
//        updateContent2.put("Tags", "new Tag1,new Tag2");
        updateContentArray.add((updateContent2));
        request.setUpdateContent(updateContentArray.toJSONString());
        return client.getAcsResponse(request);
    }

// 请求示例
public static void main(String[] argv) throws Exception {
	DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
	UpdateImageInfosResponse response = new UpdateImageInfosResponse();
	try {
		response = updateImageInfos(client);
		if (response.getNonExistImageIds() != null && response.getNonExistImageIds().size() > 0) {
			System.out.print("======nonexistent ImageIds : ======\n");
			for (String imageId : response.getNonExistImageIds()) {
				System.out.print(imageId + "\n");
			}
		}
	} catch (Exception e) {
		System.out.print("ErrorMessage = " + e.getLocalizedMessage());
	}
	System.out.print("RequestId = " + response.getRequestId() + "\n");
}

			

获取图片信息

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

import com.aliyuncs.vod.model.v20170321.GetImageInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetImageInfoResponse;

/**
 * 获取图片信息函数
 *
 * @param client 发送请求客户端
 * @return GetImageInfoResponse 获取图片信息响应数据
 * @throws Exception
*/
public static GetImageInfoResponse getImageInfo(DefaultAcsClient client) throws Exception {
    GetImageInfoRequest request = new GetImageInfoRequest();
    request.setImageId("ImageId");
    return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    GetImageInfoResponse response = new GetImageInfoResponse();
    try {
        response = getImageInfo(client);
        System.out.print("ImageId=" + response.getImageInfo().getImageId());
        System.out.print("Title=" + response.getImageInfo().getTitle());
        System.out.print("CreationTime=" + response.getImageInfo().getCreationTime());
        System.out.print("FileURL=" + response.getImageInfo().getMezzanine().getFileURL());
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}
			

删除图片

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

import com.aliyuncs.vod.model.v20170321.DeleteImageRequest;
import com.aliyuncs.vod.model.v20170321.DeleteImageResponse;

/**
 * 删除图片函数
 *
 * @param client 发送请求客户端
 * @return DeleteImageResponse 删除图片响应数据
 * @throws Exception
*/
public static DeleteImageResponse deleteImage(DefaultAcsClient client) throws Exception {
    DeleteImageRequest request = new DeleteImageRequest();
    //根据ImageURL删除图片文件
    request.setDeleteImageType("ImageURL");
    String url = "http://sample.aliyun.com/cover.jpg";
    String encodeUrl = URLEncoder.encode(url, "UTF-8");
    request.setImageURLs(encodeUrl);
    //根据ImageId删除图片文件
    //request.setDeleteImageType("ImageId");
    //request.setImageIds("ImageId1,ImageId2");
    //根据VideoId删除指定ImageType的图片文件
    //request.setDeleteImageType("VideoId");
    //request.setVideoId("VideoId");
    //request.setImageType("SpriteSnapshot");
    return client.getAcsResponse(request);
}

// 请求示例
public static void main(String[] argv) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    DeleteImageResponse response = new DeleteImageResponse();
    try {
        response = deleteImage(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}