package com.platform.plugs.live.responseEntity;

import com.aliyuncs.live.model.v20161101.DescribeCasterScenesResponse;
import com.aliyuncs.live.model.v20161101.DescribeCasterStreamUrlResponse;
import com.aliyuncs.live.model.v20161101.StartCasterResponse;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

/**
 * @Author TONG
 * @Date 2019/3/5 16:28
 **/
@Data
public class StreamInfo {
    /** 转码配置。lsd：标清 lld：流畅 lud：超清 lhd：高清 original: 原画*/
    private String transcodeConfig;
    /** 格式 flv,rtmp,m3u8*/
    private String videoFormat;
    /** 播放地址*/
    private String outputStreamUrl;

    public static StreamInfo parse(StartCasterResponse.SceneInfo1.StreamInfo data) {
        StreamInfo info = new StreamInfo();
        info.setOutputStreamUrl(data.getOutputStreamUrl());
        info.setTranscodeConfig(data.getTranscodeConfig());
        info.setVideoFormat(data.getVideoFormat());
        return info;
    }

    public static StreamInfo parse(DescribeCasterScenesResponse.Scene.StreamInfo data) {
        StreamInfo info = new StreamInfo();
        info.setOutputStreamUrl(data.getOutputStreamUrl());
        info.setTranscodeConfig(data.getTranscodeConfig());
        info.setVideoFormat(data.getVideoFormat());
        return info;
    }

    public static StreamInfo parse(DescribeCasterStreamUrlResponse.CasterStream.StreamInfo data) {
        StreamInfo info = new StreamInfo();
        info.setOutputStreamUrl(data.getOutputStreamUrl());
        info.setTranscodeConfig(data.getTranscodeConfig());
        info.setVideoFormat(data.getVideoFormat());
        return info;
    }

    public String getOutputStreamUrl() {
        if (StringUtils.isNotBlank(this.outputStreamUrl)) {
            return this.outputStreamUrl.replaceAll("http://", "https://");
        }
        return null;
    }
}