package com.zcloud.util.ali;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.vod20170321.models.GetMezzanineInfoRequest;
import com.aliyun.vod20170321.models.GetMezzanineInfoResponse;
import com.aliyun.vod20170321.models.GetVideoInfoRequest;
import com.aliyun.vod20170321.models.GetVideoInfoResponse;
import com.aliyun.vod20170321.models.GetVideoPlayAuthRequest;
import com.aliyun.vod20170321.models.GetVideoPlayAuthResponse;
import com.zcloud.entity.PageData;
import com.zcloud.util.Const;

public class GetVideoInfo {


	/**
	 * 使用AK&SK初始化账号Client
	 * 
	 * @param accessKeyId
	 * @param accessKeySecret
	 * @return Client
	 * @throws Exception
	 */
	public static com.aliyun.vod20170321.Client createClient() throws Exception {
		Config config = new Config()
				// 您的AccessKey ID
				.setAccessKeyId(Const.ALI_ACCESSKEY)
				// 您的AccessKey Secret
				.setAccessKeySecret(Const.ALI_ACCESSKEY_SECRET);
		// 访问的域名
		config.endpoint = Const.ENDPOINT;
		return new com.aliyun.vod20170321.Client(config);
	}

	//获取源文件信息
	public static GetMezzanineInfoResponse getMezzanineInfo(PageData pd) throws Exception {
		com.aliyun.vod20170321.Client client = createClient();
		GetMezzanineInfoRequest getMezzanineInfoRequest = new GetMezzanineInfoRequest();
		getMezzanineInfoRequest.videoId = pd.getString("videoId");
		// 复制代码运行请自行打印 API 的返回值
		return client.getMezzanineInfo(getMezzanineInfoRequest);
	}

	//获取视频信息
	public static GetVideoInfoResponse getVideoInfo(PageData pd) throws Exception {
		com.aliyun.vod20170321.Client client = createClient();
		GetVideoInfoRequest getVideoInfoRequest = new GetVideoInfoRequest();
		// 复制代码运行请自行打印 API 的返回值

		getVideoInfoRequest.videoId = pd.getString("videoId");
		return client.getVideoInfo(getVideoInfoRequest);
	}

	public static void main(String[] args_) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		// pd = this.getPageData();
		pd.put("videoId", "7a58a8da8e3a4bd48c72cade824abd5e");
//		GetMezzanineInfoResponse response = getMezzanineInfo(pd);
		GetVideoInfoResponse response1 = getVideoInfo(pd);

//		System.out.println(JSON.toJSON(getVideoPlayAuth(pd).getBody()));
//		System.out.println(response.getBody().getMezzanine());
		System.out.println(JSON.toJSON(response1));
//		System.out.println(response1.getBody().getVideo().duration);
//		try {
//			response = AudioOrVideoCreateUpload.getVideoPlayAuth(pd);
//			System.out.println(JSON.toJSON(response));
//			// 任务ID
//			// System.out.println("JobId = " +
//			// response.getTranscodeJobs().get(0).getJobId());
//		} catch (Exception e) {
//			System.out.println("ErrorMessage = " + e.getLocalizedMessage());
//		}
		map.put("result", errInfo);
	}

}
