package com.miaxis.test;

import com.alibaba.fastjson.JSONObject;
import com.miaxis.JsjpApplication;
import com.miaxis.common.utils.VodSignature;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.vod.v20180717.VodClient;
import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest;
import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse;
import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoRequest;
import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoResponse;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.io.File;

@SpringBootTest(classes = JsjpApplication.class)
@RunWith(SpringRunner.class)
public class VodTest {

    @Resource
    VodSignature vodSignature;

    @Value("${cos.secretId}")
    private String secretId;
    @Value("${cos.secretKey}")
    private String secretKey;

    @Resource
    VodClient vodClient;

    /**
     */
    @Test
    public void get() throws Exception {

        String uploadSignature = vodSignature.getUploadSignature();
        System.out.println(uploadSignature);
    }


    @Test
    public void get1() throws Exception {
        try{
            DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
            String[] fileIds1 = {"3701925920473528049"};
            String[] filter1 = {"basicInfo","metaData"};
            req.setFileIds(fileIds1);
            req.setFilters(filter1);
            DescribeMediaInfosResponse resp = vodClient.DescribeMediaInfos(req);

            JSONObject jsonObject = JSONObject.parseObject(DescribeMediaInfosResponse.toJsonString(resp));
            System.out.println(DescribeMediaInfosResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }



    @Test
    public void test5(){
        try{
            String docUploadPath = "C:\\Users\\wwl\\Desktop\\timg.jpg";
            File file = new File(docUploadPath);
            byte[] refereeFileOriginalBytes = FileUtils.readFileToByteArray(file);
            byte[] refereeFileBase64Bytes = Base64.encodeBase64(refereeFileOriginalBytes);
            String UpFile = new String(refereeFileBase64Bytes, "UTF-8");

            ModifyMediaInfoRequest req = new ModifyMediaInfoRequest();
            req.setFileId("3701925920473528049");
            req.setCoverData(UpFile);

            ModifyMediaInfoResponse resp = vodClient.ModifyMediaInfo(req);
            System.out.println(ModifyMediaInfoResponse.toJsonString(resp));
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }


}
